Add simple templating with pug

This commit is contained in:
Tom Raithel
2017-01-22 22:29:02 +01:00
parent bd6e4ebc1c
commit 0dde930d64
7 changed files with 41 additions and 38 deletions

View File

@@ -18,6 +18,7 @@
"front-matter": "2.1.1", "front-matter": "2.1.1",
"fs-extra": "2.0.0", "fs-extra": "2.0.0",
"marked": "0.3.6", "marked": "0.3.6",
"pug": "2.0.0-beta6",
"walk": "2.3.9" "walk": "2.3.9"
} }
} }

View File

@@ -10,17 +10,3 @@ Hier noch ein [link](http://www.google.de) zu google
<!--except--> <!--except-->
Hier steht der Rest! Hier steht der Rest!
History
-------
{% include
history-entry.html
ring="trial"
date="2017-12-10"
content="This is a history entry
- Foo
- Bar
"
%}

View File

@@ -3,24 +3,9 @@ title: "React"
ring: trial ring: trial
--- ---
Hier steht eine Einleitung über *React* - super "cool" React blablab *React* - super "cool"
Hier noch ein [link](http://www.google.de) zu google
<!--except--> <!--except-->
Hier steht der Rest! Hier steht der Rest!
History
-------
{% include
history-entry.html
ring="trial"
date="2017-12-10"
content="This is a history entry
- Foo
- Bar
"
%}

View File

@@ -4,6 +4,7 @@ import path from 'path';
import frontmatter from 'front-matter'; import frontmatter from 'front-matter';
import marked from 'marked'; import marked from 'marked';
import { srcPath, distPath } from './file'; import { srcPath, distPath } from './file';
import { item as itemTemplate } from './template';
export const createRadar = async (tree) => { export const createRadar = async (tree) => {
const fileNames = await getAllMarkdownFiles(); const fileNames = await getAllMarkdownFiles();
@@ -52,7 +53,7 @@ const createRevisionsFromFiles = (fileNames) => (
...itemInfoFromFilename(fileName), ...itemInfoFromFilename(fileName),
fileName, fileName,
attributes: fm.attributes, attributes: fm.attributes,
body: fm.body, body: marked(fm.body),
}); });
} }
}); });
@@ -98,6 +99,7 @@ const addRevisionToItem = (item = {
...rest, ...rest,
} = revision; } = revision;
return { return {
quadrant,
attributes: { attributes: {
...item.attributes, ...item.attributes,
...revision.attributes, ...revision.attributes,
@@ -111,20 +113,17 @@ export const outputRadar = (radar) => {
return Promise.all( return Promise.all(
Object.entries(radar).map(([quadrantName, quadrant]) => ( Object.entries(radar).map(([quadrantName, quadrant]) => (
Object.entries(quadrant).map(([itemName, item]) => ( Object.entries(quadrant).map(([itemName, item]) => (
new Promise((resolve, reject) => ( new Promise((resolve, reject) => {
outputFile(distPath(quadrantName, `${itemName}.html`), getItemHtml(item), (err, data) => { console.log(JSON.stringify(item, null, 2));
outputFile(distPath(quadrantName, `${itemName}.html`), itemTemplate(item), (err, data) => {
if (err) { if (err) {
reject(err); reject(err);
} else { } else {
resolve(data); resolve(data);
} }
}) })
)) })
)) ))
)) ))
); );
}; };
const getItemHtml = (item) => (`
<h1>${item.attributes.title}</h1>
`)

6
scripts/template.js Normal file
View File

@@ -0,0 +1,6 @@
import pug from 'pug';
import { relativePath } from './file';
const templateFolder = 'templates';
export const item = pug.compileFile(relativePath(templateFolder, 'item.pug'));

19
templates/item.pug Normal file
View File

@@ -0,0 +1,19 @@
extends layout.pug
block content
a(href='/' + quadrant + '.html') #{quadrant}
h1 #{attributes.title}
= ' '
small #{attributes.ring}
hr
section
!= revisions[0].body
hr
ul
each revision, index in revisions
if index > 0
li
= revision.version
!= revision.body

7
templates/layout.pug Normal file
View File

@@ -0,0 +1,7 @@
html
head
title #{attributes.title} - AOE Tech Radar
block scripts
script(src='/jquery.js')
body
block content