File tree 2 files changed +20
-14
lines changed
2 files changed +20
-14
lines changed Original file line number Diff line number Diff line change @@ -89,22 +89,24 @@ class Metadata {
89
89
return entry . childNodes . filter ( node => node . nodeName === "rdf:li" ) ;
90
90
}
91
91
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
+
96
99
if ( ! entry . hasChildNodes ( ) ) {
97
100
return true ;
98
101
}
99
-
100
102
// Child must be a Bag (unordered array) or a Seq.
101
- const seqNode = entry . childNodes [ 0 ] ;
103
+ const [ seqNode ] = entry . childNodes ;
102
104
const authors = this . _getSequence ( seqNode ) || [ ] ;
105
+
103
106
this . _metadataMap . set (
104
- entry . nodeName ,
107
+ name ,
105
108
authors . map ( node => node . textContent . trim ( ) )
106
109
) ;
107
-
108
110
return true ;
109
111
}
110
112
@@ -130,11 +132,15 @@ class Metadata {
130
132
131
133
for ( const entry of desc . childNodes ) {
132
134
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 ;
138
144
}
139
145
this . _metadataMap . set ( name , entry . textContent . trim ( ) ) ;
140
146
}
Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ describe("metadata", function () {
171
171
"dc:creator" : [ "" ] ,
172
172
"dc:description" : "" ,
173
173
"dc:format" : "application/pdf" ,
174
- "dc:subject" : "" ,
174
+ "dc:subject" : [ ] ,
175
175
"dc:title" : "" ,
176
176
"pdf:keywords" : "" ,
177
177
"pdf:pdfversion" : "1.7" ,
You can’t perform that action at this time.
0 commit comments