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
This commit is contained in:
ErickSkrauch committed 2026-10-28 18:38:44 +01:00
1 parent b63b9aa606
commit b128b92941
7 files changed
+81

No files matched your search

+13
View File
@@ -14,6 +14,9 @@ const config: Config = {
// Set the /<baseUrl>/ pathname under which your site is served
// For GitHub pages deployment, it is often '/<projectName>/'
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: [
+1
View File
@@ -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",
View File
File renamed without changes.
+1
View File
@@ -0,0 +1 @@
docs.ely.by
+37
View File
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ely.by Documentation</title>
<link rel="alternate" hreflang="ru" href="https://docs.ely.by/ru/">
<link rel="alternate" hreflang="en" href="https://docs.ely.by/en/">
<link rel="alternate" hreflang="x-default" href="https://docs.ely.by/ru/">
<script>
(function () {
var ruLike = ['ru', 'be', 'uk', 'kk'];
var languages = navigator.languages || [navigator.language || ''];
var target = '/en/';
for (var i = 0; i < languages.length; i++) {
var lang = String(languages[i]).toLowerCase().split('-')[0];
if (ruLike.indexOf(lang) !== -1) {
target = '/ru/';
break;
}
if (lang === 'en') {
break;
}
}
window.location.replace(target + window.location.search + window.location.hash);
})();
</script>
</head>
<body>
<ul>
<li><a href="/ru/" hreflang="ru">Документация Ely.by на русском</a></li>
<li><a href="/en/" hreflang="en">Ely.by documentation in English</a></li>
</ul>
</body>
</html>
+5
View File
@@ -0,0 +1,5 @@
User-agent: *
Allow: /
Sitemap: https://docs.ely.by/ru/sitemap.xml
Sitemap: https://docs.ely.by/en/sitemap.xml
+24
View File
@@ -0,0 +1,24 @@
// 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');