文档部分基本完成,还需要完善生成目录

This commit is contained in:
:NoBody: committed 2026-04-25 16:42:37 +08:00
1 parent 578109c8de
commit 365b1db47e
109 files changed
+6222 -289

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
import { DocuBuilder } from "../pdf_builder/builder.ts";
export async function generate_pdf() {
const builder = new DocuBuilder();
try {
await builder.with_browser();
const cfg = JSON.parse(await Deno.readTextFile("config.json"));
for (const config of cfg.settings) {
console.debug(`Processing config: ${JSON.stringify(config)}`);
builder.with_files_sync(config.journal.from_directory);
builder.as_html_page();
await builder.build_as_pdf(config.playwright);
}
} finally {
await builder.close_browser();
}
}
export async function generate_md() {
const builder = new DocuBuilder();
try {
const cfg = JSON.parse(await Deno.readTextFile("config.json"));
for (const config of cfg.settings) {
console.debug(`Processing config: ${JSON.stringify(config)}`);
builder.with_files_sync(config.journal.from_directory);
builder.as_markdown();
const markdownPath = config.md?.path ?? config.markdown_output;
if (!markdownPath) {
throw new Error("Missing markdown output path in config. Use md.path.");
}
await builder.build_as_raw(markdownPath);
}
} finally {
// No browser to close in this function
}
}
+17
View File
@@ -0,0 +1,17 @@
import { generate_md, generate_pdf } from "./handlers.ts";
export function match_sub_command_to_function(sub_command: Array<string>) {
switch (sub_command[0]) {
case "generate":
switch (sub_command[1]) {
case "pdf":
return generate_pdf;
case "md":
return generate_md;
default:
throw new Error(`Unknown sub-command: ${sub_command[1]}`);
}
default:
throw new Error(`Unknown sub-command: ${sub_command[0]}`);
}
}