blog.php now generates RSS feeds
This commit is contained in:
parent
e0c4ba6064
commit
6aad100966
65
blog.php
65
blog.php
|
@ -15,8 +15,10 @@ spl_autoload_register(function($class){
|
||||||
use md\MarkdownExtra;
|
use md\MarkdownExtra;
|
||||||
|
|
||||||
define('BLOG_PATH', dirname(__FILE__). '/articles');
|
define('BLOG_PATH', dirname(__FILE__). '/articles');
|
||||||
|
|
||||||
define('BLOG_EXT', 'md');
|
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('BASE_URI', str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']));
|
||||||
|
|
||||||
define('SELF', $_SERVER['SCRIPT_NAME']);
|
define('SELF', $_SERVER['SCRIPT_NAME']);
|
||||||
|
@ -231,25 +233,24 @@ $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
|
||||||
$newPage = "";
|
$newPage = "";
|
||||||
$text = "";
|
$text = "";
|
||||||
$html = "";
|
$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']);
|
||||||
urldecode(substr($_SERVER["PATH_INFO"], 1)) : urldecode(@$_REQUEST['page']);
|
$page = sanitizeFilename($page);
|
||||||
$page = sanitizeFilename($page);
|
|
||||||
|
|
||||||
if ($page != '') {
|
if ($page != '') {
|
||||||
$filename = fileNameForPage($page);
|
$filename = fileNameForPage($page);
|
||||||
|
|
||||||
if ( file_exists($filename) ) {
|
if ( file_exists($filename) ) {
|
||||||
$text = file_get_contents($filename);
|
$text = file_get_contents($filename);
|
||||||
} else {
|
|
||||||
$newPage = NULL;
|
|
||||||
include('php/404.php');
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$action = 'home';
|
$newPage = NULL;
|
||||||
|
include('php/404.php');
|
||||||
|
die();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$action = 'home';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $action === 'home') {
|
if ( $action === 'home') {
|
||||||
|
@ -266,9 +267,43 @@ if ( $action === 'home') {
|
||||||
// Page list
|
// Page list
|
||||||
$date_format = __('date_format', TITLE_DATE);
|
$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) {
|
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";
|
$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
|
} else { // convert the page and view it
|
||||||
$html .= empty($text) ? '' : toHTML($text);
|
$html .= empty($text) ? '' : toHTML($text);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue