Skip to content

Commit

Permalink
[api-minor] Change the dc:subject Metadata field to an Array
Browse files Browse the repository at this point in the history
This patch simply extends the existing handling of the `dc:creator` field, which should hopefully suffice here; please refer to https://wwwimages2.adobe.com/content/dam/acom/en/devnet/xmp/pdfs/XMP%20SDK%20Release%20cc-2016-08/XMPSpecificationPart1.pdf#page=34
  • Loading branch information
Snuffleupagus committed Feb 14, 2021
1 parent f892c00 commit bcb2f1c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions src/display/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,18 @@ class Metadata {
return entry.childNodes.filter(node => node.nodeName === "rdf:li");
}

_getCreators(entry) {
if (entry.nodeName !== "dc:creator") {
return false;
}
_getArray(entry) {
if (!entry.hasChildNodes()) {
return true;
}

// Child must be a Bag (unordered array) or a Seq.
const seqNode = entry.childNodes[0];
const authors = this._getSequence(seqNode) || [];
const [seqNode] = entry.childNodes;
const sequence = this._getSequence(seqNode) || [];

this._metadataMap.set(
entry.nodeName,
authors.map(node => node.textContent.trim())
sequence.map(node => node.textContent.trim())
);

return true;
}

Expand All @@ -130,11 +126,15 @@ class Metadata {

for (const entry of desc.childNodes) {
const name = entry.nodeName;
if (name === "#text") {
continue;
}
if (this._getCreators(entry)) {
continue;
switch (name) {
case "#text":
continue;
case "dc:creator":
case "dc:subject":
if (this._getArray(entry)) {
continue;
}
break;
}
this._metadataMap.set(name, entry.textContent.trim());
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/metadata_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe("metadata", function () {
"dc:creator": [""],
"dc:description": "",
"dc:format": "application/pdf",
"dc:subject": "",
"dc:subject": [],
"dc:title": "",
"pdf:keywords": "",
"pdf:pdfversion": "1.7",
Expand Down

0 comments on commit bcb2f1c

Please sign in to comment.