mirror of
https://github.com/tldr-pages/tldr.git
synced 2024-11-10 11:29:59 +03:00
27123e215a
- Use single quotes consistently - Insert space before parenthesis in anonymous function declarations
51 lines
997 B
JavaScript
51 lines
997 B
JavaScript
'use strict';
|
|
|
|
var glob = require('glob');
|
|
|
|
function parsePlatform(pagefile) {
|
|
return pagefile.split(/\//)[1];
|
|
}
|
|
|
|
function parsePagename(pagefile) {
|
|
return pagefile.split(/\//)[2].replace(/\.md$/, '');
|
|
}
|
|
|
|
function buildShortPagesIndex(files) {
|
|
var reducer = function (index, file) {
|
|
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()
|
|
.map(function (page) {
|
|
return {
|
|
name: page,
|
|
platform: shortIndex[page]
|
|
};
|
|
});
|
|
}
|
|
|
|
function saveIndex(index) {
|
|
var indexFile = {
|
|
commands: index
|
|
};
|
|
console.log(JSON.stringify(indexFile));
|
|
}
|
|
|
|
glob('pages/**/*.md', function (er, files) {
|
|
var shortIndex = buildShortPagesIndex(files);
|
|
var index = buildPagesIndex(shortIndex);
|
|
saveIndex(index);
|
|
});
|