Use article link markers for PDF indexing
This commit is contained in:
1 parent
09af3bd8c0
commit
33f15d9ce0
20 files changed
+1137
-293
No files matched your search
+23
-63
@@ -1,10 +1,15 @@
|
||||
//import TurndownService from "turndown";
|
||||
import { args, cfg } from "../main.ts";
|
||||
import { OpenPGPSigner } from "../pdf_builder/utils.ts";
|
||||
import { DocuBuilder } from "../pdf_builder/docu_builder.ts";
|
||||
import { PublicationInput } from "../document/inputs.ts";
|
||||
import { convertDocument } from "../document/types.ts";
|
||||
import {
|
||||
EpubOutput,
|
||||
type TextFormat,
|
||||
TextOutput,
|
||||
} from "../document/outputs.ts";
|
||||
import { createTemplateVariables } from "../template/engine.ts";
|
||||
import { prepareLocalCache } from "../assets/local_cache.ts";
|
||||
import { EpubBuilder } from "../epub_builder/epub_builder.ts";
|
||||
|
||||
function selectedConfigs() {
|
||||
return cfg.settings.filter((config: Record<string, unknown>) =>
|
||||
@@ -109,83 +114,38 @@ function runPdfWorker(
|
||||
}
|
||||
|
||||
export async function generate_md() {
|
||||
await cacheBeforeGeneration();
|
||||
try {
|
||||
for (const config of selectedConfigs()) {
|
||||
const builder = new DocuBuilder(
|
||||
config,
|
||||
await createTemplateVariables(args, config, cfg.vars),
|
||||
);
|
||||
|
||||
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
|
||||
}
|
||||
await generateText("md");
|
||||
}
|
||||
|
||||
export async function generate_html() {
|
||||
await cacheBeforeGeneration();
|
||||
for (const config of selectedConfigs()) {
|
||||
const builder = new DocuBuilder(
|
||||
config,
|
||||
await createTemplateVariables(args, config, cfg.vars),
|
||||
);
|
||||
builder.with_files_sync(config.journal.from_directory);
|
||||
const html = await builder.as_html_page();
|
||||
const markdownPath = config.md?.path ?? config.markdown_output;
|
||||
if (!markdownPath) {
|
||||
throw new Error("Missing output path in config. Use md.path.");
|
||||
}
|
||||
const htmlPath = markdownPath.replace(/\.md$/i, ".html");
|
||||
await Deno.writeTextFile(htmlPath, html);
|
||||
console.log(`Generated HTML: ${htmlPath}`);
|
||||
}
|
||||
await generateText("html");
|
||||
}
|
||||
|
||||
export async function generate_txt() {
|
||||
await generateText("txt");
|
||||
}
|
||||
|
||||
async function generateText(format: TextFormat) {
|
||||
await cacheBeforeGeneration();
|
||||
try {
|
||||
for (const config of selectedConfigs()) {
|
||||
const builder = new DocuBuilder(
|
||||
config,
|
||||
await createTemplateVariables(args, config, cfg.vars),
|
||||
);
|
||||
|
||||
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
|
||||
for (const config of selectedConfigs()) {
|
||||
const input = new PublicationInput(
|
||||
config,
|
||||
await createTemplateVariables(args, config, cfg.vars),
|
||||
);
|
||||
const result = await convertDocument(input, new TextOutput(config, format));
|
||||
console.log(`Generated ${format}: ${result.path}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function generate_epub() {
|
||||
await cacheBeforeGeneration();
|
||||
for (const config of selectedConfigs()) {
|
||||
const builder = new EpubBuilder(
|
||||
const input = new PublicationInput(
|
||||
config,
|
||||
await createTemplateVariables(args, config, cfg.vars),
|
||||
);
|
||||
builder.with_files_sync(config.journal.from_directory);
|
||||
const output = builder.outputPath();
|
||||
await builder.build(output);
|
||||
console.log(`Generated EPUB: ${output}`);
|
||||
const result = await convertDocument(input, new EpubOutput(config));
|
||||
console.log(`Generated EPUB: ${result.path}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user