aboutsummaryrefslogtreecommitdiffstats
path: root/generate.php
diff options
context:
space:
mode:
authorFrançois Kooman <fkooman@tuxed.net>2019-04-23 17:31:22 +0200
committerFrançois Kooman <fkooman@tuxed.net>2019-04-23 17:31:22 +0200
commit64ea114374fcec4a114e572df26396fbe46dd639 (patch)
treec215736ac4f2fe10d09d33b3e8f3d8fa34c9814b /generate.php
parent8c665d6214602e72f2250e10fb0e89ca27affbaf (diff)
downloadwww.tuxed.net-64ea114374fcec4a114e572df26396fbe46dd639.zip
www.tuxed.net-64ea114374fcec4a114e572df26396fbe46dd639.tar.gz
www.tuxed.net-64ea114374fcec4a114e572df26396fbe46dd639.tar.xz
update site
Diffstat (limited to 'generate.php')
-rw-r--r--generate.php218
1 files changed, 0 insertions, 218 deletions
diff --git a/generate.php b/generate.php
deleted file mode 100644
index 9180790..0000000
--- a/generate.php
+++ /dev/null
@@ -1,218 +0,0 @@
-<?php
-
-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__);
-$outputDir = sprintf('%s/output', __DIR__);
-$blogOutputDir = sprintf('%s/blog', $outputDir);
-$templateDir = sprintf('%s/views', __DIR__);
-
-$blogTitle = "François' Blog";
-$blogDescription = 'Just another boring weblog.';
-$blogUrl = 'https://www.tuxed.net/fkooman/blog/';
-$blogAuthor = 'François Kooman';
-
-$blogAuthorTwitter = 'fkooman';
-$blogAuthorGitHub = 'fkooman';
-$blogAuthorMail = 'fkooman@tuxed.net';
-$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 = [];
-
-@mkdir($outputDir, 0755, true);
-@mkdir($blogOutputDir, 0755, true);
-
-foreach (glob(sprintf('%s/*.md', $pageDir)) as $pageFile) {
- $pageInfo = [];
-
- $f = fopen($pageFile, 'r');
- $line = fgets($f);
- if (0 !== strpos($line, '---')) {
- throw new Exception(sprintf('invalid file "%s"!', $pageFile));
- }
- $line = fgets($f);
- do {
- $xx = explode(':', $line, 2);
- $pageInfo[trim($xx[0])] = trim($xx[1]);
- $line = fgets($f);
- } while (0 !== strpos($line, '---'));
-
- // read rest of the page
- $buffer = '';
- while (!feof($f)) {
- $buffer .= fgets($f);
- }
-
- fclose($f);
- $pageOutputFile = basename($pageFile, '.md').'.html';
-
- $parser = new MarkdownExtra();
- $page = [
- 'htmlContent' => $parser->transform($buffer),
- 'publish' => isset($pageInfo['publish']) ? 'no' !== $pageInfo['publish'] : true,
- 'title' => $pageInfo['title'],
- 'fileName' => $pageOutputFile,
- ];
- $pagesList[] = $page;
-}
-
-foreach (glob(sprintf('%s/*.md', $postDir)) as $postFile) {
- $postInfo = [];
-
- // obtain postInfo
- $f = fopen($postFile, 'r');
- $line = fgets($f);
- if (0 !== strpos($line, '---')) {
- throw new Exception(sprintf('invalid file! "%s"', $postFile));
- }
- $line = fgets($f);
- do {
- $xx = explode(':', $line, 2);
- $postInfo[trim($xx[0])] = trim($xx[1]);
- $line = fgets($f);
- } while (0 !== strpos($line, '---'));
-
- // read rest of the post
- $buffer = '';
- while (!feof($f)) {
- $buffer .= fgets($f);
- }
-
- fclose($f);
- $postOutputFile = basename($postFile, '.md').'.html';
-
- $parser = new MarkdownExtra();
-
- $blogPost = [
- 'htmlContent' => $parser->transform($buffer),
- 'description' => isset($postInfo['description']) ? $postInfo['description'] : $postInfo['title'],
- 'published' => $postInfo['published'],
- 'publish' => isset($postInfo['publish']) ? 'no' !== $postInfo['publish'] : true,
- 'title' => $postInfo['title'],
- 'modified' => isset($postInfo['modified']) ? $postInfo['modified'] : null,
- '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) {
- return strtotime($a['published']) < strtotime($b['published']);
-});
-
-$siteIndexPage = $twig->render(
- 'index.twig',
- [
- 'toRoot' => '',
- 'pagesList' => $pagesList,
- 'activePage' => 'index.html',
- 'postsList' => $postsList,
- 'pageTitle' => 'Blog',
- 'blogTitle' => $blogTitle,
- 'blogDescription' => $blogDescription,
- 'blogAuthor' => $blogAuthor,
- ]
-);
-
-$blogIndexPage = $twig->render(
- 'index.twig',
- [
- 'toRoot' => '../',
- 'pagesList' => $pagesList,
- 'activePage' => 'index.html',
- 'postsList' => $postsList,
- 'pageTitle' => 'Blog',
- 'blogTitle' => $blogTitle,
- 'blogDescription' => $blogDescription,
- 'blogAuthor' => $blogAuthor,
- ]
-);
-
-foreach ($postsList as $post) {
- if ($post['publish']) {
- $postPage = $twig->render(
- 'post.twig',
- [
- 'toRoot' => '../',
- 'pagesList' => $pagesList,
- 'activePage' => 'index.html',
- 'blogTitle' => $blogTitle,
- 'pageTitle' => $post['title'],
- 'post' => $post,
- 'blogDescription' => $blogDescription,
- 'blogAuthor' => $blogAuthor,
- ]
- );
- file_put_contents($blogOutputDir.'/'.$post['fileName'], $postPage);
- }
-}
-
-foreach ($pagesList as $page) {
- if ($post['publish']) {
- $pagePage = $twig->render(
- 'page.twig',
- [
- 'toRoot' => '',
- 'activePage' => $page['fileName'],
- 'pagesList' => $pagesList,
- 'blogTitle' => $blogTitle,
- 'pageTitle' => $page['title'],
- 'pageContent' => $page,
- 'blogDescription' => $blogDescription,
- 'blogAuthor' => $blogAuthor,
- ]
- );
- file_put_contents($outputDir.'/'.$page['fileName'], $pagePage);
- }
-}
-
-file_put_contents($outputDir.'/index.html', $siteIndexPage);
-file_put_contents($blogOutputDir.'/index.html', $blogIndexPage);
-
-// copy img
-@mkdir($outputDir.'/img');
-foreach (glob(__DIR__.'/img/*') as $imgFile) {
- copy($imgFile, $outputDir.'/img/'.basename($imgFile));
-}
-
-// copy css
-@mkdir($outputDir.'/css');
-copy(__DIR__.'/screen.css', $outputDir.'/css/screen.css');
-
-file_put_contents($outputDir.'/feed.xml', $feed);