-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathThe National Archives (UK).js
242 lines (229 loc) · 7.39 KB
/
The National Archives (UK).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
{
"translatorID": "229d4678-4fa0-44f8-95c4-f4cfdb9b254c",
"label": "The National Archives (UK)",
"creator": "Sebastian Karcher and Abe Jellinek",
"target": "^https?://discovery\\.nationalarchives\\.gov\\.uk/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2021-08-12 20:12:57"
}
/**
Copyright (c) 2013-2021 Sebastian Karcher and Abe Jellinek
This program 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.
This program 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 this program. If not, see
<http://www.gnu.org/licenses/>.
*/
function detectWeb(doc, url) {
if (/details\/r\//i.test(url)) {
return "manuscript";
}
else if (/results\/r\/?\?.+hb=tna/i.test(url)) {
return "multiple";
}
return false;
}
function scrape(doc, url) {
var id = url.match(/details\/r\/([A-Z\-0-9]+)/i)[1];
var reference = ZU.xpathText(doc, '//tr/th[contains(text(), "Reference")]/following-sibling::td');
var tags = ZU.xpath(doc, '//span/a[@class="tagName"]');
var apiUrl = "http://discovery.nationalarchives.gov.uk/API/records/v1/details/" + id;
Zotero.Utilities.doGet(apiUrl, function (text) {
var data = JSON.parse(text);
var item = new Zotero.Item("manuscript");
var title = data.title || doc.title.split(' | ')[0];
item.title = ZU.cleanTags(title.replace(/<.+?>/g, ""));
item.archiveLocation = reference;
item.language = data.language;
item.date = data.coveringDates;
if (data.scopeContent && data.scopeContent.description) {
item.abstractNote = ZU.cleanTags(data.scopeContent.description
.replace(/<p>/g, "\n").replace(/<p>/g, "\n"))
.replace(/\n+/g, "\n");
}
var holdings = data.heldBy;
if (holdings && holdings.length) {
item.archive = holdings.map(entry => entry.xReferenceName).join();
}
item.type = data.physicalDescriptionForm;
item.attachments.push({
document: doc,
title: "Catalog Entry"
});
var creators = data.creatorName;
for (let creator of creators) {
if (creator.surname) {
if (creator.firstName) {
item.creators.push({
lastName: creator.surname,
firstName: creator.firstName,
creatorType: "author"
});
}
else {
item.creators.push({
lastName: creator.surname,
fieldMode: 1,
creatorType: "author"
});
}
}
else {
item.creators.push({
lastName: creator.xReferenceName,
fieldMode: 1,
creatorType: "contributor"
});
}
}
for (var tag of tags) {
item.tags.push({ tag: tag.textContent });
}
item.complete();
});
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
var items = [];
// search results
var titles = ZU.xpath(doc, '//ul[@id="search-results"]//a');
if (!titles.length) {
// TODO - other multiples
return;
// titles = ZU.xpath(doc, '//td[@id="leaf-linkarea2"]//a[contains(@href, "/receive/jportal_jparticle")]');
}
for (var i in titles) {
items[titles[i].href] = ZU.trimInternal(titles[i].textContent);
}
Zotero.selectItems(items, function (items) {
if (!items) {
return;
}
ZU.processDocuments(Object.keys(items), scrape);
});
}
else {
scrape(doc, url);
}
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://discovery.nationalarchives.gov.uk/details/r/C3454320",
"items": [
{
"itemType": "manuscript",
"title": "POSTERS: Food Production: Land girls - Horse-drawn plough, and girl. Artist: Dame Laura...",
"creators": [],
"date": "1939-1946",
"abstractNote": "POSTERS: Food Production: Land girls - Horse-drawn plough, and girl. \nArtist: Dame Laura Knight. \nMedia/Technique: Watercolour and gouache painting with a charcoal underdrawing.Executed on a heavy weight artist board. Light washes of the aqueous media have been applied on top of the loose charcoal sketch giving the painting a powdery, friable quality.",
"archive": "The National Archives, Kew",
"archiveLocation": "INF 3/108",
"libraryCatalog": "The National Archives (UK)",
"shortTitle": "POSTERS",
"attachments": [
{
"title": "Catalog Entry",
"mimeType": "text/html"
}
],
"tags": [
{
"tag": "land girls"
},
{
"tag": "women"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://discovery.nationalarchives.gov.uk/details/r/C31",
"items": [
{
"itemType": "manuscript",
"title": "Records of the National Dock Labour Corporation and National Dock Labour Board",
"creators": [
{
"lastName": "National Dock Labour Board",
"fieldMode": 1,
"creatorType": "contributor"
},
{
"lastName": "National Dock Labour Corporation",
"fieldMode": 1,
"creatorType": "contributor"
}
],
"date": "1748-1989",
"abstractNote": "Scope and Content\nThe records of the National Dock Labour Corporation, established to regularise dock labour during the Second World War, and the records of the National Dock Labour Board, which took over these functions in 1947.\nAlso included are the records of four local boards responsible for day to day running of the National Dock Labour Scheme from 1947:\nLondon Dock Labour BoardCumbria Dock Labour BoardGrimsby and Immingham Dock Labour BoardSouth Coast Dock Labour Board.",
"archive": "The National Archives, Kew",
"archiveLocation": "BK",
"language": "English",
"libraryCatalog": "The National Archives (UK)",
"manuscriptType": "series",
"attachments": [
{
"title": "Catalog Entry",
"mimeType": "text/html"
}
],
"tags": [
{
"tag": "bk23"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://discovery.nationalarchives.gov.uk/results/r?_q=labour&_hb=tna",
"items": "multiple"
},
{
"type": "web",
"url": "https://discovery.nationalarchives.gov.uk/details/r/6faa8c37-6e1a-4cf5-abf6-09eb73d68d68",
"items": [
{
"itemType": "manuscript",
"title": "Deeds relating to KIRKLEES",
"creators": [],
"date": "18 Sep 1236",
"abstractNote": "Confirmation by Henry III. to Kirklees Nunnery of grants from Reyner son of William Flandrensis, of the site of the house, Adam fil Peter for repairs and firing, Robert son of Gilbert de Barkeston, Henry Teutonicus, John fil Aumund, Agnes de Flammeuill, Reimund de Medelay. Witnesses, W(illiam) elect 'Valent' (Bp. of Valence?), Peter de Malo lacu (Manley), Hugh de Vinon, Godfrey de Craucumb, John fil. Philip, Geoffrey dispenser, Henry de Capella. Dated at York by the hand of Ralph (de Nevill), Bishop of Chichester Chancellor.",
"archive": "West Yorkshire Archive Service, Calderdale",
"archiveLocation": "KM/29",
"language": "English",
"libraryCatalog": "The National Archives (UK)",
"attachments": [
{
"title": "Catalog Entry",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/