From b128b9294162f9db5babc30d9779dd11d2df5919 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 28 Oct 2026 18:38:44 +0100 Subject: [PATCH] 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//.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 --- docusaurus.config.ts | 13 +++++++++++++ package.json | 1 + {static => root}/.nojekyll | 0 root/CNAME | 1 + root/index.html | 37 +++++++++++++++++++++++++++++++++++++ root/robots.txt | 5 +++++ scripts/postbuild.mjs | 24 ++++++++++++++++++++++++ 7 files changed, 81 insertions(+) rename {static => root}/.nojekyll (100%) create mode 100644 root/CNAME create mode 100644 root/index.html create mode 100644 root/robots.txt create mode 100644 scripts/postbuild.mjs diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 8c6ab4e..6cb5618 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -14,6 +14,9 @@ const config: Config = { // Set the // pathname under which your site is served // For GitHub pages deployment, it is often '//' baseUrl: '/', + // Generate "page.html" files instead of "page/index.html" so that the URLs + // of the old Sphinx-based documentation (/ru/api.html) keep working as is + trailingSlash: false, // GitHub pages deployment config. // If you aren't using GitHub pages, you don't need these. @@ -34,6 +37,16 @@ const config: Config = { i18n: { defaultLocale: 'ru', locales: ['en', 'ru'], + // Each locale lives under its own prefix to preserve the URLs of the old documentation. + // The site root is assembled by the "postbuild" script (see scripts/postbuild.mjs) + localeConfigs: { + ru: { + baseUrl: '/ru/', + }, + en: { + baseUrl: '/en/', + }, + }, }, presets: [ diff --git a/package.json b/package.json index 475642f..5fd6b21 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "docusaurus": "docusaurus", "start": "docusaurus start", "build": "docusaurus build", + "postbuild": "node scripts/postbuild.mjs", "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", "clear": "docusaurus clear", diff --git a/static/.nojekyll b/root/.nojekyll similarity index 100% rename from static/.nojekyll rename to root/.nojekyll diff --git a/root/CNAME b/root/CNAME new file mode 100644 index 0000000..230082e --- /dev/null +++ b/root/CNAME @@ -0,0 +1 @@ +docs.ely.by \ No newline at end of file diff --git a/root/index.html b/root/index.html new file mode 100644 index 0000000..a53565d --- /dev/null +++ b/root/index.html @@ -0,0 +1,37 @@ + + + + + + Ely.by Documentation + + + + + + + + + diff --git a/root/robots.txt b/root/robots.txt new file mode 100644 index 0000000..ef8ff4a --- /dev/null +++ b/root/robots.txt @@ -0,0 +1,5 @@ +User-agent: * +Allow: / + +Sitemap: https://docs.ely.by/ru/sitemap.xml +Sitemap: https://docs.ely.by/en/sitemap.xml diff --git a/scripts/postbuild.mjs b/scripts/postbuild.mjs new file mode 100644 index 0000000..7213f32 --- /dev/null +++ b/scripts/postbuild.mjs @@ -0,0 +1,24 @@ +// Assembles the site root after "docusaurus build". +// Every locale is built into its own build// 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');