Add support for static pages
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"create": "npm run clean && babel-node ./scripts/create.js",
|
"build": "npm run clean && babel-node ./scripts/build.js",
|
||||||
"clean": "babel-node ./scripts/clean.js",
|
"clean": "babel-node ./scripts/clean.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,14 +14,3 @@ Hier steht der Rest!
|
|||||||
|
|
||||||
History
|
History
|
||||||
-------
|
-------
|
||||||
|
|
||||||
{% include
|
|
||||||
history-entry.html
|
|
||||||
ring="trial"
|
|
||||||
date="2017-12-10"
|
|
||||||
content="This is a history entry
|
|
||||||
|
|
||||||
- Foo
|
|
||||||
- Bar
|
|
||||||
"
|
|
||||||
%}
|
|
||||||
|
|||||||
21
scripts/build.js
Normal file
21
scripts/build.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import {
|
||||||
|
createRadar,
|
||||||
|
outputRadar,
|
||||||
|
} from './radar';
|
||||||
|
import {
|
||||||
|
createStatic,
|
||||||
|
} from './static';
|
||||||
|
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const radar = await createRadar();
|
||||||
|
outputRadar(radar);
|
||||||
|
createStatic(radar);
|
||||||
|
|
||||||
|
console.log('Radar build!');
|
||||||
|
console.log(JSON.stringify(radar, null, 2));
|
||||||
|
} catch(e) {
|
||||||
|
console.error('error:', e);
|
||||||
|
}
|
||||||
|
})()
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
import {
|
|
||||||
readFile,
|
|
||||||
outputFile,
|
|
||||||
} from 'fs-extra';
|
|
||||||
import frontmatter from 'front-matter';
|
|
||||||
import marked from 'marked';
|
|
||||||
import waterfall from 'async/waterfall';
|
|
||||||
import {
|
|
||||||
srcPath,
|
|
||||||
distPath,
|
|
||||||
} from './file';
|
|
||||||
import {
|
|
||||||
createRadar,
|
|
||||||
outputRadar,
|
|
||||||
} from './radar';
|
|
||||||
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
const radar = await createRadar();
|
|
||||||
outputRadar(radar);
|
|
||||||
// console.log(JSON.stringify(radar, null, 2));
|
|
||||||
} catch(e) {
|
|
||||||
console.error('error:', e);
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
//
|
|
||||||
// const fileName = srcPath('v1/tools/grunt.md');
|
|
||||||
//
|
|
||||||
// console.log('<<< start creating files');
|
|
||||||
//
|
|
||||||
// waterfall([
|
|
||||||
// (callback) => {
|
|
||||||
// readFile(fileName, 'utf8', callback);
|
|
||||||
// },
|
|
||||||
// (data, callback) => {
|
|
||||||
// const item = frontmatter(data);
|
|
||||||
// const html = marked(item.body);
|
|
||||||
//
|
|
||||||
// outputFile(distPath('test3.html'), html, callback);
|
|
||||||
// }
|
|
||||||
// ],
|
|
||||||
// (err, results) => {
|
|
||||||
// if (!err) {
|
|
||||||
// console.log('done creating files >>>');
|
|
||||||
// } else {
|
|
||||||
// console.error(err);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
@@ -1,13 +1,56 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import { walk } from 'walk';
|
||||||
|
|
||||||
export const relativePath = (...relativePath) => (
|
export const relativePath = (...relativePath) => (
|
||||||
path.resolve(__dirname, '..', ...relativePath)
|
path.resolve(__dirname, '..', ...relativePath)
|
||||||
);
|
);
|
||||||
|
|
||||||
export const srcPath = (...pathInSrc) => (
|
export const radarPath = (...pathInSrc) => (
|
||||||
relativePath('radar', ...pathInSrc)
|
relativePath('radar', ...pathInSrc)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const staticPath = (...pathInSrc) => (
|
||||||
|
relativePath('static-pages', ...pathInSrc)
|
||||||
|
);
|
||||||
|
|
||||||
export const distPath = (...pathInDist) => (
|
export const distPath = (...pathInDist) => (
|
||||||
relativePath('dist', ...pathInDist)
|
relativePath('dist', ...pathInDist)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const getAllMarkdownFiles = (folder) => (
|
||||||
|
getAllFiles(folder, isMarkdownFile)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const getAllPugFiles = (folder) => (
|
||||||
|
getAllFiles(folder, isPugFile)
|
||||||
|
);
|
||||||
|
|
||||||
|
const getAllFiles = (folder, predicate) => (
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const walker = walk(folder, { followLinks: false });
|
||||||
|
const files = [];
|
||||||
|
|
||||||
|
walker.on("file", (root, fileStat, next) => {
|
||||||
|
if (predicate(fileStat.name)) {
|
||||||
|
files.push(path.resolve(root, fileStat.name));
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
walker.on("errors", (root, nodeStatsArray, next) => {
|
||||||
|
nodeStatsArray.forEach(function (n) {
|
||||||
|
console.error("[ERROR] " + n.name)
|
||||||
|
console.error(n.error.message || (n.error.code + ": " + n.error.path));
|
||||||
|
});
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
walker.on("end", () => {
|
||||||
|
resolve(files.sort());
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const isMarkdownFile = (name) => name.match(/\.md$/);
|
||||||
|
|
||||||
|
const isPugFile = (name) => name.match(/\.pug$/);
|
||||||
|
|||||||
@@ -1,46 +1,21 @@
|
|||||||
import { walk } from 'walk';
|
|
||||||
import fs, { readFile, outputFile } from 'fs-extra';
|
import fs, { readFile, outputFile } from 'fs-extra';
|
||||||
import path from 'path';
|
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 {
|
||||||
|
radarPath,
|
||||||
|
distPath,
|
||||||
|
getAllMarkdownFiles,
|
||||||
|
} from './file';
|
||||||
import { item as itemTemplate } from './template';
|
import { item as itemTemplate } from './template';
|
||||||
|
|
||||||
export const createRadar = async (tree) => {
|
export const createRadar = async (tree) => {
|
||||||
const fileNames = await getAllMarkdownFiles();
|
const fileNames = (await getAllMarkdownFiles(radarPath())).reverse();
|
||||||
const revisions = await createRevisionsFromFiles(fileNames);
|
const revisions = await createRevisionsFromFiles(fileNames);
|
||||||
const quadrants = createQuadrants(revisions);
|
const quadrants = createQuadrants(revisions);
|
||||||
return quadrants;
|
return quadrants;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAllMarkdownFiles = () => (
|
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
const walker = walk(srcPath(), { followLinks: false });
|
|
||||||
const files = [];
|
|
||||||
|
|
||||||
walker.on("file", (root, fileStat, next) => {
|
|
||||||
if (isMarkdownFile(fileStat.name)) {
|
|
||||||
files.push(path.resolve(root, fileStat.name));
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
walker.on("errors", (root, nodeStatsArray, next) => {
|
|
||||||
nodeStatsArray.forEach(function (n) {
|
|
||||||
console.error("[ERROR] " + n.name)
|
|
||||||
console.error(n.error.message || (n.error.code + ": " + n.error.path));
|
|
||||||
});
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
walker.on("end", () => {
|
|
||||||
resolve(files.sort().reverse());
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const isMarkdownFile = (name) => name.match(/\.md$/);
|
|
||||||
|
|
||||||
const createRevisionsFromFiles = (fileNames) => (
|
const createRevisionsFromFiles = (fileNames) => (
|
||||||
Promise.all(fileNames.map((fileName) => {
|
Promise.all(fileNames.map((fileName) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -99,7 +74,6 @@ const addRevisionToItem = (item = {
|
|||||||
...rest,
|
...rest,
|
||||||
} = revision;
|
} = revision;
|
||||||
return {
|
return {
|
||||||
quadrant,
|
|
||||||
attributes: {
|
attributes: {
|
||||||
...item.attributes,
|
...item.attributes,
|
||||||
...revision.attributes,
|
...revision.attributes,
|
||||||
@@ -114,8 +88,10 @@ export const outputRadar = (radar) => {
|
|||||||
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) => {
|
||||||
console.log(JSON.stringify(item, null, 2));
|
outputFile(distPath(quadrantName, `${itemName}.html`), itemTemplate({
|
||||||
outputFile(distPath(quadrantName, `${itemName}.html`), itemTemplate(item), (err, data) => {
|
quadrantName,
|
||||||
|
item,
|
||||||
|
}), (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
39
scripts/static.js
Normal file
39
scripts/static.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { outputFile } from 'fs-extra';
|
||||||
|
import pug from 'pug';
|
||||||
|
import frontmatter from 'front-matter';
|
||||||
|
import marked from 'marked';
|
||||||
|
import {
|
||||||
|
staticPath,
|
||||||
|
distPath,
|
||||||
|
getAllPugFiles,
|
||||||
|
} from './file';
|
||||||
|
|
||||||
|
export const createStatic = async (radar) => {
|
||||||
|
const paths = await getAllPugFiles(staticPath());
|
||||||
|
const fileNames = getPlainFileNames(paths);
|
||||||
|
return renderStaticPages(radar, fileNames);
|
||||||
|
return fileNames;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPlainFileNames = (paths) => (
|
||||||
|
paths.map((fileName) => {
|
||||||
|
const [ nameWithSuffix ] = fileName.split('/').slice(-1);
|
||||||
|
return nameWithSuffix.substr(0, nameWithSuffix.length - 4);
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const renderStaticPages = (radar, fileNames) => (
|
||||||
|
Promise.all(fileNames.map((name) => (
|
||||||
|
new Promise((resolve, reject) => (
|
||||||
|
outputFile(distPath(`${name}.html`), pug.renderFile(staticPath(`${name}.pug`), {
|
||||||
|
radar,
|
||||||
|
}), (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
))
|
||||||
|
)))
|
||||||
|
);
|
||||||
14
static-pages/index.pug
Normal file
14
static-pages/index.pug
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
extends ../templates/layout.pug
|
||||||
|
|
||||||
|
block vars
|
||||||
|
- var title='Overview'
|
||||||
|
|
||||||
|
block content
|
||||||
|
ul
|
||||||
|
each quadrant, quadrantName in radar
|
||||||
|
li
|
||||||
|
h4= quadrantName
|
||||||
|
ul
|
||||||
|
each radarItem, itemName in quadrant
|
||||||
|
li
|
||||||
|
a(href='/' + quadrantName + '/' + itemName + '.html')= radarItem.attributes.title
|
||||||
@@ -1,18 +1,21 @@
|
|||||||
extends layout.pug
|
extends layout.pug
|
||||||
|
|
||||||
|
block vars
|
||||||
|
- var title=item.attributes.title
|
||||||
|
|
||||||
block content
|
block content
|
||||||
a(href='/' + quadrant + '.html') #{quadrant}
|
a(href='/' + quadrantName + '.html') #{quadrantName}
|
||||||
h1 #{attributes.title}
|
h1 #{item.attributes.title}
|
||||||
= ' '
|
= ' '
|
||||||
small #{attributes.ring}
|
small #{item.attributes.ring}
|
||||||
|
|
||||||
hr
|
hr
|
||||||
section
|
section
|
||||||
!= revisions[0].body
|
!= item.revisions[0].body
|
||||||
hr
|
hr
|
||||||
|
|
||||||
ul
|
ul
|
||||||
each revision, index in revisions
|
each revision, index in item.revisions
|
||||||
if index > 0
|
if index > 0
|
||||||
li
|
li
|
||||||
= revision.version
|
= revision.version
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
|
block vars
|
||||||
html
|
html
|
||||||
head
|
head
|
||||||
title #{attributes.title} - AOE Tech Radar
|
title #{title} - AOE Tech Radar
|
||||||
block scripts
|
block scripts
|
||||||
script(src='/jquery.js')
|
script(src='/jquery.js')
|
||||||
|
|
||||||
|
h3 AOE Tech Radar
|
||||||
|
|
||||||
|
hr
|
||||||
|
|
||||||
body
|
body
|
||||||
block content
|
block content
|
||||||
|
|||||||
Reference in New Issue
Block a user