38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
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
|
|
}
|
|
}
|