-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetPageInfo.js
55 lines (46 loc) · 1.61 KB
/
GetPageInfo.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
let table = base.getTable('Core Site Indexed Content');
let result = await table.selectRecordsAsync({
fields: ['URL', 'Meta Title', 'H1 Title'],
});
function getH1Title(htmlAsText) {
let h1StartingLocation = htmlAsText.indexOf('<h1');
let h1TagEndLocation =
htmlAsText.substring(h1StartingLocation).indexOf('>') + h1StartingLocation;
let h1CloseLocation =
htmlAsText.substring(h1TagEndLocation).indexOf('</h1') + h1TagEndLocation;
return htmlAsText.substring(h1TagEndLocation + 1, h1CloseLocation);
}
function getMetaTitle(htmlAsText) {
let titleStartingLocation = htmlAsText.indexOf('<title>');
let titleTagClosingLocation = htmlAsText.indexOf('>', titleStartingLocation);
let titleCloseLocation = htmlAsText.indexOf(
'</title',
titleTagClosingLocation,
);
return htmlAsText.substring(titleTagClosingLocation + 1, titleCloseLocation);
}
function GEtMetaDescription(htmlAsText) {}
let records = result.records;
for (let record of records.filter((r) => r.getCellValue('URL'))) {
try {
let h1Title = record.getCellValue('H1 Title');
if (!record.getCellValue('H1 Title')) {
console.log('H1 title empty');
let response = await remoteFetchAsync(record.getCellValue('URL'));
if (response.ok) {
let promise = response.text();
let html = await promise.then((text) => {
return text;
});
let h1Title = getH1Title(html);
let metaTitle = getMetaTitle(html);
table.updateRecordAsync(record, {
'H1 Title': h1Title,
'Meta Title': metaTitle,
});
}
}
} catch {
console.log('oh no');
}
}