forked from rook/rook.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess.js
40 lines (34 loc) · 1.19 KB
/
preprocess.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"use strict";
// on publish this script will check all docs projects and versions and prepare static data
// so it does not have to be generated using complicated logic from liquid templates / jekyll
const fs = require("fs");
const jsonfile = require("jsonfile");
const path = require("path");
const semver = require("semver");
function getDirectories(srcpath) {
return fs
.readdirSync(srcpath)
.filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory());
}
const ROOT_DIR = `${__dirname}`;
// collect all docs projects with versions (forcing master to the end)
const projects = [
...getDirectories(`${ROOT_DIR}/docs`).map(project => {
// get all versions except master
const versions = getDirectories(`${ROOT_DIR}/docs/${project}`)
.filter(v => v !== "master")
.sort((a, b) =>
semver.rcompare(semver.coerce(a).version, semver.coerce(b).version)
);
return {
project,
path: `/docs/${project}`,
versions: [...versions, "master"].map(version => ({
version,
path: `/docs/${project}/${version}`
}))
};
})
];
// write json for jekyll (and browser)
jsonfile.writeFileSync(`${ROOT_DIR}/_data/projects.json`, projects);