2016-01-19 19:44:37 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-10-02 05:49:50 +01:00
|
|
|
var glob = require('glob');
|
2016-01-19 19:44:37 +00:00
|
|
|
|
|
|
|
function parsePlatform(pagefile) {
|
|
|
|
return pagefile.split(/\//)[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
function parsePagename(pagefile) {
|
|
|
|
return pagefile.split(/\//)[2].replace(/\.md$/, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildShortPagesIndex(files) {
|
2016-10-02 05:49:50 +01:00
|
|
|
var reducer = function (index, file) {
|
2016-01-19 19:44:37 +00:00
|
|
|
var os = parsePlatform(file);
|
|
|
|
var page = parsePagename(file);
|
|
|
|
if (index[page]) {
|
|
|
|
index[page].push(os);
|
|
|
|
} else {
|
|
|
|
index[page] = [os];
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
};
|
|
|
|
|
|
|
|
return files.reduce(reducer, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildPagesIndex(shortIndex) {
|
|
|
|
return Object.keys(shortIndex)
|
|
|
|
.sort()
|
2016-10-02 05:49:50 +01:00
|
|
|
.map(function (page) {
|
2016-01-19 19:44:37 +00:00
|
|
|
return {
|
|
|
|
name: page,
|
|
|
|
platform: shortIndex[page]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveIndex(index) {
|
2016-01-24 08:54:27 +00:00
|
|
|
var indexFile = {
|
|
|
|
commands: index
|
|
|
|
};
|
|
|
|
console.log(JSON.stringify(indexFile));
|
2016-01-19 19:44:37 +00:00
|
|
|
}
|
|
|
|
|
2016-10-02 05:49:50 +01:00
|
|
|
glob('pages/**/*.md', function (er, files) {
|
2016-01-19 19:44:37 +00:00
|
|
|
var shortIndex = buildShortPagesIndex(files);
|
|
|
|
var index = buildPagesIndex(shortIndex);
|
|
|
|
saveIndex(index);
|
|
|
|
});
|