commit c8ae75ea6921a099ab85a1111a288d4ee16eb60c
parent d0109d324a4a3e4778b18ffe54399d5613341c09
Author: Robert D Herb <github@robertdherb.com>
Date: Wed, 3 Feb 2016 16:23:36 -0600
Make posts and pages actually *do* something.
Up next: Basic styling
Diffstat:
5 files changed, 43 insertions(+), 22 deletions(-)
diff --git a/functions.php b/functions.php
@@ -22,6 +22,8 @@ function write_html() {
}
}
+ $output = str_replace( "{allposts}", post_list(), $output );
+
print( $output );
}
@@ -36,4 +38,33 @@ function format_name( $name ) {
}
+function link_name( $name ) {
+ return str_replace( ".md", "", $name );
+}
+
+function post_list() {
+
+ $posts = scandir( "posts/" );
+ $posts = array_diff( $posts, array( "..", "." ) );
+ $postDates = array();
+ foreach( $posts as $thisPost ) {
+ $postDates[] = filectime( "posts/" . $thisPost);
+ }
+
+ $posts = array_combine( $postDates, $posts );
+ krsort( $posts );
+
+
+ $output = "\n\t<ul id=\"posts\">";
+
+ foreach( $posts as $thisPost ) {
+ $output .= "\n\t\t<li><a href=\"" . URL . BLOG_DIR . "/post/" . link_name( $thisPost ) . "\">" . date( "Y-m-d", key( $posts ) ) . " - " . format_name( $thisPost ) . "</a></li>";
+ }
+
+ $output .= "\n\t</ul>";
+
+ return $output;
+
+}
+
?>
diff --git a/header.php b/header.php
@@ -1,7 +1,7 @@
<?php
$nav = "<ul class=\"nav\">\n";
foreach( $pages as $thisPage ) {
- $nav .= "\t\t\t<li id=\"" . $thisPage . "\">\n\t\t\t\t<a href=\"/" . $url . $blogDir . "/pages/" . $thisPage . "\">" . format_name( $thisPage ) . "</a></li>\n";
+ $nav .= "\t\t\t<li id=\"" . $thisPage . "\">\n\t\t\t\t<a href=\"" . URL . BLOG_DIR . "/page/" . link_name( $thisPage ) . "\">" . format_name( $thisPage ) . "</a></li>\n";
}
$nav .= "</ul>";
$title = "Just a Blog";
diff --git a/index.php b/index.php
@@ -18,7 +18,7 @@ require_once( "functions.php" );
require_once( "lib/parsedown/Parsedown.php" );
/* This should probably be an ini file */
-$url = "http://localhost/";
+define( "URL", "http://localhost/" );
if( file_exists( "./blogdir.txt" ) ) {
$blogDir = file_get_contents( "blogdir.txt" );
}
@@ -33,10 +33,10 @@ else {
//$blogDir = $documentRoot . "/" .
preg_match( "([0-9A-Za-z_\-]+)", $blogDir ) . "/";
+ define( "BLOG_DIR", $blogDir );
+
$pages = scandir( "pages/" );
$pages = array_diff( $pages, array( "..", "." ) );
-$posts = scandir( "posts/" );
-$posts = array_diff( $posts, array( "..", "." ) );
/* Make sure a home page exists. One should be supplied for you. */
if( !file_exists( "pages/home.md" ) ) {
@@ -44,16 +44,7 @@ if( !file_exists( "pages/home.md" ) ) {
the pages directory.", E_USER_ERROR );
}
-$postDates = array();
-foreach( $posts as $thisPost ) {
-// $postDates[filectime( "posts/" . $thisPost)] = $thisPost;
- $postDates[] = filectime( "posts/" . $thisPost);
-}
-
-$posts = array_combine( $postDates, $posts );
-
sort( $pages );
-krsort( $posts );
$headerHtml = "templates/header.html";
include( "header.php" );
@@ -67,16 +58,12 @@ else if( isset( $_GET['post'] ) ) {
}
else {
- print( "
- <ul id=\"posts\">" );
- foreach( $posts as $thisPost ) {
- print( "
- <li><a href=\"" . $url . $blogDir . "pages/" . $thisPost . "\">" . date( "Y-m-d", key( $posts ) ) . " - " . format_name( $thisPost ) . "</a></li>" );
- }
- print( "
- </ul>" );
+ $content = file_get_contents( "pages/home.md" );
+}
+
+print( write_html( $parsedown->text( $content ) ) );
write_html( file_get_contents( "html/footer.html" ) );
-}
+
?>
diff --git a/pages/home.md b/pages/home.md
@@ -0,0 +1,3 @@
+# Hello!
+
+{allposts}
diff --git a/pages/this_is_a_test.md b/pages/this_is_a_test.md