Merge branch 'code_docs'

This commit is contained in:
manfromhuh 2022-07-05 15:13:44 -04:00
commit 91119d3575
7 changed files with 34 additions and 24 deletions

View File

@ -1 +0,0 @@
# simple_blog

View File

@ -1,4 +1,5 @@
<?php <?php
//Parses it's passed input to convert it to a month name.
function get_month_name($passed_var){ function get_month_name($passed_var){
switch($passed_var){ switch($passed_var){
case "01": case "01":

View File

@ -1,4 +1,5 @@
<?php <?php
//Sets the proper level 1 heading for the folder.
include_once ($_SERVER['DOCUMENT_ROOT'].'/common/get_month_name.php'); include_once ($_SERVER['DOCUMENT_ROOT'].'/common/get_month_name.php');
$current_dir = basename(getcwd()); $current_dir = basename(getcwd());
$named_month = get_month_name($current_dir); $named_month = get_month_name($current_dir);

View File

@ -1,7 +1,8 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en-US"> <html lang="en-US">
<?php <?php
function Title() { //Sets the page title based on the name of the current directory
function Title() {//Needs cleanup.
//~ $new_title = $_SERVER['REQUEST_URI']; //~ $new_title = $_SERVER['REQUEST_URI'];
//~ $new_title = preg_replace("/^^\//i", "", $new_title); //~ $new_title = preg_replace("/^^\//i", "", $new_title);
@ -27,7 +28,7 @@
?> ?>
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<?php <?php//If a tags file is present parse it and add any tags found to the renderd page's metadata.
if(file_exists('tags')){ if(file_exists('tags')){
$tag_data_raw = fopen('tags',"r"); $tag_data_raw = fopen('tags',"r");
$tag_data = fread($tag_data_raw, filesize('tags')); $tag_data = fread($tag_data_raw, filesize('tags'));

View File

@ -1,6 +1,9 @@
<?php <?php
//The common file used to render pages on the blog.
include_once ($_SERVER['DOCUMENT_ROOT'].'/common/header.php'); include_once ($_SERVER['DOCUMENT_ROOT'].'/common/header.php');
include_once ($_SERVER['DOCUMENT_ROOT'].'/common/menu.php'); include_once ($_SERVER['DOCUMENT_ROOT'].'/common/menu.php');
//Looks for an article.md to see if the current directory is an article or not
//If it is not then it is a menu page.
if (file_exists('article.md')){ if (file_exists('article.md')){
include_once ($_SERVER['DOCUMENT_ROOT'].'/common/md_read.php'); include_once ($_SERVER['DOCUMENT_ROOT'].'/common/md_read.php');
} else { } else {

View File

@ -1,8 +1,10 @@
//
function format_page(){//Set the title of the page based on the main header, <h1>, tag.le != '' )){ function format_page(){//Set the title of the page based on the main header, <h1>, tag.le != '' )){
if ( document.getElementsByTagName('h1').length !== 0){ if ( document.getElementsByTagName('h1').length !== 0){
document.title = document.getElementsByTagName('h1')[0].innerText; document.title = document.getElementsByTagName('h1')[0].innerText;
} }
//detect if the page contains code blocks to be highlighted and loads the prisim.js and prism.css files to accomplish this. //Detect if the page contains code blocks to be highlighted and loads the
//prisim.js and prism.css files if codeblocks are found.
code_tag = document.getElementsByTagName('code').length; code_tag = document.getElementsByTagName('code').length;
if ( code_tag !== 0 ){ if ( code_tag !== 0 ){
var script = document.createElement('script'); var script = document.createElement('script');
@ -15,11 +17,14 @@ function format_page(){//Set the title of the page based on the main header, <h1
document.head.appendChild(script); document.head.appendChild(script);
document.head.appendChild(style_sheet); document.head.appendChild(style_sheet);
} }
//Sets the displayed fontsize.
//This functionality won't work without JavaScript enabled. For this reason the
//buttons won't be shown if this script isn't run.
if ( document.getElementById("font_btns") ){//Show the font selection buttons. if ( document.getElementById("font_btns") ){//Show the font selection buttons.
document.getElementById("font_btns").style.display = 'inline'; document.getElementById("font_btns").style.display = 'inline';
var font_size = read_cookie("font_size"); var font_size = read_cookie("font_size");//reads a saved value for fontsize from the site cookie
if ( font_size != "" || font_size != "medium" ){ if ( font_size != "" || font_size != "medium" ){
font_set(font_size); font_set(font_size);//insure a sane default
} }
} }
if ( document.getElementById("search_inputs") ){//Show the search box and button on the tags page. if ( document.getElementById("search_inputs") ){//Show the search box and button on the tags page.
@ -43,7 +48,7 @@ function format_page(){//Set the title of the page based on the main header, <h1
}); });
} }
} }
function font_set(size_to_set){ function font_set(size_to_set){//Set a cookie to remember the fontsize selection.
document.getElementById("article").style.fontSize = size_to_set; document.getElementById("article").style.fontSize = size_to_set;
set_cookie("font_size",size_to_set); set_cookie("font_size",size_to_set);
} }
@ -52,7 +57,7 @@ function focus_element(element_id){
ele_to_focus.focus(); ele_to_focus.focus();
ele_to_focus.select(); ele_to_focus.select();
} }
function tag_search(){ function tag_search(){//searches in the avaliable tags and displays all articles matching the searched tag.
var search_input, filter, tag_list, li, a, i; var search_input, filter, tag_list, li, a, i;
search_input = document.getElementById("tag_sort"); search_input = document.getElementById("tag_sort");
filter = search_input.value.toUpperCase(); filter = search_input.value.toUpperCase();
@ -66,9 +71,8 @@ function tag_search(){
li[i].style.display = "none"; li[i].style.display = "none";
} }
} }
} }
function title_search(){ function title_search(){//searches for matches in the article titles rather than tags. Allows more granular search
var search_input, filter, tag_list, li_list, ol, a, i; var search_input, filter, tag_list, li_list, ol, a, i;
search_input = document.getElementById("title_sort"); search_input = document.getElementById("title_sort");
filter = search_input.value.toUpperCase(); filter = search_input.value.toUpperCase();
@ -88,7 +92,7 @@ function title_search(){
} }
} }
function search_toggle(){ function search_toggle(){//Toggles if the unit being sorted on is the article title or tag
if (document.getElementById("tag_sort")){ if (document.getElementById("tag_sort")){
document.getElementById("tag_sort").placeholder = "Search Titles"; document.getElementById("tag_sort").placeholder = "Search Titles";
document.getElementById("tag_sort").onkeyup = function() {title_search()}; document.getElementById("tag_sort").onkeyup = function() {title_search()};
@ -107,10 +111,10 @@ function search_toggle(){
focus_element("tag_sort"); focus_element("tag_sort");
} }
} }
function set_cookie(prop_name, prop_value){ function set_cookie(prop_name, prop_value){//sets a passed cookie property and value.
document.cookie = prop_name + "=" + prop_value + ";path=/;SameSite=Strict;"; document.cookie = prop_name + "=" + prop_value + ";path=/;SameSite=Strict;";
} }
function read_cookie(cname){ function read_cookie(cname){//reads a property value
let prop_name = cname + '='; let prop_name = cname + '=';
let decoded_cookie = decodeURIComponent(document.cookie); let decoded_cookie = decodeURIComponent(document.cookie);
let split_cookie = decoded_cookie.split(';'); let split_cookie = decoded_cookie.split(';');
@ -125,11 +129,11 @@ function read_cookie(cname){
} }
return ""; return "";
} }
function printDiv(divName) { function printDiv(divName) {//Formats the page for printing.
var printContents = document.getElementById(divName).innerHTML; var printContents = document.getElementById(divName).innerHTML;
w=window.open(); w=window.open();
w.document.write(printContents); w.document.write(printContents);
w.print(); w.print();
w.close(); w.close();
} }
window.onload = format_page; window.onload = format_page;//loades the page formatting script.

View File

@ -4,6 +4,7 @@
<?php <?php
include_once ($_SERVER['DOCUMENT_ROOT'].'/common/get_month_name.php'); include_once ($_SERVER['DOCUMENT_ROOT'].'/common/get_month_name.php');
//Removes the number used to keep articles in post order from the displayed title.
function remove_sorting_number($link_title){ function remove_sorting_number($link_title){
$first_three = mb_substr($link_title, 0, 3,"UTF-8"); $first_three = mb_substr($link_title, 0, 3,"UTF-8");
@ -31,14 +32,14 @@ if (file_exists($dir) && is_dir($dir) ) {
$file_array[] = $file; $file_array[] = $file;
} }
} }
foreach($file_array as $file) { foreach($file_array as $file) {//Renders the folder names as more readable titles.
$_replace = array('.php', '.html', '.htm'); $_replace = array('.php', '.html', '.htm');//Remove file extensions from webpages.
$link_title = str_replace('_',' ',$file); $link_title = str_replace('_',' ',$file);//Remove undersores and replace them with spaces
$link_title = str_replace($_replace,'',$link_title); $link_title = str_replace($_replace,'',$link_title);
$link_title = ucwords($link_title); $link_title = ucwords($link_title);//Set the first letter of each word to upercase.
$link_title = get_month_name($link_title); $link_title = get_month_name($link_title);//
$link_title = remove_sorting_number($link_title); $link_title = remove_sorting_number($link_title);//Removes the number used to keep articles in post order from the displayed title.
echo("<ul><li><a href='$file'> $link_title </a></li></ul>\n"); echo("<ul><li><a href='$file'> $link_title </a></li></ul>\n");//Output the result.
} }
} }
else { else {