Files
ARUNAVO RAY 3d763cf75e docs: move the user docs to the website and bring the rest up to date (#529)
* docs: move the user docs to the website and fix what the code contradicts

The README is down to the pitch, a quick start and links. The docs/
pages that repeated the website (environment variables, sources, push
targets, notifications, force-push protection, SSO, Nix) and the root
NIX.md and certs/README.md are now short stubs pointing at the site,
after moving their remaining true facts there.

Checking those facts against the code also turned up site pages that
were wrong:
- SAML sign-in does not work from the UI, and the ACS URL was wrong
- the OIDC provider discovery URL lives under /api/auth
- force-push protection does not stop Gitea's own mirror schedule
- a read-only /app/certs mount stops the container at startup
- gitea-mirror-db on Nix does not touch the real database
- several environment variable rows described the wrong behavior
- DESTINATION_PROVIDER is not checked against the destination lock

The link checker now covers every markdown file in the repository, and
four screenshots nothing links to are gone.

* ci: check the environment variable reference against the code

scripts/check-env-docs.ts fails when the app reads a variable the
reference page does not list, or the page lists one nothing reads. The
variables that are read but deliberately undocumented (internal ones,
and those stored but never used) are listed in the script with a
reason, and the check also fails when one of those stops being read.

* docs: bring the maintainer docs up to date

CLAUDE.md, CONTRIBUTING.md, the development workflow, the SSO testing
guide, the Nix packaging notes and the site's own README and CLAUDE.md
described scripts, files, ports and behavior that no longer exist. They
now match the code: Astro 7, multiple sources and destinations, the real
CI steps, the test isolation rules, the TypeScript 7 type check
workaround, and the AGPL license.

GRACEFUL_SHUTDOWN.md and RECOVERY_IMPROVEMENTS.md are merged into
SHUTDOWN_AND_RECOVERY.md. It also records two gaps: a job stopped by a
clean shutdown is not resumed by recovery, and Docker's 10 second stop
timeout is shorter than the 30 second shutdown.

AGENTS.md now points at CLAUDE.md.

* docs: changelog for the docs consolidation

* ci: count the env config loader's envFlag reads in the env check
2026-11-17 16:56:57 +05:30

141 lines
5.3 KiB
TypeScript

#!/usr/bin/env bun
/**
* Checks the links in the docs website and the README.
*
* The site does not rewrite relative `./page.md` links, and Cloudflare Pages
* answered every unknown path with the homepage, so 38 links in the docs sent
* readers to the homepage for months without anyone noticing. This fails on:
* - a relative link to a .md file in a site page
* - a site link (/docs/..., /use-cases/..., /comparison/...) to a page that
* does not exist, or to a heading anchor the page does not have
* - a relative link in a repository markdown file (README.md, docs/ and the
* rest) to a file that does not exist
*
* Run with `bun scripts/check-docs-links.ts`; exits 1 when something is broken.
*/
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
import path from "node:path";
const root = path.resolve(import.meta.dir, "..");
const pagesDir = path.join(root, "www/src/pages");
const SITE = "https://gitea-mirror.raylabs.io";
const SITE_SECTIONS = /^\/(docs|use-cases|comparison)(\/|$)/;
function walk(dir: string): string[] {
return readdirSync(dir).flatMap((name) => {
const full = path.join(dir, name);
return statSync(full).isDirectory() ? walk(full) : [full];
});
}
/** The page file a site path is served from, if any. */
function pageFor(sitePath: string): string | undefined {
const clean = sitePath.replace(/\/$/, "");
for (const candidate of [
`${clean}.mdx`,
`${clean}.md`,
`${clean}.astro`,
`${clean}/index.mdx`,
`${clean}/index.md`,
`${clean}/index.astro`,
]) {
const file = path.join(pagesDir, candidate);
if (existsSync(file)) return file;
}
return undefined;
}
/** Heading anchors the way Astro's markdown builds them (github-slugger). */
function anchorsOf(file: string): Set<string> | undefined {
if (!/\.mdx?$/.test(file)) return undefined; // .astro pages: not checked
const seen = new Map<string, number>();
const anchors = new Set<string>();
let inFence = false;
for (const line of readFileSync(file, "utf8").split("\n")) {
if (line.startsWith("```")) inFence = !inFence;
const heading = !inFence && /^#{1,6}\s+(.+?)\s*#*\s*$/.exec(line);
if (!heading) continue;
const text = heading[1]
.replace(/`([^`]*)`/g, "$1")
.replace(/\[([^\]]*)\]\([^)]*\)/g, "$1")
.replace(/[*_]/g, "");
let slug = text
.toLowerCase()
.replace(/[^\p{L}\p{M}\p{N}\p{Pc}\- ]/gu, "")
.replace(/ /g, "-");
const count = seen.get(slug) ?? 0;
seen.set(slug, count + 1);
if (count > 0) slug = `${slug}-${count}`;
anchors.add(slug);
}
return anchors;
}
const problems: string[] = [];
function checkSiteLink(source: string, target: string) {
const [sitePath, anchor] = target.split("#");
const page = pageFor(sitePath);
if (!page) {
problems.push(`${source}: ${target} has no page`);
return;
}
if (anchor) {
const anchors = anchorsOf(page);
if (anchors && !anchors.has(anchor)) problems.push(`${source}: ${target} has no #${anchor} heading`);
}
}
const linkPattern = /\]\(([^)\s]+)\)|href=["'{`]+([^"'}`\s]+)["'}`]/g;
for (const file of walk(path.join(root, "www/src")).filter((f) => /\.(mdx?|astro|tsx?)$/.test(f))) {
const source = path.relative(root, file);
const text = readFileSync(file, "utf8");
for (const match of text.matchAll(linkPattern)) {
const target = match[1] ?? match[2];
if (target.includes("${")) continue; // built at runtime, checked below for use cases
if (/^\.{1,2}\/.*\.md(#|$)/.test(target)) {
problems.push(`${source}: ${target} is a relative .md link; use the site path, such as /docs/sources/`);
} else if (SITE_SECTIONS.test(target)) {
checkSiteLink(source, target);
}
}
// Nav entries in docs-nav.ts and similar data files.
for (const match of text.matchAll(/href:\s*['"]([^'"]+)['"]/g)) {
if (SITE_SECTIONS.test(match[1])) checkSiteLink(source, match[1]);
}
}
// Use case cards build their links from the slugs in use-cases.ts.
const useCases = readFileSync(path.join(root, "www/src/lib/use-cases.ts"), "utf8");
for (const match of useCases.matchAll(/slug:\s*['"]([^'"]+)['"]/g)) {
checkSiteLink("www/src/lib/use-cases.ts", `/use-cases/${match[1]}/`);
}
// Every other markdown file in the repository: site links must exist, and
// relative links must point at a file that does, from the file's own folder.
const markdownFiles = Bun.spawnSync(["git", "ls-files", "*.md"], { cwd: root })
.stdout.toString()
.split("\n")
.filter((file) => file && !file.startsWith("www/src/"));
for (const source of markdownFiles) {
const text = readFileSync(path.join(root, source), "utf8");
for (const match of text.matchAll(/\]\(<?([^)\s>]+)>?(?:\s+"[^"]*")?\)/g)) {
const target = match[1];
const url = URL.canParse(target) ? new URL(target) : null;
if (url?.origin === SITE) {
const sitePath = url.pathname + url.hash;
if (SITE_SECTIONS.test(sitePath)) checkSiteLink(source, sitePath);
} else if (!/^[a-z][a-z0-9+.-]*:|^#|^\//i.test(target)) {
const file = path.join(root, path.dirname(source), decodeURI(target.split("#")[0]));
if (!existsSync(file)) problems.push(`${source}: ${target} does not exist`);
}
}
}
if (problems.length) {
console.error(`${problems.length} broken link(s):\n${problems.map((p) => ` ${p}`).join("\n")}`);
process.exit(1);
}
console.log("Docs links OK");