-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathUS National Archives Research Catalog.js
275 lines (259 loc) · 7.98 KB
/
US National Archives Research Catalog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
{
"translatorID": "f8b5501a-1acc-4ffa-a0a5-594add5e6bd3",
"label": "US National Archives Research Catalog",
"creator": "Philipp Zumstein",
"target": "^https?://catalog\\.archives\\.gov/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2025-03-20 15:44:13"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2017 Philipp Zumstein
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
function detectWeb(doc, url) {
if (url.includes('/id/')) {
return "book";
// something like archival material would be more appropriate...
// but for now we use this type to save some information
}
// multiples will not work easily because the API will then return
// somehow an empty json, thus we skipped this here.
return false;
}
async function doWeb(doc, url) {
let id = doc.location.pathname.match(/\/id\/(\d+)/)[1];
let jsonURL = `https://catalog.archives.gov/proxy/records/search?naId_is=${id}&allowLegacyOrgNames=true`;
let json = (await requestJSON(jsonURL)).body.hits.hits[0]._source.record;
let item = new Zotero.Item("book");
item.title = json.title;
var creators = [];
if (json.creators) {
creators.push(...json.creators);
}
if (json.ancestors) {
for (let ancestor of json.ancestors) {
if (ancestor.creators) {
creators.push(...ancestor.creators);
}
}
}
for (var i = 0; i < creators.length; i++) {
creators[i] = creators[i].heading.replace('(Most Recent)', '');
// TODO: Update and simplify this. We should be able to clean authors like:
// Veterans Administration. (7/21/1930 - 3/15/1989)
// and probably don't need two branches for the cleaning.
if (creators[i].includes(", ")) {
creators[i] = creators[i].replace(/, \d{4}\s*-\s*(\d{4})?$/, '').replace(/\([^(]+\)/, '');
item.creators.push(ZU.cleanAuthor(creators[i], "author", true));
}
else {
creators[i] = creators[i].replace(/\.? ?\d\d?\/\d\d?\/\d\d\d\d-\d\d?\/\d\d?\/\d\d\d\d/, '');
if (creators[i].length > 255) {
creators[i] = creators[i].substr(0, 251) + '...';
}
item.creators.push({ lastName: creators[i].trim(), creatorType: 'author', fieldMode: 1 });
}
}
if (doc.querySelector('#preview.digital-objects')) {
item.url = url;
}
else {
item.attachments.push({
title: 'Catalog Page',
url,
mimeType: 'text/html'
});
}
let resourcesHeading = doc.querySelector('h2#resources');
if (resourcesHeading) {
for (let resource of resourcesHeading.parentElement.querySelectorAll('a[role="link"]')) {
let href = resource.title.match(/Go to (https:\/\/[^\s]+)/);
if (!href) continue;
item.attachments.push({
title: resource.textContent,
url: href[1],
mimeType: 'text/html',
snapshot: false
});
}
}
if (json.coverageStartDate) {
item.date = json.coverageStartDate.logicalDate.replace('-01-01', '');
// Use issued if we have a date range
if (json.coverageEndDate) {
item.extra = 'issued: ' + item.date + '/'
+ json.coverageEndDate.logicalDate.replace('-12-31', '');
}
}
else {
item.date = json.date;
}
if (json.ancestors.length) {
item.series = json.ancestors[0].title;
}
item.abstractNote = json.scopeAndContentNote;
if (json.physicalOccurrences) {
for (let p of json.physicalOccurrences) {
if (p.referenceUnits.length && p.referenceUnits[0].name) {
item.archive = p.referenceUnits[0].name.replace(/\[.*\]/, '');
break;
}
}
}
item.archiveLocation = json.localIdentifier;
item.extra = (item.extra || '') + '\nNational Archives Identifier: ' + json.naId;
item.complete();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://catalog.archives.gov/id/486076",
"items": [
{
"itemType": "book",
"title": "The Struggle for Trade Union Democracy, December 1947",
"creators": [
{
"lastName": "Supreme Commander for the Allied Powers. Economic and Scientific Section. Director for Labor. Labor Division",
"creatorType": "author",
"fieldMode": 1
}
],
"date": "1945",
"archive": "National Archives at College Park - Textual Reference",
"extra": "issued: 1945/1952\nNational Archives Identifier: 486076",
"libraryCatalog": "US National Archives Research Catalog",
"series": "Records of Allied Operational and Occupation Headquarters, World War II",
"attachments": [
{
"title": "Catalog Page",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://catalog.archives.gov/id/5496901",
"items": [
{
"itemType": "book",
"title": "Alien Case File for Francisca Torre Vda De Garcia",
"creators": [
{
"lastName": "Department of Justice. Immigration and Naturalization Service",
"creatorType": "author",
"fieldMode": 1
}
],
"abstractNote": "This file consists of an alien case file for Francisca Torre Vda De Garcia. Date of birth is listed as 10/10/1901. Country is listed as Cuba. Port of Entry is Miami, Florida. Date of entry is 03/08/1973. Father is listed as Zotero. Mother is listed as Candita. Alias name is listed as Francisca Torres.",
"archive": "National Archives at Kansas City",
"archiveLocation": "A20229735/085-08-0653/Box 186",
"extra": "National Archives Identifier: 5496901",
"libraryCatalog": "US National Archives Research Catalog",
"series": "Records of U.S. Citizenship and Immigration Services",
"attachments": [
{
"title": "Catalog Page",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://catalog.archives.gov/id/603604",
"items": [
{
"itemType": "book",
"title": "Manuscripts and Notes",
"creators": [
{
"firstName": "Harriet C.",
"lastName": "Brown",
"creatorType": "author"
}
],
"abstractNote": "This series contains book drafts and correspondence.",
"archive": "Herbert Hoover Library",
"extra": "National Archives Identifier: 603604",
"libraryCatalog": "US National Archives Research Catalog",
"series": "Harriet Connor Brown Papers",
"attachments": [
{
"title": "Catalog Page",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://catalog.archives.gov/id/115728212",
"defer": true,
"items": [
{
"itemType": "book",
"title": "Approved Pension Application File for Lucy Test, Mother of Joseph R Test, Company C, 11th Ohio Infantry Regiment (Application No. WC46539)",
"creators": [
{
"lastName": "Veterans Administration. (7/21/1930 - 3/15/1989)",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Department of the Interior. Bureau of Pensions. 1849-1930",
"creatorType": "author",
"fieldMode": 1
}
],
"archive": "National Archives at Washington, DC - Textual Reference",
"extra": "National Archives Identifier: 115728212",
"libraryCatalog": "US National Archives Research Catalog",
"series": "Records of the Department of Veterans Affairs",
"url": "https://catalog.archives.gov/id/115728212",
"attachments": [
{
"title": "Fold3",
"mimeType": "text/html",
"snapshot": false
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/