From 398b5840edcb4179aee2a622138ef103a1fa792f Mon Sep 17 00:00:00 2001 From: sloum Date: Thu, 18 Jan 2024 09:09:45 -0800 Subject: [PATCH] Adds rss capabilities --- .gitignore | 1 + common.php | 8 ++++---- index.php | 7 +------ new-post.php | 2 ++ rss_gen.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 rss_gen.php diff --git a/.gitignore b/.gitignore index 330a5d8..927bba5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ posts/* media/* blog_pass_hash.txt +rssFeed.xml diff --git a/common.php b/common.php index 5977138..30867a7 100644 --- a/common.php +++ b/common.php @@ -19,16 +19,16 @@ function title_from_filename( $fn ) { return $fn; } -function make_date_from_stamp( $ts ) { +function make_date_from_stamp( $ts, $ds=DATE_STYLE ) { // Expects "time" from split_filename - $date = date( DATE_STYLE, (int)$ts ); + $date = date( $ds, (int)$ts ); return $date; } -function split_filename( $fn ) { +function split_filename( $fn, $ds=DATE_STYLE ) { $parts = explode( "_", $fn, 2); $out = []; - $out["time"] = make_date_from_stamp( $parts[0] ); + $out["time"] = make_date_from_stamp( $parts[0], $ds ); $out["title"] = title_from_filename( $parts[1] ); $out["raw"] = urlencode( $fn ); $out["encoded"] = $fn; diff --git a/index.php b/index.php index b9063cb..ec904af 100644 --- a/index.php +++ b/index.php @@ -16,6 +16,7 @@ + @@ -49,9 +50,3 @@ - - - - - - diff --git a/new-post.php b/new-post.php index 5c4bb23..d9b3ebe 100644 --- a/new-post.php +++ b/new-post.php @@ -26,6 +26,8 @@ $success = file_put_contents( "./posts/" . $ts . "_" . urlencode( $title ) . ".md", $body ); if ( $success ) { // Yay! Redirect to admin + include_once( 'rss_gen.php' ); + build_feed(); header("Location: admin.php?success=1"); die(); } else { diff --git a/rss_gen.php b/rss_gen.php new file mode 100644 index 0000000..bc392ae --- /dev/null +++ b/rss_gen.php @@ -0,0 +1,54 @@ + + + + $siteName + $siteRoot + $siteName RSS Feed + $buildDate + $siteLang + + XML; + + $item = <<<'XML' + + %s + %s + %s + %s + + + XML; + + foreach ( array_reverse( $files ) as $f ) { + $fn = split_filename( $f, DATE_RSS ); + $root = $siteRoot . 'post.php?f='; + $t = title_from_filename( $f ); + $header .= sprintf( $item, $fn['title'], $fn['encoded'], $root . $fn['encoded'], $fn['time'] ); + } + + $header .= " \n"; + file_put_contents( "./rssFeed.xml", $header ); +}