blog.php now generates RSS feeds

This commit is contained in:
Jacob 2023-07-01 12:33:55 +02:00
parent e0c4ba6064
commit 6aad100966
2 changed files with 1262 additions and 281 deletions

View file

@ -15,8 +15,10 @@ spl_autoload_register(function($class){
use md\MarkdownExtra;
define('BLOG_PATH', dirname(__FILE__). '/articles');
define('BLOG_EXT', 'md');
define('BLOG_TITLE', "speedie's blog");
define('BLOG_DESC', "speedie's blog, about stuff I want to talk about.");
define('BLOG_URL', "https://speedie.site/blog");
define('BASE_URI', str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']));
define('SELF', $_SERVER['SCRIPT_NAME']);
@ -231,13 +233,13 @@ $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
$newPage = "";
$text = "";
$html = "";
$rss = "";
if ($action === 'view') {
$page = preg_match('@^/@', @$_SERVER["PATH_INFO"]) ?
$page = preg_match('@^/@', @$_SERVER["PATH_INFO"]) ?
urldecode(substr($_SERVER["PATH_INFO"], 1)) : urldecode(@$_REQUEST['page']);
$page = sanitizeFilename($page);
$page = sanitizeFilename($page);
if ($page != '') {
if ($page != '') {
$filename = fileNameForPage($page);
if ( file_exists($filename) ) {
@ -247,9 +249,8 @@ if ($action === 'view') {
include('php/404.php');
die();
}
} else {
} else {
$action = 'home';
}
}
if ( $action === 'home') {
@ -266,9 +267,43 @@ if ( $action === 'home') {
// Page list
$date_format = __('date_format', TITLE_DATE);
// Create the RSS feed
$rss .= "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
$rss .= "<channel>\n";
$rss .= " <title>". BLOG_TITLE ."</title>\n";
$rss .= " <description>". BLOG_DESC ."</description>\n";
$rss .= " <atom:link href=\"". BLOG_URL ."\" rel=\"self\" type=\"application/rss+xml\" />\n";
foreach ($filelist as $pageName => $pageDate) {
$pubDate = date('r', strtotime(getDateForPage($pageName, $date_format, $pageDate)));
$link = pageURL($pageName, $pageName);
$filename = fileNameForPage($pageName);
$text = file_get_contents($filename);
$description = toHTML($text);
$rss .= "<item>\n";
$rss .= " <title>$pageName</title>\n";
$rss .= " <link>$link</link>\n";
$rss .= " <guid>$link</guid>\n";
$rss .= " <pubDate>$pubDate</pubDate>\n";
$rss .= " <description>\n";
$rss .= " <![CDATA[\n";
$rss .= " $description\n";
$rss .= " ]]>\n";
$rss .= " </description>\n";
$rss .= "</item>\n";
$html .= "<p>".pageLink($pageName, $pageName).", written ".getDateForPage($pageName, $date_format, $pageDate)."</p>\n";
}
// End the RSS feed
$rss .= "</channel>\n";
$rss .= "</rss>\n";
if (file_get_contents('rss.xml') != $rss) {
file_put_contents('rss.xml', $rss);
echo "GNU";
}
} else { // convert the page and view it
$html .= empty($text) ? '' : toHTML($text);
}

1472
rss.xml

File diff suppressed because it is too large Load diff