-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
56 lines (47 loc) · 1.33 KB
/
build.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
import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import fetch from 'node-fetch'
import {fromHtml} from 'hast-util-from-html'
import {select, selectAll} from 'hast-util-select'
import {toString} from 'hast-util-to-string'
const response = await fetch(
'https://microformats.org/wiki/existing-rel-values'
)
const text = await response.text()
const tree = fromHtml(text)
const value = table('formats').concat(table('HTML5_link_type_extensions'))
if (value.length === 0) {
throw new Error('Couldn’t find any rels')
}
await fs.writeFile(
'index.js',
[
'/**',
' * List of values for `rel` on `<a>` and `<area>` elements according to',
' * Microformats.',
' *',
' * @type {Array<string>}',
' */',
'export const aRel = ' + JSON.stringify(value.sort(), null, 2),
''
].join('\n')
)
/**
* @param {string} name
*/
function table(name) {
const node = select('h2:has(#' + name + ') ~ table', tree)
assert(node, 'expected table to exist for `' + name + '`')
const rows = selectAll('tr', node).slice(1)
let index = -1
/** @type {Array<string>} */
const result = []
while (++index < rows.length) {
const cells = selectAll('td', rows[index])
if (/not allowed/i.test(toString(cells[2]).trim())) {
continue
}
result.push(toString(cells[0]).trim())
}
return result
}