Skip to content

Commit

Permalink
v0.0.3
Browse files Browse the repository at this point in the history
* Articles know about previous and next article (break old article templates)
* Theme color
* Classes added to post (for extra styling)
  • Loading branch information
Frank Boës committed Aug 8, 2016
1 parent 91cba8d commit 94fe554
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 51 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
var Generator = require('./lib/generator');

Generator
.buildArticles
.getArticles()
.then(
function (post) {
Generator.buildOtherPages();
Generator.buildAllPages();
Generator.copyImages();
}
)
Expand Down
66 changes: 36 additions & 30 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++) {
Expand All @@ -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'));
});
});
};
Expand Down
16 changes: 16 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions lib/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blogophon",
"version": "0.0.2",
"version": "0.0.3",
"description": "Most-simple blog",
"main": "index.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion theme/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<link rel="alternate" type="application/rss+xml" title="RSS" href="{{config.baseUrl}}{{config.basePath}}posts.rss"/>
<link rel="alternate" type="application/atom+xml" title="ATOM" href="{{config.baseUrl}}{{config.basePath}}posts.atom"/>
<link rel="alternate" type="application/json" title="JSON" href="{{config.baseUrl}}{{config.basePath}}rss.json"/>
{{#config.themeColor}}
<meta name="theme-color" content="{{config.themeColor}}">
{{/config.themeColor}}
</head>
<body class="index">
<div id="container">
Expand All @@ -32,7 +35,7 @@ <h2>{{title}}</h2>

<div class="teasers">
{{#index}}
<article lang="{{meta.Language}}">
<article class="{{meta.Classes}}" lang="{{meta.Language}}">
<span class="date">
<time datetime="{{meta.isoDate}}">{{meta.localeDate}}</time>
</span>
Expand Down
43 changes: 26 additions & 17 deletions theme/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<html lang="{{config.language}}">
<head>
<meta charset="UTF-8" />
<title>{{meta.Title}} - {{config.name}}</title>
<title>{{post.meta.Title}} - {{config.name}}</title>
<meta property="og:type" content="page" />
<meta property="og:site_name" content="{{config.name}}" />
<meta property="og:url" content="{{config.baseUrl}}{{config.basePath}}{{meta.Url}}" />
<meta property="og:title" name="title" content="{{meta.Title}}" />
<meta property="og:description" name="description" content="{{meta.Description}}" />
{{#meta.Keywords}}
<meta name="keywords" content="{{meta.Keywords}}" />
{{/meta.Keywords}}
<meta property="og:url" content="{{config.baseUrl}}{{config.basePath}}{{post.meta.Url}}" />
<meta property="og:title" name="title" content="{{post.meta.Title}}" />
<meta property="og:description" name="description" content="{{post.meta.Description}}" />
{{#post.meta.Keywords}}
<meta name="keywords" content="{{post.meta.Keywords}}" />
{{/post.meta.Keywords}}
<link type="image/x-icon" href="http://cdn.3960.org/css/favicon.ico" rel="shortcut icon"/>
<link rel="apple-touch-icon" href="http://cdn.3960.org/css/iphone.png" type="image/png" />
<link rel="publisher" href="https://plus.google.com/111597900565235858304" />
Expand All @@ -20,6 +20,9 @@
<link rel="alternate" type="application/rss+xml" title="RSS" href="{{config.baseUrl}}{{config.basePath}}posts.rss"/>
<link rel="alternate" type="application/atom+xml" title="ATOM" href="{{config.baseUrl}}{{config.basePath}}posts.atom"/>
<link rel="alternate" type="application/json" title="JSON" href="{{config.baseUrl}}{{config.basePath}}rss.json"/>
{{#config.themeColor}}
<meta name="theme-color" content="{{config.themeColor}}">
{{/config.themeColor}}
</head>
<body class="post">
<div id="container">
Expand All @@ -29,23 +32,29 @@ <h1 id="header"><a href="{{config.basePath}}">{{config.name}}</a></h1>
<div id="main">
<main>
<div id="content">
<article lang="{{meta.Language}}">
<article class="{{post.meta.Classes}}" lang="{{post.meta.Language}}">
<span class="date">
<time datetime="{{meta.isoDate}}">{{meta.localeDate}}</time>
<time datetime="{{post.meta.isoDate}}">{{post.meta.localeDate}}</time>
</span>
{{{content}}}
{{#meta.Tags.length}}
{{{post.html}}}
{{#post.meta.Tags.length}}
<p class="meta">
Andere Artikel zum Thema
{{#meta.Tags}}
{{#post.meta.Tags}}
· <a rel="tag" href="{{config.basePath}}tagged/{{id}}/">„{{title}}”</a>
{{/meta.Tags}}
{{/post.meta.Tags}}
</p>
{{/meta.Tags.length}}
{{/post.meta.Tags.length}}
</article>
<p style="margin-top:1em;text-align:right;" class="noprint">
<a href="../.." rel="up" id="up">Zurück zur Übersichtsseite</a>
</p>
<div id="prevnext">
<a href="../.." rel="up" id="up" style="font-size:1em;">Zurück zur Übersichtsseite</a>
{{#post.prev.Url}}
<a href="{{post.prev.Url}}" rel="prev" class="prev" title="{{post.prev.Title}}">&laquo;</a>
{{/post.prev.Url}}
{{#post.next.Url}}
<a href="{{post.next.Url}}" rel="next" class="next" title="{{post.next.Url}}">&raquo;</a>
{{/post.next.Url}}
</div>
</div>
</main>
<aside>
Expand Down
1 change: 1 addition & 0 deletions user/_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "Most-simple blog",
"language": "en",
"siteEmail": "",
"themeColor": "#ffffff",
"deploy":"",
"imageSizes": [
[200,200],
Expand Down

0 comments on commit 94fe554

Please sign in to comment.