Skip to content

Commit 53810f5

Browse files
committed
[api-minor] Change the dc:subject Metadata field to an Array
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
1 parent f892c00 commit 53810f5

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/display/metadata.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,24 @@ class Metadata {
8989
return entry.childNodes.filter(node => node.nodeName === "rdf:li");
9090
}
9191

92-
_getCreators(entry) {
93-
if (entry.nodeName !== "dc:creator") {
94-
return false;
95-
}
92+
_getArray(entry) {
93+
const name = entry.nodeName;
94+
assert(
95+
name === "dc:creator" || name === "dc:subject",
96+
`_getArray - unexpected type: "${name}".`
97+
);
98+
9699
if (!entry.hasChildNodes()) {
97100
return true;
98101
}
99-
100102
// Child must be a Bag (unordered array) or a Seq.
101-
const seqNode = entry.childNodes[0];
103+
const [seqNode] = entry.childNodes;
102104
const authors = this._getSequence(seqNode) || [];
105+
103106
this._metadataMap.set(
104-
entry.nodeName,
107+
name,
105108
authors.map(node => node.textContent.trim())
106109
);
107-
108110
return true;
109111
}
110112

@@ -130,11 +132,15 @@ class Metadata {
130132

131133
for (const entry of desc.childNodes) {
132134
const name = entry.nodeName;
133-
if (name === "#text") {
134-
continue;
135-
}
136-
if (this._getCreators(entry)) {
137-
continue;
135+
switch (name) {
136+
case "#text":
137+
continue;
138+
case "dc:creator":
139+
case "dc:subject":
140+
if (this._getArray(entry)) {
141+
continue;
142+
}
143+
break;
138144
}
139145
this._metadataMap.set(name, entry.textContent.trim());
140146
}

test/unit/metadata_spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describe("metadata", function () {
171171
"dc:creator": [""],
172172
"dc:description": "",
173173
"dc:format": "application/pdf",
174-
"dc:subject": "",
174+
"dc:subject": [],
175175
"dc:title": "",
176176
"pdf:keywords": "",
177177
"pdf:pdfversion": "1.7",

0 commit comments

Comments
 (0)