blog.php now generates RSS feeds
This commit is contained in:
parent
e0c4ba6064
commit
6aad100966
41
blog.php
41
blog.php
|
@ -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,8 +233,8 @@ $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
|
|||
$newPage = "";
|
||||
$text = "";
|
||||
$html = "";
|
||||
$rss = "";
|
||||
|
||||
if ($action === 'view') {
|
||||
$page = preg_match('@^/@', @$_SERVER["PATH_INFO"]) ?
|
||||
urldecode(substr($_SERVER["PATH_INFO"], 1)) : urldecode(@$_REQUEST['page']);
|
||||
$page = sanitizeFilename($page);
|
||||
|
@ -250,7 +252,6 @@ if ($action === 'view') {
|
|||
} else {
|
||||
$action = 'home';
|
||||
}
|
||||
}
|
||||
|
||||
if ( $action === 'home') {
|
||||
$pageNames = getAllPageNames();
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Reference in a new issue