Skip to content

Commit 3316ad4

Browse files
committed
Use website scripts as the source of truth
Generate embedded examples and manual script pages from the website checkout. Drop local copies and skip examples without the checkout. prompt: Use website scripts as source of truth and update agents.md
1 parent c675ac9 commit 3316ad4

57 files changed

Lines changed: 62 additions & 2916 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎agents.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ To add a new cmd-line flag:
360360
361361
User docs live in the sumatra-website repo, in `../hack/webapps/sumatra-website/www/docs` (called `www/docs` below); it is the source of truth. `bun cmd/gen-docs.ts` copies the pages reachable from `SumatraPDF-documentation.md` into `.work/docs` for the in-app manual; without a website checkout (CI) it skips and the exe ships without the manual. `cmd/gen-settings.ts` and `cmd/gen-js-reference-md.ts` write their generated pages there. Commit doc changes in the website repo.
362362
363+
PDF example scripts live only in `sumatra-website/www/docs/scripts`. Edit and commit them in the website repo; do not keep copies in `docs/scripts` here. `cmd/gen-pdf-scripts.ts` bundles them into `.work/scripts.js` for embedding, and `cmd/gen-docs.ts` stages the scripts listed in `Tool-run-javascript-examples.md` into `.work/docs/scripts`. Without the website checkout, builds omit both the manual and example scripts.
364+
363365
When writing or restructuring a feature page in `www/docs`, follow `docs/writing-docs.md`.
364366
365367
## Version history (www/docs/Version-history.md)

‎cmd/gen-docs.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function copyScriptExamples(outDir: string, pages: string[]): void {
158158
throw new Error(`${kScriptExamplesPage}: duplicate script ${name}`);
159159
}
160160
names.add(name);
161-
copyFileNormalized(join(outDir, "scripts", name), join(docsDir, "scripts", name));
161+
copyFileNormalized(join(outDir, "scripts", name), join(scriptsDir, name));
162162
}
163163
for (const file of readdirSync(scriptsDir, { withFileTypes: true })) {
164164
if (file.isFile() && file.name.endsWith(".js") && !names.has(file.name)) {

‎cmd/gen-pdf-scripts.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
2-
import { join, resolve } from "node:path";
1+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
2+
import { join, relative, resolve } from "node:path";
3+
import { websiteDocsDir } from "./util";
34

45
const root = resolve(import.meta.dir, "..");
56
const kDefaultScript = "load-a-pdf.js";
67
const kScriptSeparator = "// ---";
78

8-
export function genPDFScripts(inputRoot = root): string {
9-
const scriptsDir = join(inputRoot, "docs/scripts");
9+
export function genPDFScripts(inputRoot = root): string | null {
10+
const scriptsDir = join(inputRoot, relative(root, websiteDocsDir), "scripts");
11+
const output = join(inputRoot, ".work/scripts.js");
12+
if (!existsSync(scriptsDir)) {
13+
rmSync(output, { force: true });
14+
console.log(`gen-pdf-scripts: skipping, '${scriptsDir}' missing (needs sumatra-website checkout)`);
15+
return null;
16+
}
1017
const names = readdirSync(scriptsDir, { withFileTypes: true })
1118
.filter((file) => file.isFile() && file.name.endsWith(".js"))
1219
.map((file) => file.name)
@@ -21,12 +28,12 @@ export function genPDFScripts(inputRoot = root): string {
2128
});
2229
if (!scripts.length) throw new Error("No PDF scripts found");
2330
const bundle = scripts.join(`\n${kScriptSeparator}\n`) + "\n";
24-
const output = join(inputRoot, ".work/scripts.js");
2531
mkdirSync(join(inputRoot, ".work"), { recursive: true });
2632
if (!existsSync(output) || readFileSync(output, "utf8") !== bundle) writeFileSync(output, bundle);
2733
return output;
2834
}
2935

3036
if (import.meta.main) {
31-
console.log(genPDFScripts());
37+
const output = genPDFScripts();
38+
if (output) console.log(output);
3239
}

‎cmd/helper/embedded.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export async function packEmbedded(
7676
const staging = join(dir, "embedded");
7777
const archive = join(dir, "embedded.lzsa");
7878
const inputs = new Map<string, string>();
79-
inputs.set("scripts.js", genPDFScripts(inputRoot));
79+
const scripts = genPDFScripts(inputRoot);
80+
if (scripts) inputs.set("scripts.js", scripts);
8081
const docs = join(inputRoot, ".work/docs");
8182
if (opts.manual) {
8283
for (const src of filesUnder(docs)) inputs.set(relative(docs, src), src);

‎cmd/pack-embedded-prebuild.cmd‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ if exist "%WORK%\docs\" (
7373
)
7474
if not exist "%STAGING%\" mkdir "%STAGING%"
7575
copy /y "%WORK%\translations.txt" "%STAGING%\translations.txt" >nul || exit /b 1
76-
copy /y "%WORK%\scripts.js" "%STAGING%\scripts.js" >nul || exit /b 1
76+
if exist "%WORK%\scripts.js" (
77+
copy /y "%WORK%\scripts.js" "%STAGING%\scripts.js" >nul || exit /b 1
78+
) else (
79+
if exist "%STAGING%\scripts.js" del /q "%STAGING%\scripts.js"
80+
)
7781
copy /y "%ROOT%\ext\marked.min.js" "%STAGING%\marked.min.js" >nul || exit /b 1
7882
copy /y "%ROOT%\ext\mermaid.min.js" "%STAGING%\mermaid.min.js" >nul || exit /b 1
7983

‎docs/scripts/add-an-annotation.js‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎docs/scripts/convert-pdf-to-images.js‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎docs/scripts/convert-pdf-to-plain-text.js‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎docs/scripts/copy-outline.js‎

Lines changed: 0 additions & 40 deletions
This file was deleted.

‎docs/scripts/create-a-pdf.js‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)