diff --git a/package.json b/package.json index 6b0e4313..5a393acf 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build:md:api": "node scripts/markdown/api/index.mjs && node scripts/markdown/api/configuration.mjs", "build:md:readmes": "node scripts/markdown/readmes.mjs", "build:md:governance": "node scripts/markdown/governance.mjs", - "build:html": "node scripts/html/index.mjs", + "build:html": "node scripts/html/index.mjs && node scripts/html/sitemap-index.mjs", "build:rss-feed": "node scripts/rss-feed/index.mjs", "build": "npm-run-all build:*", "lint": "npm-run-all \"lint:!(fix)\"", diff --git a/scripts/html/doc-kit.config.mjs b/scripts/html/doc-kit.config.mjs index 71924db4..63c0bb73 100644 --- a/scripts/html/doc-kit.config.mjs +++ b/scripts/html/doc-kit.config.mjs @@ -10,7 +10,7 @@ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..'); const VERSION = process.env.VERSION; const MAJOR_VERSION = VERSION ? `v${major(VERSION)}.x` : undefined; -const URL_PATH = VERSION ? `/docs/api/${MAJOR_VERSION}` : '/'; +const URL_PATH = VERSION ? `/docs/api/${MAJOR_VERSION}` : ''; const ORIGIN = process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` @@ -110,6 +110,10 @@ export default { }, }, }, + sitemap: { + indexURL: '{baseURL}/', + pageURL: '{baseURL}{path}.html', + }, }; if (!VERSION) { diff --git a/scripts/html/index.mjs b/scripts/html/index.mjs index 7bd0c835..ff471191 100644 --- a/scripts/html/index.mjs +++ b/scripts/html/index.mjs @@ -31,6 +31,7 @@ const runDocKit = version => '-t', 'orama-db', '-t', + 'sitemap', 'llms-txt', '--config-file', './scripts/html/doc-kit.config.mjs', diff --git a/scripts/html/sitemap-index.mjs b/scripts/html/sitemap-index.mjs new file mode 100644 index 00000000..36367b03 --- /dev/null +++ b/scripts/html/sitemap-index.mjs @@ -0,0 +1,25 @@ +import { readFile, writeFile } from 'node:fs/promises'; +import { major } from 'semver'; + +const versions = JSON.parse(await readFile('./versions.json', 'utf8')); + +const ORIGIN = process.env.VERCEL_URL + ? `https://${process.env.VERCEL_URL}` + : 'http://localhost:3000'; + +const sitemaps = [ + `${ORIGIN}/sitemap.xml`, + ...versions.map( + version => `${ORIGIN}/docs/api/v${major(version)}.x/sitemap.xml` + ), +]; + +const sitemapIndex = ` + +${sitemaps + .map(url => ` \n ${url}\n `) + .join('\n')} + +`; + +await writeFile('./out/sitemap-index.xml', sitemapIndex, 'utf8');