1
0
mirror of https://github.com/twirl/The-API-Book.git synced 2025-05-13 21:26:26 +02:00
The-API-Book/scripts/build-landing.mjs
2023-07-30 15:25:21 +03:00

28 lines
889 B
JavaScript

import { resolve } from 'path';
import { readdirSync, writeFileSync, statSync } from 'fs';
const examplesDir = resolve('docs', 'examples');
export const buildLanding = (structure, lang, l10n, templates) => {
const examples = readdirSync(examplesDir);
const landingHtml = templates.landing({
structure: structure,
examples: examples.reduce((examples, folder) => {
const fullName = resolve(examplesDir, folder);
if (statSync(fullName).isDirectory()) {
const name = folder.match(/^\d+\. (.+)$/)[1];
examples.push({
name,
path: `examples/${folder}`
});
}
return examples;
}, []),
l10n: l10n[lang],
lang,
templates
});
writeFileSync(resolve('docs', l10n[lang].landingFile), landingHtml);
};