forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
octicon-tag.js
executable file
·40 lines (35 loc) · 929 Bytes
/
octicon-tag.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
#!/usr/bin/env node
import { fileURLToPath } from 'url'
import path from 'path'
import walk from 'walk-sync'
import replace from 'replace'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const FINDER = /{{\s?octicon-([a-z-]+)(\s[\w\s\d-]+)?\s?}}/g
async function rewriteFiles(dir) {
const files = walk(dir, { includeBasePath: true })
replace({
regex: FINDER,
replacement: (match, p1, p2) => {
if (p2) {
return `{% octicon "${p1}" aria-label="${p2.trim()}" %}`
} else {
return `{% octicon "${p1}" %}`
}
},
paths: files,
recursive: true,
})
}
async function main() {
const dirs = [
path.join(__dirname, '../../content'),
path.join(__dirname, '../../data'),
path.join(__dirname, '../../translations'),
]
for (const dir of dirs) {
await rewriteFiles(dir)
}
}
main()
.catch(console.error)
.finally(() => console.log('Done!'))