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
@@ -2,15 +2,10 @@ import { OpenPGPSigner } from "./utils.ts";
|
||||
import { DocuBuilder } from "./docu_builder.ts";
|
||||
import { IndexBuilder } from "./index_builder.ts";
|
||||
import type { TemplateVariables } from "../template/engine.ts";
|
||||
import { PublicationInput } from "../document/inputs.ts";
|
||||
import type { DocumentConfig, HtmlDocument } from "../document/types.ts";
|
||||
|
||||
export type GPConfig = {
|
||||
journal: {
|
||||
from_directory: string;
|
||||
template_directory?: string;
|
||||
build_mode?: "detached" | "flat";
|
||||
build_js_script?: string | false;
|
||||
};
|
||||
asset_base?: string;
|
||||
export type GPConfig = DocumentConfig & {
|
||||
pdf: {
|
||||
generate_index?: boolean;
|
||||
use_qpdf?: {
|
||||
@@ -42,14 +37,19 @@ export type PDFPipelineOptions = {
|
||||
export async function processPdfConfig(
|
||||
config: GPConfig,
|
||||
options: PDFPipelineOptions = {},
|
||||
document?: HtmlDocument,
|
||||
) {
|
||||
const builder = new DocuBuilder(config, options.variables);
|
||||
const input = document ??
|
||||
await new PublicationInput(config, options.variables).read();
|
||||
const builder = new DocuBuilder(
|
||||
{ ...config, asset_base: input.assetBase },
|
||||
options.variables,
|
||||
);
|
||||
|
||||
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.as_html_page(input);
|
||||
await builder.build_as_pdf(config.playwright);
|
||||
} finally {
|
||||
await builder.close_browser();
|
||||
@@ -64,6 +64,7 @@ export async function processPdfConfig(
|
||||
config,
|
||||
insertIndexAfterPage,
|
||||
options.keepIndexPdf ?? false,
|
||||
input,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -80,10 +81,15 @@ async function addIndexToPdf(
|
||||
config: GPConfig,
|
||||
insertIndexAfterPage = 1,
|
||||
keepIndexPdf = false,
|
||||
document?: HtmlDocument,
|
||||
) {
|
||||
console.log(`Adding index to PDF ${config.playwright.path}...`);
|
||||
|
||||
const indexBuilder = new IndexBuilder(config.playwright.path, config);
|
||||
const indexBuilder = new IndexBuilder(
|
||||
config.playwright.path,
|
||||
config,
|
||||
document,
|
||||
);
|
||||
await indexBuilder.build_index();
|
||||
console.log(
|
||||
`Index entries for ${config.playwright.path}: ${indexBuilder.indexed_map.size}`,
|
||||
@@ -121,6 +127,7 @@ async function addIndexToPdf(
|
||||
}
|
||||
await indexBuilder.add_pdf_outline({
|
||||
inserted_index_pages: insertedIndexPages,
|
||||
insert_index_after_page: insertIndexAfterPage,
|
||||
});
|
||||
|
||||
if (keepIndexPdf) {
|
||||
|
||||
Reference in new issue
Block a user