aboutsummaryrefslogtreecommitdiffstats
path: root/generate.php
diff options
context:
space:
mode:
authorFran├žois Kooman <fkooman@tuxed.net>2017-01-07 20:40:44 +0100
committerFran├žois Kooman <fkooman@tuxed.net>2017-01-07 20:40:44 +0100
commitc44287313ec05665f4e9b2df8fb4db4ce2cb7b7e (patch)
tree37566e3eaa4c559f692f5d49d7d864738f9b14e8 /generate.php
parent0fa6ad7f34739099792dbb927d9c3f27340a226f (diff)
downloadwww.tuxed.net-c44287313ec05665f4e9b2df8fb4db4ce2cb7b7e.zip
www.tuxed.net-c44287313ec05665f4e9b2df8fb4db4ce2cb7b7e.tar.gz
www.tuxed.net-c44287313ec05665f4e9b2df8fb4db4ce2cb7b7e.tar.xz
generate pages as well
Diffstat (limited to 'generate.php')
-rw-r--r--generate.php75
1 files changed, 58 insertions, 17 deletions
diff --git a/generate.php b/generate.php
index 2034a26..33978a7 100644
--- a/generate.php
+++ b/generate.php
@@ -5,6 +5,7 @@ require_once 'vendor/autoload.php';
use Michelf\MarkdownExtra;
$postDir = sprintf('%s/posts', __DIR__);
+$pageDir = sprintf('%s/pages', __DIR__);
$outputDir = sprintf('%s/output', __DIR__);
$templateDir = sprintf('%s/views', __DIR__);
@@ -21,7 +22,42 @@ $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]);
-$blogPosts = [];
+$postsList = [];
+$pagesList = [];
+
+foreach (glob(sprintf('%s/*.md', $pageDir)) as $pageFile) {
+ $pageInfo = [];
+
+ $f = fopen($pageFile, 'r');
+ $line = fgets($f);
+ if (0 !== strpos($line, '---')) {
+ throw new Exception('invalid file!');
+ }
+ $line = fgets($f);
+ do {
+ $xx = explode(':', $line);
+ $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 = [];
@@ -69,32 +105,22 @@ usort($postsList, function ($a, $b) {
$indexPage = $twig->render(
'index.twig',
[
+ 'pagesList' => $pagesList,
+ 'activePage' => 'index.html',
'postsList' => $postsList,
- 'pageTitle' => 'Index',
+ 'pageTitle' => 'Blog',
'blogTitle' => $blogTitle,
'blogDescription' => $blogDescription,
'blogAuthor' => $blogAuthor
]
);
-$contactPage = $twig->render(
- 'contact.twig',
- [
- 'blogTitle' => $blogTitle,
- 'blogDescription' => $blogDescription,
- 'blogAuthor' => $blogAuthor,
- 'pageTitle' => 'Contact',
- 'blogAuthorMail' => $blogAuthorMail,
- 'blogAuthorTwitter' => $blogAuthorTwitter,
- 'blogAuthorGitHub' => $blogAuthorGitHub,
- 'blogAuthorMailFingerprint' => $blogAuthorMailFingerprint,
- ]
-);
-
foreach ($postsList as $post) {
$postPage = $twig->render(
'post.twig',
[
+ 'pagesList' => $pagesList,
+ 'activePage' => 'index.html',
'blogTitle' => $blogTitle,
'pageTitle' => $post['title'],
'post' => $post,
@@ -105,8 +131,23 @@ foreach ($postsList as $post) {
file_put_contents($outputDir.'/'.$post['fileName'], $postPage);
}
+foreach ($pagesList as $page) {
+ $pagePage = $twig->render(
+ 'page.twig',
+ [
+ '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', $indexPage);
-file_put_contents($outputDir.'/contact.html', $contactPage);
// copy img
//@mkdir($outputDir.'/img');