aboutsummaryrefslogtreecommitdiffstats
path: root/generate.php
diff options
context:
space:
mode:
authorFran├žois Kooman <fkooman@tuxed.net>2017-02-27 11:11:19 +0100
committerFran├žois Kooman <fkooman@tuxed.net>2017-02-27 11:11:19 +0100
commitf71a9632d406ea4d182f83333b563d64c86364e5 (patch)
tree2d6ff3745db7747b9a3604f503129fec6dc409ae /generate.php
parent9e60ba02214c8bc28423d74295408f523072245c (diff)
downloadwww.tuxed.net-f71a9632d406ea4d182f83333b563d64c86364e5.zip
www.tuxed.net-f71a9632d406ea4d182f83333b563d64c86364e5.tar.gz
www.tuxed.net-f71a9632d406ea4d182f83333b563d64c86364e5.tar.xz
introduce RSS feed
Diffstat (limited to 'generate.php')
-rw-r--r--generate.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/generate.php b/generate.php
index c829c66..9a0eff3 100644
--- a/generate.php
+++ b/generate.php
@@ -3,6 +3,9 @@
require_once 'vendor/autoload.php';
use Michelf\MarkdownExtra;
+use Suin\RSSWriter\Channel;
+use Suin\RSSWriter\Feed;
+use Suin\RSSWriter\Item;
$postDir = sprintf('%s/posts', __DIR__);
$pageDir = sprintf('%s/pages', __DIR__);
@@ -23,6 +26,19 @@ $blogAuthorMailFingerprint = '6237 BAF1 418A 907D AA98 EAA7 9C5E DD64 5A57 1EB2
$loader = new Twig_Loader_Filesystem($templateDir);
$twig = new Twig_Environment($loader, ['strict_variables' => true]);
+$dateTime = new DateTime();
+
+$feed = new Feed();
+$channel = new Channel();
+$channel
+ ->title($blogTitle)
+ ->description($blogDescription)
+ ->url($blogUrl)
+ ->language('en-US')
+ ->pubDate($dateTime->getTimestamp())
+ ->lastBuildDate($dateTime->getTimestamp())
+ ->appendTo($feed);
+
$postsList = [];
$pagesList = [];
@@ -100,6 +116,20 @@ foreach (glob(sprintf('%s/*.md', $postDir)) as $postFile) {
'fileName' => $postOutputFile,
];
$postsList[] = $blogPost;
+
+ if ($blogPost['publish']) {
+ $item = new Item();
+ $item
+ ->title($blogPost['title'])
+ ->description($blogPost['description'])
+ ->contentEncoded($blogPost['htmlContent'])
+ ->url(sprintf('%s%s', $blogUrl, $blogPost['fileName']))
+ ->author($blogAuthorMail)
+ ->pubDate(strtotime($blogPost['published']))
+ ->guid(sprintf('%s%s', $blogUrl, $blogPost['fileName']))
+ ->preferCdata(true) // By this, title and description become CDATA wrapped HTML.
+ ->appendTo($channel);
+ }
}
usort($postsList, function ($a, $b) {
@@ -184,3 +214,5 @@ foreach (glob(__DIR__.'/img/*') as $imgFile) {
// copy css
@mkdir($outputDir.'/css');
copy(__DIR__.'/screen.css', $outputDir.'/css/screen.css');
+
+file_put_contents($outputDir.'/feed.xml', $feed);