import { DocuBuilder, IndexBuilder, OpenPGPSigner, } from "../pdf_builder/builder.ts"; export async function generate_pdf() { const cfg = JSON.parse(await Deno.readTextFile("config.json")); for (const config of cfg.settings) { const builder = new DocuBuilder(config); try { await builder.with_browser(); console.debug(`Processing config: ${JSON.stringify(config)}`); builder.with_files_sync(config.journal.from_directory); await builder.as_html_page(); await builder.build_as_pdf(config.playwright); } finally { await builder.close_browser(); } } } export async function generate_md() { const cfg = JSON.parse(await Deno.readTextFile("config.json")); try { for (const config of cfg.settings) { const builder = new DocuBuilder(config); console.debug(`Processing config: ${JSON.stringify(config)}`); builder.with_files_sync(config.journal.from_directory); await 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 } } export async function generate_txt() { const cfg = JSON.parse(await Deno.readTextFile("config.json")); try { for (const config of cfg.settings) { const builder = new DocuBuilder(config); console.debug(`Processing config: ${JSON.stringify(config)}`); builder.with_files_sync(config.journal.from_directory); await builder.as_txt(); const markdownPath = config.md?.path ?? config.markdown_output; if (!markdownPath) { throw new Error("Missing txt output path in config. Use md.path."); } const txtPath = markdownPath.replace("md", "txt"); await builder.build_as_raw(txtPath); } } finally { // No browser to close in this function } } export async function add_index_to_pdf(insert_index_after_page: number = 1) { const config = JSON.parse(await Deno.readTextFile("config.json")); for (const cfg of config.settings) { console.log(`Adding index to PDF ${cfg.playwright.path}...`); const indexBuilder = new IndexBuilder( cfg.playwright.path, cfg, ); await indexBuilder.build_index(); const _html = indexBuilder.as_html_page(); //console.log(html); await indexBuilder.html2pdf({ "path": "./tmps/index.pdf", "format": "A4", "headerTemplate": '