文档部分基本完成,还需要完善生成目录
This commit is contained in:
1 parent
578109c8de
commit
115fd47bae
108 files changed
+6202
-289
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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]}`);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user