Files
docs/scripts/postbuild.mjs
T
ErickSkrauch b128b92941 Preserve URLs of the old Sphinx-based documentation
Build each locale into its own prefix (/ru/, /en/) with trailingSlash: false,
so pages are generated as build/<locale>/<page>.html exactly like the old
documentation and the existing URLs (e.g. /ru/api.html) keep working on
GitHub Pages without any redirects.

The site root is assembled by the postbuild script:
- index.html redirects to /ru/ or /en/ based on the browser language
- 404.html is copied from the default locale (GitHub Pages only uses the root one)
- CNAME, .nojekyll and robots.txt pointing to per-locale sitemaps
2026-10-28 18:38:44 +01:00

25 lines
1.1 KiB
JavaScript

// Assembles the site root after "docusaurus build".
// Every locale is built into its own build/<locale>/ directory (see i18n.localeConfigs in
// docusaurus.config.ts), so files that must live in the site root are placed here.
import {cpSync, copyFileSync, existsSync} from 'node:fs';
import {dirname, join} from 'node:path';
import {fileURLToPath} from 'node:url';
const projectDir = join(dirname(fileURLToPath(import.meta.url)), '..');
const buildDir = join(projectDir, 'build');
const defaultLocale = 'ru';
if (!existsSync(join(buildDir, defaultLocale))) {
// Partial build (e.g. "docusaurus build --locale en"): there is nothing to assemble
console.warn(`[postbuild] build/${defaultLocale} not found, skipping the site root assembly`);
process.exit(0);
}
// CNAME, .nojekyll, robots.txt and the language-detecting index.html
cpSync(join(projectDir, 'root'), buildDir, {recursive: true});
// GitHub Pages only serves the 404.html from the site root
copyFileSync(join(buildDir, defaultLocale, '404.html'), join(buildDir, '404.html'));
console.log('[postbuild] Site root assembled');