From 94fe55449c9066a0ddc2d562e15ca071464f06b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Boe=CC=88s?= Date: Mon, 8 Aug 2016 09:23:24 +0200 Subject: [PATCH] v0.0.3 * Articles know about previous and next article (break old article templates) * Theme color * Classes added to post (for extra styling) --- index.js | 4 +-- lib/generator.js | 66 ++++++++++++++++++++++++++--------------------- lib/index.js | 16 ++++++++++++ lib/post.js | 6 +++++ package.json | 2 +- theme/index.html | 5 +++- theme/post.html | 43 ++++++++++++++++++------------ user/_config.json | 1 + 8 files changed, 92 insertions(+), 51 deletions(-) diff --git a/index.js b/index.js index e9366f9b..ac4b3c4d 100755 --- a/index.js +++ b/index.js @@ -4,10 +4,10 @@ var Generator = require('./lib/generator'); Generator - .buildArticles + .getArticles() .then( function (post) { - Generator.buildOtherPages(); + Generator.buildAllPages(); Generator.copyImages(); } ) diff --git a/lib/generator.js b/lib/generator.js index 2a56aee8..f9cda876 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -33,42 +33,46 @@ var index = require('./index')(); * [buildArticles description] * @return {[type]} [description] */ -Generator.buildArticles = new Promise ( - function(resolve, reject) { - glob(config.directories.data + "/**/*.md", function (er, files) { - var i, finished = 0; - PostReader.on('parsed', function (post) { - shell.mkdir('-p', config.directories.htdocs + '/' + post.meta.Url); - fs.writeFile(config.directories.htdocs + '/' + post.meta.Url + 'index.html', Mustache.render(templates.post, { - meta: post.meta, - content: post.html, - config: config - })); - index.push(post); - finished ++; - if (finished === files.length) { - console.log("Wrote " + finished + " articles"); - resolve( finished ); +Generator.getArticles = function() { + return new Promise ( + function(resolve, reject) { + glob(config.directories.data + "/**/*.md", function (er, files) { + var i, finished = 0; + PostReader.on('parsed', function (post) { + index.push(post); + finished ++; + if (finished === files.length) { + index.makeNextPrev(); + resolve( finished ); + } + }); + for (i = 0; i < files.length; i++) { + PostReader.parse(files[i]); } }); - for (i = 0; i < files.length; i++) { - PostReader.parse(files[i]); - } - }); - } -); + } + ); +}; /** * [buildOtherPages description] * @return {[type]} [description] */ -Generator.buildOtherPages = function ( ) { - var pagedPosts = index.getPagedPosts(5), page, indexFilename; +Generator.buildAllPages = function ( ) { + var pagedPosts = index.getPagedPosts(5), page, indexFilename, i, allPosts = index.getPosts(); var fileReady = function(filename) { console.log("Wrote " + filename); }; + console.log(allPosts); - fs.writeFile(config.directories.htdocs + '/sitemap.json', JSON.stringify(index.getPosts()), fileReady("sitemap.json")); + for (i = 0; i < allPosts.length; i++) { + var post = allPosts[i]; + shell.mkdir('-p', config.directories.htdocs + '/' + post.meta.Url); + fs.writeFile(config.directories.htdocs + post.meta.Url + 'index.html', Mustache.render(templates.post, { + post: post, + config: config + }),fileReady( post.meta.Url + 'index.html')); + } fs.remove(config.directories.htdocs + '/index*', function (err) { for (page = 0; page < pagedPosts.length; page ++) { @@ -79,31 +83,33 @@ Generator.buildOtherPages = function ( ) { } }); + fs.writeFile(config.directories.htdocs + '/sitemap.json', JSON.stringify(allPosts), fileReady("/sitemap.json")); + fs.writeFile(config.directories.htdocs + '/posts.rss', Mustache.render(templates.rss, { index: index.getPosts(10), pubDate: dateFormat(index.pubDate, 'ddd, dd mmm yyyy hh:MM:ss o'), config: config - }), fileReady('posts.rss')); + }), fileReady('/posts.rss')); - fs.writeFile(config.directories.htdocs + '/rss.json', JSON.stringify(RssJs(index.getPosts(), dateFormat(index.pubDate, 'ddd, dd mmm yyyy hh:MM:ss o'))), fileReady('rss.json')); + fs.writeFile(config.directories.htdocs + '/rss.json', JSON.stringify(RssJs(allPosts, dateFormat(index.pubDate, 'ddd, dd mmm yyyy hh:MM:ss o'))), fileReady('/rss.json')); fs.writeFile(config.directories.htdocs + '/posts.atom', Mustache.render(templates.atom, { index: index.getPosts(10), pubDate: dateFormat(index.pubDate, 'isoDateTime'), config: config - }), fileReady('posts.atom')); + }), fileReady('/posts.atom')); fs.writeFile(config.directories.htdocs + '/sitemap.xml', Mustache.render(templates.sitemap, { index: index.getPosts(10), config: config - }), fileReady('sitemap.xml')); + }), fileReady('/sitemap.xml')); var tags = index.getTags(); fs.remove(config.directories.htdocs + '/tagged', function (err) { Object.keys(tags).map(function (key) { shell.mkdir('-p', config.directories.htdocs + '/tagged/' + tags[key].id); tags[key].config = config; - fs.writeFile(config.directories.htdocs + '/tagged/' + tags[key].id + '/index.html', Mustache.render(templates.index, tags[key]), fileReady("tagged/" + tags[key].id + '/index.html')); + fs.writeFile(config.directories.htdocs + '/tagged/' + tags[key].id + '/index.html', Mustache.render(templates.index, tags[key]), fileReady("/tagged/" + tags[key].id + '/index.html')); }); }); }; diff --git a/lib/index.js b/lib/index.js index 47a86c44..e2214d38 100644 --- a/lib/index.js +++ b/lib/index.js @@ -39,6 +39,22 @@ var Index = function () { index.push(post); }, + makeNextPrev: function () { + if (!isSorted) { + sortIndex(); + } + var i; + for(i = 0; i < index.length; i++) { + if (i > 0 && index[i-1]) { + index[i].prev = index[i-1].meta; + } + if (i < index.length -1 && index[i+1]) { + index[i].next = index[i+1].meta; + } + } + return this; + }, + /** * Get all posts, sorted by date. * @param {integer} i Only return i results. If left empty, all results will be returned. diff --git a/lib/post.js b/lib/post.js index faad5abb..a3175be8 100644 --- a/lib/post.js +++ b/lib/post.js @@ -62,6 +62,12 @@ var Post = function (markdown, meta) { }); }); } + if (meta.Classes === undefined) { + meta.Classes = ''; + } + meta.Classes = meta.Classes.trim().split(/,\s+/).map(function(c) { + return c.toId(); + }); if (meta.Description !== undefined) { meta.Description = meta.Description.replace(/\[(.+?)\]\(.+?\)/g, '$1').trim(); } diff --git a/package.json b/package.json index ec88f441..5a0ccecb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blogophon", - "version": "0.0.2", + "version": "0.0.3", "description": "Most-simple blog", "main": "index.js", "scripts": { diff --git a/theme/index.html b/theme/index.html index 9ae65221..4bcf882a 100644 --- a/theme/index.html +++ b/theme/index.html @@ -17,6 +17,9 @@ + {{#config.themeColor}} + + {{/config.themeColor}}
@@ -32,7 +35,7 @@

{{title}}

{{#index}} -
+
diff --git a/theme/post.html b/theme/post.html index c73f2e7c..2d8ded1d 100644 --- a/theme/post.html +++ b/theme/post.html @@ -2,15 +2,15 @@ - {{meta.Title}} - {{config.name}} + {{post.meta.Title}} - {{config.name}} - - - - {{#meta.Keywords}} - - {{/meta.Keywords}} + + + + {{#post.meta.Keywords}} + + {{/post.meta.Keywords}} @@ -20,6 +20,9 @@ + {{#config.themeColor}} + + {{/config.themeColor}}
@@ -29,23 +32,29 @@

{{config.name}}

-
+
- + - {{{content}}} - {{#meta.Tags.length}} + {{{post.html}}} + {{#post.meta.Tags.length}}

Andere Artikel zum Thema - {{#meta.Tags}} + {{#post.meta.Tags}} · - {{/meta.Tags}} + {{/post.meta.Tags}}

- {{/meta.Tags.length}} + {{/post.meta.Tags.length}}
-

- Zurück zur Übersichtsseite -

+
+ Zurück zur Übersichtsseite + {{#post.prev.Url}} + + {{/post.prev.Url}} + {{#post.next.Url}} + + {{/post.next.Url}} +