-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
37 lines (32 loc) · 909 Bytes
/
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
import fs from 'node:fs/promises'
import fetch from 'node-fetch'
import {fromHtml} from 'hast-util-from-html'
import {selectAll} from 'hast-util-select'
import {toString} from 'hast-util-to-string'
import {htmlLinkTypes} from './index.js'
const response = await fetch(
'https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types'
)
const text = await response.text()
const tree = fromHtml(text)
const nodes = selectAll('.standard-table td:first-child code', tree)
let index = -1
while (++index < nodes.length) {
const data = toString(nodes[index])
if (data && !htmlLinkTypes.includes(data)) {
htmlLinkTypes.push(data)
}
}
await fs.writeFile(
'index.js',
[
'/**',
' * List of link types as specified by HTML.',
' *',
' * @type {Array<string>}',
' */',
'export const htmlLinkTypes = ' +
JSON.stringify(htmlLinkTypes.sort(), null, 2),
''
].join('\n')
)