From deb20fdfca35c64066fe4e375099350dc77ea408 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Mon, 22 May 2023 15:18:52 -0500 Subject: initial commit --- index.php | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 index.php (limited to 'index.php') diff --git a/index.php b/index.php new file mode 100644 index 0000000..9a4e11b --- /dev/null +++ b/index.php @@ -0,0 +1,189 @@ +My Blog'; + + // Get metadata on all posts from the metadata.json file + include_once('_functions/loadJSON.php'); + $contentCol .= loadHomepageJSON('_data/metadata.json'); + + // Create a template + include_once('_classes/Template.php'); + $template = new Template( + $GLOBALS['fullDomain'], + 'Explore the thoughts of...', + 'Blog | YourName', + '', + $contentCol, + '' + ); + + // Echo the HTML to the user + $template->echoTemplate(); +} + +function showPost($params) +{ + // URL Parameter + $query = $params[0]; + + // Get metadata on this post from the metadata.json file + include_once('_functions/loadJSON.php'); + $headerData = loadPostJSON('_data/metadata.json', $query); + + // Apply metadata to post header + $header = '

' . $headerData->title . '

'; + + // Get post .md file that matches the .html file requested in the URL + include_once('_functions/parseMarkdown.php'); + $fileName = './posts/' . $headerData->id . '-' . str_replace('.html', '.md', $query); + $securedHTML = parseMarkdown($fileName); + + // Echo Results + $contentCol = '
' . $header . '
' . $securedHTML . '
'; + + // Create a comment section + $postURL = $GLOBALS['fullDomain'] . '/post/' . $query; + $commentForm = '

Leave a Comment

Comments are saved as Markdown and cannot be edited or deleted.
'; + + // Load saved comments + $userComments = '

Comments

'; + $userComments .= loadCommentJSON('_data/comments.json', $query); + $userComments .= '
'; + + // Combine comment form and previous user comments + $commentSection = $commentForm . $userComments; + + // Create a template + include_once('_classes/Template.php'); + $template = new Template( + $GLOBALS['fullDomain'] . '/post/' . $query, + $headerData->description . ' Read more at ' . $GLOBALS['fullDomain'] . '!', + $headerData->title . ' | Blog', + '', + $contentCol, + $commentSection + ); + + // Echo the HTML to the user + $template->echoTemplate(); +} + +function showComments() +{ + // Add title + $commentHeader = '

Recent Comments

'; + + // Load saved comments + include_once('_functions/parseMarkdown.php'); + include_once('_functions/loadJSON.php'); + $userComments = '

Comments Across All Blog Posts

'; + $userComments .= loadCommentJSON('_data/comments.json'); + $userComments .= '
'; + + // Combine comment form and previous user comments + $commentSection = $commentHeader . $userComments; + + // Create a template + include_once('_classes/Template.php'); + $template = new Template( + $GLOBALS['fullDomain'] . '/comments/', + 'Read through some recent comments for blog posts at ' . $GLOBALS['fullDomain'] . '.', + 'Recent Comments | Blog', + '', + '', + $commentSection + ); + + // Echo the HTML to the user + $template->echoTemplate(); +} + +function showCategory() +{ + // Open the article list + $contentCol = '

Categories

'; + + // Get metadata on all posts from the metadata.json file + include_once('_functions/loadJSON.php'); + $contentCol .= loadCategoryJSON('_data/metadata.json'); + + // Create a template + include_once('_classes/Template.php'); + $template = new Template( + $GLOBALS['fullDomain'] . '/categories/', + 'Browse the categories for blog posts at ' . $GLOBALS['fullDomain'] . '.', + 'Categories | Blog', + '', + $contentCol, + '' + ); + + // Echo the HTML to the user + $template->echoTemplate(); +} + +function showRSS() +{ + // Loop through the metadata file and display any article that is published + include_once('_functions/loadRSS.php'); + $rssContents = loadRSS('_data/metadata.json'); + + // Echo the RSS XML + header('Content-type: text/xml'); + echo $rssContents; + die(); +} + +function showRobots() +{ + header('Content-type: text/plain'); + echo 'User-agent: * Disallow:'; + die(); +} -- cgit v1.2.3-70-g09d2