@projektemacher/vivliostyle-batch-cli 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -34
- package/dist/index.d.ts +7 -1
- package/dist/vivliostyle-batch-cli.js +128 -21
- package/package.json +1 -1
- package/src/metadata.ts +103 -19
- package/src/render/pdf-postprocess.ts +6 -0
- package/src/render/pdf.ts +4 -0
- package/src/render/xmp.ts +12 -0
- package/src/vivliostyle-cli.ts +19 -3
package/README.md
CHANGED
|
@@ -10,9 +10,9 @@ It runs the [Vivliostyle viewer](https://www.npmjs.com/package/@vivliostyle/view
|
|
|
10
10
|
- Preview documents in the browser
|
|
11
11
|
- Render with the real browser engine, so canvas charts, WebGL scenes and cross-origin iframes end up in the PDF
|
|
12
12
|
- Stay sharp past 96dpi: `--pixel-ratio` redraws JS-painted content at higher backing resolution
|
|
13
|
-
- Stamp PDF metadata — title, author, subject, keywords, language — into the information dictionary and a matching XMP packet
|
|
13
|
+
- Stamp PDF metadata — title, author, subject, keywords, DOI/URL, language — into the information dictionary and a matching XMP packet
|
|
14
14
|
- Label the output as PDF/A or PDF/X with `--pdfa` / `--pdfx`, embedding an ICC output intent (`--icc-profile`, bundled sRGB default)
|
|
15
|
-
- Metadata comes from the flags, the publication manifest or the document itself (`<title>`, `<meta>` tags)
|
|
15
|
+
- Metadata comes from the flags, the publication manifest or the document itself (`<title>`, `<meta>` tags, `<link rel="canonical">`)
|
|
16
16
|
- Per-push showcase page (GitHub Pages) with the render fixtures next to their PDFs
|
|
17
17
|
- Automatic detection and mapping of static assets from HTML (`<link>`, `<script>`, `<img>`, etc.)
|
|
18
18
|
- Support for custom static asset mappings via `--static`
|
|
@@ -67,41 +67,43 @@ vivliostyle-cli -i index.html -o output.pdf -- --size A4 --viewer-param pixelRat
|
|
|
67
67
|
|
|
68
68
|
## Options
|
|
69
69
|
|
|
70
|
-
| Option | Description
|
|
71
|
-
| ----------------------------------- |
|
|
72
|
-
| `-i, --input <input>` | Input HTML or publication manifest file (required)
|
|
73
|
-
| `-o, --output <file>` | Output file path (default: `output.pdf`)
|
|
74
|
-
| `--title <title>` | Document title (overrides source)
|
|
75
|
-
| `--author <author>` | Document author
|
|
76
|
-
| `--subject <subject>` | Document subject (e.g. the page's description meta tag content)
|
|
77
|
-
| `--keywords <keywords>` | Document keywords, comma separated
|
|
78
|
-
| `--
|
|
79
|
-
| `--
|
|
80
|
-
| `--
|
|
81
|
-
| `--
|
|
82
|
-
| `--
|
|
83
|
-
| `--
|
|
84
|
-
| `--
|
|
85
|
-
| `--
|
|
86
|
-
| `--
|
|
87
|
-
| `--
|
|
88
|
-
| `--
|
|
89
|
-
| `--
|
|
90
|
-
| `--
|
|
91
|
-
| `--
|
|
92
|
-
| `--
|
|
93
|
-
| `--
|
|
94
|
-
| `--
|
|
95
|
-
| `--
|
|
96
|
-
| `--
|
|
97
|
-
| `--
|
|
98
|
-
| `--
|
|
99
|
-
| `--
|
|
100
|
-
|
|
|
70
|
+
| Option | Description |
|
|
71
|
+
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
72
|
+
| `-i, --input <input>` | Input HTML or publication manifest file (required) |
|
|
73
|
+
| `-o, --output <file>` | Output file path (default: `output.pdf`) |
|
|
74
|
+
| `--title <title>` | Document title (overrides source) |
|
|
75
|
+
| `--author <author>` | Document author |
|
|
76
|
+
| `--subject <subject>` | Document subject (e.g. the page's description meta tag content) |
|
|
77
|
+
| `--keywords <keywords>` | Document keywords, comma separated |
|
|
78
|
+
| `--doi <doi>` | Document DOI (bare `10.x/…`, `doi:` URI or doi.org URL); wins over `--url` and is written as the XMP `dc:identifier` (`doi:` prefix) |
|
|
79
|
+
| `--url <url>` | Document URL; XMP `dc:identifier` when no DOI is set, so reference managers can pick up the source |
|
|
80
|
+
| `--language <lang>` | Document language tag (e.g. `en`, `de`, `ja`); taken from the document or manifest when omitted, falling back to `de` |
|
|
81
|
+
| `--pdfa <level>` | Label the output as PDF/A: `1a`, `1b`, `2a`, `2b`, `2u`, `3a`, `3b`, `3u`, `4`. Embeds the sRGB output intent unless overridden |
|
|
82
|
+
| `--pdfx <version>` | Label the output as PDF/X: `X-4` or `X-1a:2003` (requires `--icc-profile`) |
|
|
83
|
+
| `--icc-profile <path>` | ICC profile embedded as the PDF output intent (required for `--pdfx`) |
|
|
84
|
+
| `--no-validate` | Skip the built-in compliance checks run for `--pdfa`/`--pdfx` output |
|
|
85
|
+
| `--verapdf` | Additionally run the verapdf binary (must be on the PATH) against the output and fail the build on full ISO rule-set violations |
|
|
86
|
+
| `--static <mapping>` | Map virtual path to local path: `/virtual/path:/local/path` (repeatable) |
|
|
87
|
+
| `--no-scripts` | Do not map `<script src>` tags as static assets |
|
|
88
|
+
| `--asset-base <urlBase=localBase>` | Map URLs starting with `urlBase` to files under `localBase` (repeatable) |
|
|
89
|
+
| `--ignore-asset <path>` | Skip specific virtual paths when deriving static mappings (repeatable) |
|
|
90
|
+
| `--allow-remote` | Keep subresource references that would be fetched from the network (default: drop) |
|
|
91
|
+
| `--executable-browser <path>` | Chrome/Chromium binary to render with (default: search puppeteer cache, then system) |
|
|
92
|
+
| `--dump-html <dir>` | Write the rewritten input HTML into `<dir>` and keep it (debugging aid) |
|
|
93
|
+
| `--fetch-missing` | Load references without a local file from the web (implies `--allow-remote`; drops gone remotes after a HEAD probe) |
|
|
94
|
+
| `--wait-for-content [ms]` --------- | Delay pagination until the page finished its own async work; pages with `<script>` wait automatically (10s default, `0` disables) |
|
|
95
|
+
| `--quiet-ms <ms>` ----------------- | Quiet period before the layout gate opens (default 400) --------------------------- |
|
|
96
|
+
| `--pixel-ratio <n>` --------------- | Render at `n` times the output resolution; redraws `__vivResize` pages at `n`× backing pixels |
|
|
97
|
+
| `--timeout <ms>` ------------------ | Give up on a page after `<ms>` (default: 300000) --------------------------------- |
|
|
98
|
+
| `--format <format>` | Output format: `pdf` (default: `pdf`) |
|
|
99
|
+
| `--log-level <level>` | Log level: `silent`, `info`, `verbose`, or `debug` (default: `info`) |
|
|
100
|
+
| `--mode <mode>` | Execution mode: `build` or `preview` (default: `build`) |
|
|
101
|
+
| `--preview` | Shorthand for `--mode preview` — open result in browser |
|
|
102
|
+
| `-d, --debug` | Enable debug mode (sets log level to `debug`) |
|
|
101
103
|
|
|
102
104
|
## Notes
|
|
103
105
|
|
|
104
|
-
- **PDF metadata and standards labeling**: every build stamps a producer/creator identity (`vivliostyle-batch-cli`) and a document language. Title, author, subject, keywords and language resolve with this precedence: CLI flags → publication manifest (`.json` input) → the document itself (`<title>`, `<meta name="author">`/`dc.creator`, `<meta name="description">`, `<meta name="keywords">`, `html[lang]`) → language fallback `de`. The values land in both the PDF information dictionary and an XMP metadata stream kept consistent with it, plus the catalog `/Lang` entry. `--pdfa <level>` and `--pdfx <version>` additionally write the standards identification (XMP `pdfaid`/`pdfxid` properties, an OutputIntent with an embedded ICC profile and a file identifier). This is a **label, not a conversion**: the rendered content is neither converted nor checked, so conformance of the content is the author's responsibility — verify with veraPDF when it matters. Chrome's output carries transparency, so `--pdfa 2b` (or newer) is the realistic level; PDF/A-1b will usually fail validation.
|
|
106
|
+
- **PDF metadata and standards labeling**: every build stamps a producer/creator identity (`vivliostyle-batch-cli`) and a document language. Title, author, subject, keywords, DOI/URL and language resolve with this precedence: CLI flags → publication manifest (`.json` input) → the document itself (`<title>`, `<meta name="author">`/`dc.creator`, `<meta name="description">`, `<meta name="keywords">`, `citation_doi`/`dc.doi`/`dc.identifier`, `<link rel="canonical">`/`og:url`, `html[lang]`) → language fallback `de`. The values land in both the PDF information dictionary and an XMP metadata stream kept consistent with it, plus the catalog `/Lang` entry. A DOI (flag, manifest, or meta — bare, `doi:` or doi.org URL forms all normalize) is written as XMP `dc:identifier` with a `doi:` prefix; when no DOI is known, the document URL is written there instead. Reference managers (Zotero, JabRef) pick the identifier up on PDF import. `--pdfa <level>` and `--pdfx <version>` additionally write the standards identification (XMP `pdfaid`/`pdfxid` properties, an OutputIntent with an embedded ICC profile and a file identifier). This is a **label, not a conversion**: the rendered content is neither converted nor checked, so conformance of the content is the author's responsibility — verify with veraPDF when it matters. Chrome's output carries transparency, so `--pdfa 2b` (or newer) is the realistic level; PDF/A-1b will usually fail validation.
|
|
105
107
|
|
|
106
108
|
Validation happens in two layers: every labeled build runs the built-in checks (a practical subset covering the PDF version of the labeled part, the XMP identification, the OutputIntent, the file identifier, embedded fonts and the absence of JavaScript; `--no-validate` skips them), and `--verapdf` additionally runs the [veraPDF](https://verapdf.org/) binary against the output for the full ISO rule set. `--verapdf` requires a veraPDF installation on the PATH (it needs a Java runtime) and makes the build fail if either the binary is missing or the output violates the labeled standard. For CI, the repository ships a reusable setup action (`.github/actions/setup-verapdf`) that installs veraPDF unattended.
|
|
107
109
|
|
package/dist/index.d.ts
CHANGED
|
@@ -63,6 +63,10 @@ type DocumentMetadata = {
|
|
|
63
63
|
author?: string;
|
|
64
64
|
subject?: string;
|
|
65
65
|
keywords?: string;
|
|
66
|
+
/** Normalized bare DOI (10.…/…); reference managers read it as dc:identifier. */
|
|
67
|
+
doi?: string;
|
|
68
|
+
/** Source URL of the document, used as dc:identifier when no DOI is known. */
|
|
69
|
+
url?: string;
|
|
66
70
|
language?: string;
|
|
67
71
|
/** ISO 8601 creation date (information dictionary and XMP CreateDate). */
|
|
68
72
|
created?: string;
|
|
@@ -77,6 +81,8 @@ type CliOptions = {
|
|
|
77
81
|
author?: string;
|
|
78
82
|
subject?: string;
|
|
79
83
|
keywords?: string;
|
|
84
|
+
doi?: string;
|
|
85
|
+
url?: string;
|
|
80
86
|
language?: string;
|
|
81
87
|
created?: string;
|
|
82
88
|
modified?: string;
|
|
@@ -367,7 +373,7 @@ declare function resolveIccProfile(options: Pick<CliOptions, "iccProfile">, labe
|
|
|
367
373
|
* input (HTML meta tags or a publication manifest); the language falls back
|
|
368
374
|
* to "de" when no source provides one.
|
|
369
375
|
*/
|
|
370
|
-
declare function resolvePdfMetadata(options: Pick<CliOptions, "title" | "author" | "subject" | "keywords" | "language" | "created" | "modified">, inputAbs: string, htmlMode: boolean): DocumentMetadata & {
|
|
376
|
+
declare function resolvePdfMetadata(options: Pick<CliOptions, "title" | "author" | "subject" | "keywords" | "doi" | "url" | "language" | "created" | "modified">, inputAbs: string, htmlMode: boolean): DocumentMetadata & {
|
|
371
377
|
language: string;
|
|
372
378
|
};
|
|
373
379
|
declare function execute(options: CliOptions, extraArgs?: string[]): Promise<void>;
|
|
@@ -415,6 +415,15 @@ function buildXmpPacket(fields, label) {
|
|
|
415
415
|
if (fields.keywords !== undefined) {
|
|
416
416
|
properties.push(`<pdf:Keywords>${xmlEscape(fields.keywords)}</pdf:Keywords>`);
|
|
417
417
|
}
|
|
418
|
+
// dc:identifier carries the DOI when one is known — Zotero and friends pick
|
|
419
|
+
// it up on PDF import — otherwise the source URL. The info dictionary has
|
|
420
|
+
// no entry for either, so this is the only place they appear.
|
|
421
|
+
if (fields.doi !== undefined) {
|
|
422
|
+
properties.push(`<dc:identifier>doi:${xmlEscape(fields.doi)}</dc:identifier>`);
|
|
423
|
+
}
|
|
424
|
+
else if (fields.url !== undefined) {
|
|
425
|
+
properties.push(`<dc:identifier>${xmlEscape(fields.url)}</dc:identifier>`);
|
|
426
|
+
}
|
|
418
427
|
if (fields.producer !== undefined) {
|
|
419
428
|
properties.push(`<pdf:Producer>${xmlEscape(fields.producer)}</pdf:Producer>`);
|
|
420
429
|
}
|
|
@@ -665,6 +674,8 @@ async function postProcessPdf(pdf, options) {
|
|
|
665
674
|
author: metadata.author,
|
|
666
675
|
subject: metadata.subject,
|
|
667
676
|
keywords: metadata.keywords,
|
|
677
|
+
doi: metadata.doi,
|
|
678
|
+
url: metadata.url,
|
|
668
679
|
producer: metadata.producer,
|
|
669
680
|
creatorTool: metadata.creator,
|
|
670
681
|
createDate: createDateXmp,
|
|
@@ -1017,6 +1028,8 @@ function pdfMetadata(request) {
|
|
|
1017
1028
|
...(request.author === undefined ? {} : { author: request.author }),
|
|
1018
1029
|
...(request.subject === undefined ? {} : { subject: request.subject }),
|
|
1019
1030
|
...(request.keywords === undefined ? {} : { keywords: request.keywords }),
|
|
1031
|
+
...(request.doi === undefined ? {} : { doi: request.doi }),
|
|
1032
|
+
...(request.url === undefined ? {} : { url: request.url }),
|
|
1020
1033
|
...(request.language === undefined ? {} : { language: request.language }),
|
|
1021
1034
|
...(request.created === undefined ? {} : { created: request.created }),
|
|
1022
1035
|
...(request.modified === undefined ? {} : { modified: request.modified }),
|
|
@@ -1457,39 +1470,97 @@ function fileURLOfSelf() {
|
|
|
1457
1470
|
// src/metadata.ts
|
|
1458
1471
|
/** Language tag assumed when no source provides one (project contract). */
|
|
1459
1472
|
const DEFAULT_LANGUAGE = "de";
|
|
1473
|
+
// Bare DOI form (ISO 26324): a directory indicator plus a suffix. Accepts
|
|
1474
|
+
// variants authors hand over: bare, doi: URIs and resolver URLs.
|
|
1475
|
+
const DOI_PATTERN = /^10\.\d{4,9}\/\S+$/;
|
|
1476
|
+
/**
|
|
1477
|
+
* Normalizes a DOI the user supplied: resolver URLs (`https://doi.org/…`,
|
|
1478
|
+
* `http://dx.doi.org/…`, `https://hdl.handle.net/…` keeps `10.` handles) and
|
|
1479
|
+
* `doi:` URIs reduce to the bare form, which is validated against ISO 26324.
|
|
1480
|
+
* Returns undefined when the value is not a DOI at all.
|
|
1481
|
+
*/
|
|
1482
|
+
function normalizeDoi(value) {
|
|
1483
|
+
let doi = value.trim();
|
|
1484
|
+
for (const prefix of ["https://doi.org/", "http://doi.org/", "https://dx.doi.org/", "http://dx.doi.org/", "doi:"]) {
|
|
1485
|
+
if (doi.toLowerCase().startsWith(prefix.toLowerCase())) {
|
|
1486
|
+
doi = doi.slice(prefix.length);
|
|
1487
|
+
break;
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
doi = doi.trim();
|
|
1491
|
+
if (!DOI_PATTERN.test(doi))
|
|
1492
|
+
return undefined;
|
|
1493
|
+
return doi;
|
|
1494
|
+
}
|
|
1495
|
+
/** Reads a DOI from a meta content, ignoring values that are not DOIs. */
|
|
1496
|
+
function doiMetaContent(names, document) {
|
|
1497
|
+
const content = metaContentOf(names, document);
|
|
1498
|
+
return content === undefined ? undefined : normalizeDoi(content);
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Extracts a document URL: the canonical link wins, then the usual
|
|
1502
|
+
* URL meta tags. Only absolute http(s) URLs are accepted.
|
|
1503
|
+
*/
|
|
1504
|
+
function extractDocumentUrl(document) {
|
|
1505
|
+
const candidates = [
|
|
1506
|
+
document.querySelector('link[rel="canonical" i]')?.getAttribute("href"),
|
|
1507
|
+
document.querySelector('meta[property="og:url" i]')?.getAttribute("content"),
|
|
1508
|
+
document.querySelector('meta[name="citation_url" i]')?.getAttribute("content"),
|
|
1509
|
+
document.querySelector('meta[name="dc.url" i]')?.getAttribute("content")
|
|
1510
|
+
];
|
|
1511
|
+
for (const candidate of candidates) {
|
|
1512
|
+
const url = candidate?.trim();
|
|
1513
|
+
if (url === undefined || url === "")
|
|
1514
|
+
continue;
|
|
1515
|
+
let parsed;
|
|
1516
|
+
try {
|
|
1517
|
+
parsed = new URL(url);
|
|
1518
|
+
}
|
|
1519
|
+
catch {
|
|
1520
|
+
continue;
|
|
1521
|
+
}
|
|
1522
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:")
|
|
1523
|
+
return url;
|
|
1524
|
+
}
|
|
1525
|
+
return undefined;
|
|
1526
|
+
}
|
|
1527
|
+
/** First non-empty `content` of the named meta tags (name or http-equiv). */
|
|
1528
|
+
function metaContentOf(names, document) {
|
|
1529
|
+
for (const name of names) {
|
|
1530
|
+
const element = document.querySelector(`meta[name="${name}" i]`) ?? document.querySelector(`meta[http-equiv="${name}" i]`);
|
|
1531
|
+
const content = element?.getAttribute("content")?.trim();
|
|
1532
|
+
if (content !== undefined && content !== "")
|
|
1533
|
+
return content;
|
|
1534
|
+
}
|
|
1535
|
+
return undefined;
|
|
1536
|
+
}
|
|
1460
1537
|
/**
|
|
1461
1538
|
* Extracts metadata from the input document: <title>, the usual
|
|
1462
|
-
* author/description/keywords meta tags, the
|
|
1463
|
-
*
|
|
1464
|
-
*
|
|
1539
|
+
* author/description/keywords meta tags, the DOI (citation_doi, dc.doi,
|
|
1540
|
+
* dc.identifier when it holds a DOI), the document URL (canonical link,
|
|
1541
|
+
* og:url), the creation/modification dates (dcterms, falling back to the
|
|
1542
|
+
* plain date meta tag) and the document language.
|
|
1465
1543
|
*/
|
|
1466
1544
|
function extractMetadataFromDocument(document) {
|
|
1467
1545
|
const title = document.querySelector("title")?.textContent?.trim();
|
|
1468
|
-
const metaContent = (names) => {
|
|
1469
|
-
for (const name of names) {
|
|
1470
|
-
const element = document.querySelector(`meta[name="${name}" i]`) ?? document.querySelector(`meta[http-equiv="${name}" i]`);
|
|
1471
|
-
const content = element?.getAttribute("content")?.trim();
|
|
1472
|
-
if (content !== undefined && content !== "")
|
|
1473
|
-
return content;
|
|
1474
|
-
}
|
|
1475
|
-
return undefined;
|
|
1476
|
-
};
|
|
1477
1546
|
return {
|
|
1478
1547
|
...(title === undefined || title === "" ? {} : { title }),
|
|
1479
|
-
...optional(
|
|
1480
|
-
...optional(
|
|
1481
|
-
...optional(
|
|
1482
|
-
...optional(
|
|
1483
|
-
...optional(
|
|
1484
|
-
...optional(
|
|
1548
|
+
...optional(metaContentOf(["author", "dc.creator", "dcterms.creator"], document), (value) => ({ author: value })),
|
|
1549
|
+
...optional(metaContentOf(["description", "dc.description"], document), (value) => ({ subject: value })),
|
|
1550
|
+
...optional(metaContentOf(["keywords"], document), (value) => ({ keywords: value })),
|
|
1551
|
+
...optional(doiMetaContent(["citation_doi", "dc.doi", "dc.identifier", "doi"], document), (value) => ({ doi: value })),
|
|
1552
|
+
...optional(extractDocumentUrl(document), (value) => ({ url: value })),
|
|
1553
|
+
...optional(metaContentOf(["dcterms.created", "dc.date", "date"], document), (value) => ({ created: value })),
|
|
1554
|
+
...optional(metaContentOf(["dcterms.modified", "dc.date.modified", "modified"], document), (value) => ({ modified: value })),
|
|
1555
|
+
...optional(document.documentElement.getAttribute("lang")?.trim() || metaContentOf(["content-language"], document), (value) => ({
|
|
1485
1556
|
language: value
|
|
1486
1557
|
}))
|
|
1487
1558
|
};
|
|
1488
1559
|
}
|
|
1489
1560
|
/**
|
|
1490
1561
|
* Extracts metadata from a publication manifest (W3C Web Publication
|
|
1491
|
-
* Manifest shape): title, author, description, keywords and
|
|
1492
|
-
* Returns undefined when the text is not a JSON object.
|
|
1562
|
+
* Manifest shape): title, author, description, keywords, DOI, URL and
|
|
1563
|
+
* language. Returns undefined when the text is not a JSON object.
|
|
1493
1564
|
*/
|
|
1494
1565
|
function extractMetadataFromManifest(text) {
|
|
1495
1566
|
let manifest;
|
|
@@ -1507,6 +1578,8 @@ function extractMetadataFromManifest(text) {
|
|
|
1507
1578
|
...optional(asAuthorList(record.author), (value) => ({ author: value })),
|
|
1508
1579
|
...optional(asString(record.description), (value) => ({ subject: value })),
|
|
1509
1580
|
...optional(asStringList(record.keywords, ", "), (value) => ({ keywords: value })),
|
|
1581
|
+
...optional(asDoi(record.doi ?? record.identifier), (value) => ({ doi: value })),
|
|
1582
|
+
...optional(asUrl(record.url), (value) => ({ url: value })),
|
|
1510
1583
|
...optional(asStringList(record.language ?? record.inLanguage, " "), (value) => ({ language: value }))
|
|
1511
1584
|
};
|
|
1512
1585
|
}
|
|
@@ -1563,6 +1636,27 @@ function optional(value, wrap) {
|
|
|
1563
1636
|
function asString(value) {
|
|
1564
1637
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : undefined;
|
|
1565
1638
|
}
|
|
1639
|
+
/** Reads a DOI from a manifest value; non-DOI identifiers are ignored. */
|
|
1640
|
+
function asDoi(value) {
|
|
1641
|
+
if (typeof value !== "string")
|
|
1642
|
+
return undefined;
|
|
1643
|
+
return normalizeDoi(value);
|
|
1644
|
+
}
|
|
1645
|
+
/** Reads a http(s) URL from a manifest value; relative links are ignored. */
|
|
1646
|
+
function asUrl(value) {
|
|
1647
|
+
if (typeof value !== "string")
|
|
1648
|
+
return undefined;
|
|
1649
|
+
const url = value.trim();
|
|
1650
|
+
try {
|
|
1651
|
+
const parsed = new URL(url);
|
|
1652
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
1653
|
+
return undefined;
|
|
1654
|
+
}
|
|
1655
|
+
catch {
|
|
1656
|
+
return undefined;
|
|
1657
|
+
}
|
|
1658
|
+
return url;
|
|
1659
|
+
}
|
|
1566
1660
|
/** Flattens string | {name} | ({name} | string)[] into "a; b" form. */
|
|
1567
1661
|
function asAuthorList(value) {
|
|
1568
1662
|
const names = Array.isArray(value) ? value : [value];
|
|
@@ -2755,6 +2849,8 @@ function buildProgram() {
|
|
|
2755
2849
|
.option("--author <author>", "Document author")
|
|
2756
2850
|
.option("--subject <subject>", "Document subject (e.g. the page's description meta tag content)")
|
|
2757
2851
|
.option("--keywords <keywords>", "Document keywords, comma separated")
|
|
2852
|
+
.option("--doi <doi>", "Document DOI (bare, doi: URI or doi.org URL). Wins over --url for the XMP identifier")
|
|
2853
|
+
.option("--url <url>", "Document URL; XMP dc:identifier when no DOI is set (reference managers read it)")
|
|
2758
2854
|
.option("--language <lang>", "Document language tag (e.g. en, de, ja). Taken from the document or manifest when omitted, falling back to 'de'")
|
|
2759
2855
|
.option("--created <date>", "Document creation date (ISO 8601, e.g. 2024-11-18T00:00:00+01:00). Taken from the document's dcterms.created meta tag when omitted")
|
|
2760
2856
|
.option("--modified <date>", "Document modification date (ISO 8601). Taken from the document's dcterms.modified meta tag when omitted")
|
|
@@ -2860,7 +2956,7 @@ function buildProgram() {
|
|
|
2860
2956
|
" • the browser prints that page to PDF, so canvases and iframes stay real content.",
|
|
2861
2957
|
" • Collapsed <details> content is opened for the PDF; the preview keeps the page as it is.",
|
|
2862
2958
|
" • --asset-base localBase is also a fallback root for CSS-referenced assets.",
|
|
2863
|
-
" • PDF metadata (--title/--author/--subject/--keywords/--language/--created/--modified)",
|
|
2959
|
+
" • PDF metadata (--title/--author/--subject/--keywords/--doi/--url/--language/--created/--modified)",
|
|
2864
2960
|
" • values read from the document or the publication manifest; language falls",
|
|
2865
2961
|
" • back to 'de'. --pdfa/--pdfx label the output; the built-in validation",
|
|
2866
2962
|
" • checks the practical subset (--no-validate skips it) and --verapdf runs",
|
|
@@ -2901,6 +2997,8 @@ async function runRender(params) {
|
|
|
2901
2997
|
...(params.metaFields.author === undefined ? {} : { author: params.metaFields.author }),
|
|
2902
2998
|
...(params.metaFields.subject === undefined ? {} : { subject: params.metaFields.subject }),
|
|
2903
2999
|
...(params.metaFields.keywords === undefined ? {} : { keywords: params.metaFields.keywords }),
|
|
3000
|
+
...(params.metaFields.doi === undefined ? {} : { doi: params.metaFields.doi }),
|
|
3001
|
+
...(params.metaFields.url === undefined ? {} : { url: params.metaFields.url }),
|
|
2904
3002
|
...(params.metaFields.language === undefined ? {} : { language: params.metaFields.language }),
|
|
2905
3003
|
...(params.metaFields.created === undefined ? {} : { created: params.metaFields.created }),
|
|
2906
3004
|
...(params.metaFields.modified === undefined ? {} : { modified: params.metaFields.modified }),
|
|
@@ -3018,10 +3116,19 @@ function resolvePdfMetadata(options, inputAbs, htmlMode) {
|
|
|
3018
3116
|
"author",
|
|
3019
3117
|
"subject",
|
|
3020
3118
|
"keywords",
|
|
3119
|
+
"doi",
|
|
3120
|
+
"url",
|
|
3021
3121
|
"language",
|
|
3022
3122
|
"created",
|
|
3023
3123
|
"modified"
|
|
3024
3124
|
]);
|
|
3125
|
+
if (cliFields.doi !== undefined) {
|
|
3126
|
+
const normalized = normalizeDoi(cliFields.doi);
|
|
3127
|
+
if (normalized === undefined) {
|
|
3128
|
+
throw new Error(`--doi is not a DOI: "${cliFields.doi}". Use the bare form (10.xxxx/…), a doi: URI or a doi.org URL`);
|
|
3129
|
+
}
|
|
3130
|
+
cliFields.doi = normalized;
|
|
3131
|
+
}
|
|
3025
3132
|
let derived;
|
|
3026
3133
|
if (htmlMode) {
|
|
3027
3134
|
derived = extractMetadataFromDocument(new JSDOM(readFileSync(inputAbs, "utf-8")).window.document);
|
package/package.json
CHANGED
package/src/metadata.ts
CHANGED
|
@@ -21,6 +21,10 @@ export type DocumentMetadata = {
|
|
|
21
21
|
author?: string;
|
|
22
22
|
subject?: string;
|
|
23
23
|
keywords?: string;
|
|
24
|
+
/** Normalized bare DOI (10.…/…); reference managers read it as dc:identifier. */
|
|
25
|
+
doi?: string;
|
|
26
|
+
/** Source URL of the document, used as dc:identifier when no DOI is known. */
|
|
27
|
+
url?: string;
|
|
24
28
|
language?: string;
|
|
25
29
|
/** ISO 8601 creation date (information dictionary and XMP CreateDate). */
|
|
26
30
|
created?: string;
|
|
@@ -31,30 +35,89 @@ export type DocumentMetadata = {
|
|
|
31
35
|
/** Language tag assumed when no source provides one (project contract). */
|
|
32
36
|
export const DEFAULT_LANGUAGE = "de";
|
|
33
37
|
|
|
38
|
+
// Bare DOI form (ISO 26324): a directory indicator plus a suffix. Accepts
|
|
39
|
+
// variants authors hand over: bare, doi: URIs and resolver URLs.
|
|
40
|
+
export const DOI_PATTERN = /^10\.\d{4,9}\/\S+$/;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Normalizes a DOI the user supplied: resolver URLs (`https://doi.org/…`,
|
|
44
|
+
* `http://dx.doi.org/…`, `https://hdl.handle.net/…` keeps `10.` handles) and
|
|
45
|
+
* `doi:` URIs reduce to the bare form, which is validated against ISO 26324.
|
|
46
|
+
* Returns undefined when the value is not a DOI at all.
|
|
47
|
+
*/
|
|
48
|
+
export function normalizeDoi(value: string): string | undefined {
|
|
49
|
+
let doi = value.trim();
|
|
50
|
+
for (const prefix of ["https://doi.org/", "http://doi.org/", "https://dx.doi.org/", "http://dx.doi.org/", "doi:"]) {
|
|
51
|
+
if (doi.toLowerCase().startsWith(prefix.toLowerCase())) {
|
|
52
|
+
doi = doi.slice(prefix.length);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
doi = doi.trim();
|
|
57
|
+
if (!DOI_PATTERN.test(doi)) return undefined;
|
|
58
|
+
return doi;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Reads a DOI from a meta content, ignoring values that are not DOIs. */
|
|
62
|
+
function doiMetaContent(names: readonly string[], document: Document): string | undefined {
|
|
63
|
+
const content = metaContentOf(names, document);
|
|
64
|
+
return content === undefined ? undefined : normalizeDoi(content);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Extracts a document URL: the canonical link wins, then the usual
|
|
69
|
+
* URL meta tags. Only absolute http(s) URLs are accepted.
|
|
70
|
+
*/
|
|
71
|
+
function extractDocumentUrl(document: Document): string | undefined {
|
|
72
|
+
const candidates: Array<string | null | undefined> = [
|
|
73
|
+
document.querySelector('link[rel="canonical" i]')?.getAttribute("href"),
|
|
74
|
+
document.querySelector('meta[property="og:url" i]')?.getAttribute("content"),
|
|
75
|
+
document.querySelector('meta[name="citation_url" i]')?.getAttribute("content"),
|
|
76
|
+
document.querySelector('meta[name="dc.url" i]')?.getAttribute("content")
|
|
77
|
+
];
|
|
78
|
+
for (const candidate of candidates) {
|
|
79
|
+
const url = candidate?.trim();
|
|
80
|
+
if (url === undefined || url === "") continue;
|
|
81
|
+
let parsed: URL;
|
|
82
|
+
try {
|
|
83
|
+
parsed = new URL(url);
|
|
84
|
+
} catch {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") return url;
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** First non-empty `content` of the named meta tags (name or http-equiv). */
|
|
93
|
+
function metaContentOf(names: readonly string[], document: Document): string | undefined {
|
|
94
|
+
for (const name of names) {
|
|
95
|
+
const element = document.querySelector(`meta[name="${name}" i]`) ?? document.querySelector(`meta[http-equiv="${name}" i]`);
|
|
96
|
+
const content = element?.getAttribute("content")?.trim();
|
|
97
|
+
if (content !== undefined && content !== "") return content;
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
34
102
|
/**
|
|
35
103
|
* Extracts metadata from the input document: <title>, the usual
|
|
36
|
-
* author/description/keywords meta tags, the
|
|
37
|
-
*
|
|
38
|
-
*
|
|
104
|
+
* author/description/keywords meta tags, the DOI (citation_doi, dc.doi,
|
|
105
|
+
* dc.identifier when it holds a DOI), the document URL (canonical link,
|
|
106
|
+
* og:url), the creation/modification dates (dcterms, falling back to the
|
|
107
|
+
* plain date meta tag) and the document language.
|
|
39
108
|
*/
|
|
40
109
|
export function extractMetadataFromDocument(document: Document): DocumentMetadata {
|
|
41
110
|
const title = document.querySelector("title")?.textContent?.trim();
|
|
42
|
-
const metaContent = (names: readonly string[]): string | undefined => {
|
|
43
|
-
for (const name of names) {
|
|
44
|
-
const element = document.querySelector(`meta[name="${name}" i]`) ?? document.querySelector(`meta[http-equiv="${name}" i]`);
|
|
45
|
-
const content = element?.getAttribute("content")?.trim();
|
|
46
|
-
if (content !== undefined && content !== "") return content;
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
};
|
|
50
111
|
return {
|
|
51
112
|
...(title === undefined || title === "" ? {} : { title }),
|
|
52
|
-
...optional(
|
|
53
|
-
...optional(
|
|
54
|
-
...optional(
|
|
55
|
-
...optional(
|
|
56
|
-
...optional(
|
|
57
|
-
...optional(
|
|
113
|
+
...optional(metaContentOf(["author", "dc.creator", "dcterms.creator"], document), (value) => ({ author: value })),
|
|
114
|
+
...optional(metaContentOf(["description", "dc.description"], document), (value) => ({ subject: value })),
|
|
115
|
+
...optional(metaContentOf(["keywords"], document), (value) => ({ keywords: value })),
|
|
116
|
+
...optional(doiMetaContent(["citation_doi", "dc.doi", "dc.identifier", "doi"], document), (value) => ({ doi: value })),
|
|
117
|
+
...optional(extractDocumentUrl(document), (value) => ({ url: value })),
|
|
118
|
+
...optional(metaContentOf(["dcterms.created", "dc.date", "date"], document), (value) => ({ created: value })),
|
|
119
|
+
...optional(metaContentOf(["dcterms.modified", "dc.date.modified", "modified"], document), (value) => ({ modified: value })),
|
|
120
|
+
...optional(document.documentElement.getAttribute("lang")?.trim() || metaContentOf(["content-language"], document), (value) => ({
|
|
58
121
|
language: value
|
|
59
122
|
}))
|
|
60
123
|
};
|
|
@@ -62,8 +125,8 @@ export function extractMetadataFromDocument(document: Document): DocumentMetadat
|
|
|
62
125
|
|
|
63
126
|
/**
|
|
64
127
|
* Extracts metadata from a publication manifest (W3C Web Publication
|
|
65
|
-
* Manifest shape): title, author, description, keywords and
|
|
66
|
-
* Returns undefined when the text is not a JSON object.
|
|
128
|
+
* Manifest shape): title, author, description, keywords, DOI, URL and
|
|
129
|
+
* language. Returns undefined when the text is not a JSON object.
|
|
67
130
|
*/
|
|
68
131
|
export function extractMetadataFromManifest(text: string): DocumentMetadata | undefined {
|
|
69
132
|
let manifest: unknown;
|
|
@@ -79,6 +142,8 @@ export function extractMetadataFromManifest(text: string): DocumentMetadata | un
|
|
|
79
142
|
...optional(asAuthorList(record.author), (value) => ({ author: value })),
|
|
80
143
|
...optional(asString(record.description), (value) => ({ subject: value })),
|
|
81
144
|
...optional(asStringList(record.keywords, ", "), (value) => ({ keywords: value })),
|
|
145
|
+
...optional(asDoi(record.doi ?? record.identifier), (value) => ({ doi: value })),
|
|
146
|
+
...optional(asUrl(record.url), (value) => ({ url: value })),
|
|
82
147
|
...optional(asStringList(record.language ?? record.inLanguage, " "), (value) => ({ language: value }))
|
|
83
148
|
};
|
|
84
149
|
}
|
|
@@ -140,6 +205,25 @@ function asString(value: unknown): string | undefined {
|
|
|
140
205
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : undefined;
|
|
141
206
|
}
|
|
142
207
|
|
|
208
|
+
/** Reads a DOI from a manifest value; non-DOI identifiers are ignored. */
|
|
209
|
+
function asDoi(value: unknown): string | undefined {
|
|
210
|
+
if (typeof value !== "string") return undefined;
|
|
211
|
+
return normalizeDoi(value);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Reads a http(s) URL from a manifest value; relative links are ignored. */
|
|
215
|
+
function asUrl(value: unknown): string | undefined {
|
|
216
|
+
if (typeof value !== "string") return undefined;
|
|
217
|
+
const url = value.trim();
|
|
218
|
+
try {
|
|
219
|
+
const parsed = new URL(url);
|
|
220
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return undefined;
|
|
221
|
+
} catch {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
return url;
|
|
225
|
+
}
|
|
226
|
+
|
|
143
227
|
/** Flattens string | {name} | ({name} | string)[] into "a; b" form. */
|
|
144
228
|
function asAuthorList(value: unknown): string | undefined {
|
|
145
229
|
const names = Array.isArray(value) ? value : [value];
|
|
@@ -35,6 +35,10 @@ export type PdfMetadata = {
|
|
|
35
35
|
author?: string;
|
|
36
36
|
subject?: string;
|
|
37
37
|
keywords?: string;
|
|
38
|
+
/** Bare DOI; wins over url for the XMP dc:identifier. */
|
|
39
|
+
doi?: string;
|
|
40
|
+
/** Source URL; dc:identifier when no DOI is set. */
|
|
41
|
+
url?: string;
|
|
38
42
|
language?: string;
|
|
39
43
|
/** ISO 8601 or PDF date; overrides the creation date the print backend wrote. */
|
|
40
44
|
created?: string;
|
|
@@ -251,6 +255,8 @@ export async function postProcessPdf(pdf: Uint8Array, options: PostProcessOption
|
|
|
251
255
|
author: metadata.author,
|
|
252
256
|
subject: metadata.subject,
|
|
253
257
|
keywords: metadata.keywords,
|
|
258
|
+
doi: metadata.doi,
|
|
259
|
+
url: metadata.url,
|
|
254
260
|
producer: metadata.producer,
|
|
255
261
|
creatorTool: metadata.creator,
|
|
256
262
|
createDate: createDateXmp,
|
package/src/render/pdf.ts
CHANGED
|
@@ -53,6 +53,8 @@ export type RenderPdfRequest = {
|
|
|
53
53
|
author?: string;
|
|
54
54
|
subject?: string;
|
|
55
55
|
keywords?: string;
|
|
56
|
+
doi?: string;
|
|
57
|
+
url?: string;
|
|
56
58
|
language?: string;
|
|
57
59
|
/** ISO 8601 creation date; overrides the one the print backend wrote. */
|
|
58
60
|
created?: string;
|
|
@@ -101,6 +103,8 @@ function pdfMetadata(request: RenderPdfRequest) {
|
|
|
101
103
|
...(request.author === undefined ? {} : { author: request.author }),
|
|
102
104
|
...(request.subject === undefined ? {} : { subject: request.subject }),
|
|
103
105
|
...(request.keywords === undefined ? {} : { keywords: request.keywords }),
|
|
106
|
+
...(request.doi === undefined ? {} : { doi: request.doi }),
|
|
107
|
+
...(request.url === undefined ? {} : { url: request.url }),
|
|
104
108
|
...(request.language === undefined ? {} : { language: request.language }),
|
|
105
109
|
...(request.created === undefined ? {} : { created: request.created }),
|
|
106
110
|
...(request.modified === undefined ? {} : { modified: request.modified }),
|
package/src/render/xmp.ts
CHANGED
|
@@ -45,6 +45,10 @@ export type XmpFields = {
|
|
|
45
45
|
author?: string;
|
|
46
46
|
subject?: string;
|
|
47
47
|
keywords?: string;
|
|
48
|
+
/** Bare DOI; wins over url for dc:identifier (what reference managers read). */
|
|
49
|
+
doi?: string;
|
|
50
|
+
/** Source URL; used as dc:identifier only when no DOI is set. */
|
|
51
|
+
url?: string;
|
|
48
52
|
producer?: string;
|
|
49
53
|
creatorTool?: string;
|
|
50
54
|
/** XMP dates (YYYY-MM-DDThh:mm:ssTZD, XMP Part 1, 8.2.1.2). */
|
|
@@ -143,6 +147,14 @@ export function buildXmpPacket(fields: XmpFields, label?: PdfLabel): string {
|
|
|
143
147
|
if (fields.keywords !== undefined) {
|
|
144
148
|
properties.push(`<pdf:Keywords>${xmlEscape(fields.keywords)}</pdf:Keywords>`);
|
|
145
149
|
}
|
|
150
|
+
// dc:identifier carries the DOI when one is known — Zotero and friends pick
|
|
151
|
+
// it up on PDF import — otherwise the source URL. The info dictionary has
|
|
152
|
+
// no entry for either, so this is the only place they appear.
|
|
153
|
+
if (fields.doi !== undefined) {
|
|
154
|
+
properties.push(`<dc:identifier>doi:${xmlEscape(fields.doi)}</dc:identifier>`);
|
|
155
|
+
} else if (fields.url !== undefined) {
|
|
156
|
+
properties.push(`<dc:identifier>${xmlEscape(fields.url)}</dc:identifier>`);
|
|
157
|
+
}
|
|
146
158
|
if (fields.producer !== undefined) {
|
|
147
159
|
properties.push(`<pdf:Producer>${xmlEscape(fields.producer)}</pdf:Producer>`);
|
|
148
160
|
}
|
package/src/vivliostyle-cli.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { loadDefaultIccProfile } from "./render/pdf-postprocess.js";
|
|
|
17
17
|
import {
|
|
18
18
|
extractMetadataFromDocument,
|
|
19
19
|
extractMetadataFromManifest,
|
|
20
|
+
normalizeDoi,
|
|
20
21
|
parsePdfaLabel,
|
|
21
22
|
parsePdfxLabel,
|
|
22
23
|
resolveMetadata,
|
|
@@ -35,6 +36,8 @@ type CliOptions = {
|
|
|
35
36
|
author?: string;
|
|
36
37
|
subject?: string;
|
|
37
38
|
keywords?: string;
|
|
39
|
+
doi?: string;
|
|
40
|
+
url?: string;
|
|
38
41
|
language?: string;
|
|
39
42
|
created?: string;
|
|
40
43
|
modified?: string;
|
|
@@ -1424,6 +1427,8 @@ function buildProgram(): Command {
|
|
|
1424
1427
|
.option("--author <author>", "Document author")
|
|
1425
1428
|
.option("--subject <subject>", "Document subject (e.g. the page's description meta tag content)")
|
|
1426
1429
|
.option("--keywords <keywords>", "Document keywords, comma separated")
|
|
1430
|
+
.option("--doi <doi>", "Document DOI (bare, doi: URI or doi.org URL). Wins over --url for the XMP identifier")
|
|
1431
|
+
.option("--url <url>", "Document URL; XMP dc:identifier when no DOI is set (reference managers read it)")
|
|
1427
1432
|
.option(
|
|
1428
1433
|
"--language <lang>",
|
|
1429
1434
|
"Document language tag (e.g. en, de, ja). Taken from the document or manifest when omitted, falling back to 'de'"
|
|
@@ -1590,7 +1595,7 @@ function buildProgram(): Command {
|
|
|
1590
1595
|
" • the browser prints that page to PDF, so canvases and iframes stay real content.",
|
|
1591
1596
|
" • Collapsed <details> content is opened for the PDF; the preview keeps the page as it is.",
|
|
1592
1597
|
" • --asset-base localBase is also a fallback root for CSS-referenced assets.",
|
|
1593
|
-
" • PDF metadata (--title/--author/--subject/--keywords/--language/--created/--modified)",
|
|
1598
|
+
" • PDF metadata (--title/--author/--subject/--keywords/--doi/--url/--language/--created/--modified)",
|
|
1594
1599
|
" • values read from the document or the publication manifest; language falls",
|
|
1595
1600
|
" • back to 'de'. --pdfa/--pdfx label the output; the built-in validation",
|
|
1596
1601
|
" • checks the practical subset (--no-validate skips it) and --verapdf runs",
|
|
@@ -1629,7 +1634,7 @@ export function parseArgs(argv: string[]): {
|
|
|
1629
1634
|
// ---------------------------------------------------------------------------
|
|
1630
1635
|
|
|
1631
1636
|
/** Metadata fields the CLI layer resolves before handing them to the renderer. */
|
|
1632
|
-
type MetadataFieldName = "title" | "author" | "subject" | "keywords" | "language" | "created" | "modified";
|
|
1637
|
+
type MetadataFieldName = "title" | "author" | "subject" | "keywords" | "doi" | "url" | "language" | "created" | "modified";
|
|
1633
1638
|
|
|
1634
1639
|
/** ICC profile bytes with the name they get in the PDF's OutputIntent. */
|
|
1635
1640
|
type IccProfile = { bytes: Uint8Array; name: string };
|
|
@@ -1666,6 +1671,8 @@ async function runRender(params: RenderParams): Promise<void> {
|
|
|
1666
1671
|
...(params.metaFields.author === undefined ? {} : { author: params.metaFields.author }),
|
|
1667
1672
|
...(params.metaFields.subject === undefined ? {} : { subject: params.metaFields.subject }),
|
|
1668
1673
|
...(params.metaFields.keywords === undefined ? {} : { keywords: params.metaFields.keywords }),
|
|
1674
|
+
...(params.metaFields.doi === undefined ? {} : { doi: params.metaFields.doi }),
|
|
1675
|
+
...(params.metaFields.url === undefined ? {} : { url: params.metaFields.url }),
|
|
1669
1676
|
...(params.metaFields.language === undefined ? {} : { language: params.metaFields.language }),
|
|
1670
1677
|
...(params.metaFields.created === undefined ? {} : { created: params.metaFields.created }),
|
|
1671
1678
|
...(params.metaFields.modified === undefined ? {} : { modified: params.metaFields.modified }),
|
|
@@ -1782,7 +1789,7 @@ export function resolveIccProfile(options: Pick<CliOptions, "iccProfile">, label
|
|
|
1782
1789
|
* to "de" when no source provides one.
|
|
1783
1790
|
*/
|
|
1784
1791
|
export function resolvePdfMetadata(
|
|
1785
|
-
options: Pick<CliOptions, "title" | "author" | "subject" | "keywords" | "language" | "created" | "modified">,
|
|
1792
|
+
options: Pick<CliOptions, "title" | "author" | "subject" | "keywords" | "doi" | "url" | "language" | "created" | "modified">,
|
|
1786
1793
|
inputAbs: string,
|
|
1787
1794
|
htmlMode: boolean
|
|
1788
1795
|
): DocumentMetadata & { language: string } {
|
|
@@ -1791,10 +1798,19 @@ export function resolvePdfMetadata(
|
|
|
1791
1798
|
"author",
|
|
1792
1799
|
"subject",
|
|
1793
1800
|
"keywords",
|
|
1801
|
+
"doi",
|
|
1802
|
+
"url",
|
|
1794
1803
|
"language",
|
|
1795
1804
|
"created",
|
|
1796
1805
|
"modified"
|
|
1797
1806
|
]) as DocumentMetadata;
|
|
1807
|
+
if (cliFields.doi !== undefined) {
|
|
1808
|
+
const normalized = normalizeDoi(cliFields.doi);
|
|
1809
|
+
if (normalized === undefined) {
|
|
1810
|
+
throw new Error(`--doi is not a DOI: "${cliFields.doi}". Use the bare form (10.xxxx/…), a doi: URI or a doi.org URL`);
|
|
1811
|
+
}
|
|
1812
|
+
cliFields.doi = normalized;
|
|
1813
|
+
}
|
|
1798
1814
|
let derived: DocumentMetadata | undefined;
|
|
1799
1815
|
if (htmlMode) {
|
|
1800
1816
|
derived = extractMetadataFromDocument(new JSDOM(readFileSync(inputAbs, "utf-8")).window.document);
|