fix: build docs for custom domain root
This commit is contained in:
parent
45419d99ed
commit
762e86f45d
2
.github/workflows/pages.yml
vendored
2
.github/workflows/pages.yml
vendored
@ -45,7 +45,7 @@ jobs:
|
||||
|
||||
- name: Build
|
||||
env:
|
||||
DOCS_SITE_BASE_PATH: /docs
|
||||
DOCS_SITE_CNAME: documentation.openclaw.ai
|
||||
run: npm run docs:build
|
||||
|
||||
- name: Smoke generated site
|
||||
|
||||
@ -13,6 +13,7 @@ const outDir = path.join(root, "dist", "docs-site");
|
||||
const config = JSON.parse(fs.readFileSync(path.join(docsDir, "docs.json"), "utf8"));
|
||||
const md = createMarkdownRenderer();
|
||||
const basePath = normalizeBasePath(process.env.DOCS_SITE_BASE_PATH ?? "");
|
||||
const legacyBasePath = normalizeBasePath(process.env.DOCS_SITE_LEGACY_BASE_PATH ?? "/docs");
|
||||
|
||||
fs.rmSync(outDir, { recursive: true, force: true });
|
||||
fs.mkdirSync(outDir, { recursive: true });
|
||||
@ -272,7 +273,9 @@ function writeRedirects() {
|
||||
const source = cleanPath(redirect.source);
|
||||
const dest = cleanPath(redirect.destination);
|
||||
writeRedirectFile(source, publicPath(dest));
|
||||
if (basePath) writeRedirectFile(`${basePath}${source}`, publicPath(dest));
|
||||
for (const prefix of new Set([basePath, legacyBasePath].filter(Boolean))) {
|
||||
writeRedirectFile(`${prefix}${source}`, publicPath(dest));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,7 +297,7 @@ function writeStaticAssets() {
|
||||
fs.writeFileSync(path.join(assetsDir, "docs-site.js"), siteJs(), "utf8");
|
||||
fs.writeFileSync(path.join(outDir, ".nojekyll"), "", "utf8");
|
||||
if (process.env.DOCS_SITE_CNAME) {
|
||||
fs.writeFileSync(path.join(outDir, "CNAME"), process.env.DOCS_SITE_CNAME, "utf8");
|
||||
fs.writeFileSync(path.join(outDir, "CNAME"), `${process.env.DOCS_SITE_CNAME}\n`, "utf8");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -56,9 +56,18 @@ if (!/data-language-picker/.test(index) || !/class="language-option active"[^>]*
|
||||
if (!/Português \(BR\)/.test(index)) {
|
||||
throw new Error("index: language picker labels were not rendered");
|
||||
}
|
||||
if (/src="\/assets\//.test(index) || /href="\/assets\//.test(index)) {
|
||||
if (process.env.DOCS_SITE_BASE_PATH && (/src="\/assets\//.test(index) || /href="\/assets\//.test(index))) {
|
||||
throw new Error("index: absolute asset paths were not base-path rewritten");
|
||||
}
|
||||
if (!process.env.DOCS_SITE_BASE_PATH && !/href="\/assets\/docs-site\.css"/.test(index)) {
|
||||
throw new Error("index: custom-domain build did not emit root asset paths");
|
||||
}
|
||||
if (process.env.DOCS_SITE_CNAME) {
|
||||
const cnamePath = path.join(site, "CNAME");
|
||||
if (!fs.existsSync(cnamePath) || fs.readFileSync(cnamePath, "utf8").trim() !== process.env.DOCS_SITE_CNAME) {
|
||||
throw new Error("CNAME: custom domain file missing or wrong");
|
||||
}
|
||||
}
|
||||
const siteJs = fs.readFileSync(path.join(site, "assets/docs-site.js"), "utf8");
|
||||
if (!/function syncSidebar/.test(siteJs) || !/async function navigateTo/.test(siteJs)) {
|
||||
throw new Error("assets: docs PJAX navigation is missing");
|
||||
@ -78,7 +87,7 @@ const legacyDigitalOcean = path.join(site, "docs/platforms/digitalocean/index.ht
|
||||
if (!fs.existsSync(legacyDigitalOcean)) {
|
||||
throw new Error("legacy DigitalOcean redirect: missing /docs/platforms/digitalocean compatibility file");
|
||||
}
|
||||
if (!/url=\/docs\/install\/digitalocean/.test(fs.readFileSync(legacyDigitalOcean, "utf8"))) {
|
||||
if (!/url=\/(?:docs\/)?install\/digitalocean/.test(fs.readFileSync(legacyDigitalOcean, "utf8"))) {
|
||||
throw new Error("legacy DigitalOcean redirect: wrong destination");
|
||||
}
|
||||
const showcase = fs.readFileSync(path.join(site, "start/showcase/index.html"), "utf8");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user