Files
Abdulmuizz Hamzat 0dc32b5210 refactor: selfhosting docs (#798)f
* Remove the run-docker-full-stack.sh script to streamline the deployment process and eliminate unnecessary complexity.

* fix: update documentation to clarify script behavior for building and pulling images

* update docs

* fix: update script URL to use classroomio.com for downloads

* fix: humanize selfhosting docs and minor amendment

* fix: attend to comment

* fix: humanize docs

* update docs

* fix: adjusted the Restarting ClassroomIO... function

* fix: update commands and documentation for environment variable handling and upgrades

* chore: added space for rebuild
2026-08-11 13:33:20 +01:00

60 lines
2.4 KiB
JavaScript

/**
* Packages `blume build` output for the assets-only Cloudflare Worker.
*
* Two things have to be reconciled:
*
* 1. `deployment.base: '/docs'` makes Blume emit URLs like `/docs/foo`, but it
* does NOT nest the output — pages land in `dist/foo/index.html`. The worker
* is asked for `/docs/foo` (the website proxies the full path through), so
* the build is moved under `build/docs/` to line up with the served paths.
*
* 2. Astro's own `redirects` are unusable under a base: it prefixes a
* redirect's source but not its target, emitting `url=/guides` rather than
* `/docs/guides`. So the redirects are written here as a Cloudflare
* `_redirects` file, which must sit at the root of the assets directory.
*/
import { readdirSync } from 'node:fs';
import { cp, mkdir, rm, writeFile } from 'node:fs/promises';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const dist = resolve(root, 'dist');
const out = resolve(root, 'build');
const content = resolve(root, 'content/docs');
const slugs = (dir) =>
readdirSync(resolve(content, dir), { withFileTypes: true })
.filter((e) => e.isFile() && e.name.endsWith('.mdx') && e.name !== 'index.mdx')
.map((e) => e.name.replace(/\.mdx$/, ''));
// Guides moved from `/docs/<slug>` to `/docs/guides/<slug>` (Blume scopes a tab's
// sidebar by route prefix). The old URLs are public, so forward them.
const rootSlugs = new Set(slugs('.'));
const GUIDE_REDIRECTS = slugs('guides')
// A slug that is also a root page would shadow it — `_redirects` beats assets.
.filter((slug) => !rootSlugs.has(slug))
.map((slug) => `/docs/${slug} /docs/guides/${slug} 301`)
.join('\n');
const REDIRECTS = `# Generated by scripts/package-assets.mjs — do not edit.
/docs/ /docs 301
/docs/home /docs 301
/docs/how-to-guides/* /docs/:splat 301
/docs/api/reference /docs/api 301
/docs/contributor-guides /docs/guides/contributing 301
/docs/contributor-guides/* /docs/guides/contributing/:splat 301
/docs/self-hosted/configuration/sso /docs/self-hosted/enterprise 301
${GUIDE_REDIRECTS}
`;
await rm(out, { recursive: true, force: true });
await mkdir(out, { recursive: true });
await cp(dist, resolve(out, 'docs'), { recursive: true });
await writeFile(resolve(out, '_redirects'), REDIRECTS);
console.log('[docs] Packaged dist/ -> build/docs/ with _redirects');