forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
site-data-tag.js
executable file
·36 lines (30 loc) · 822 Bytes
/
site-data-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
#!/usr/bin/env node
const path = require('path')
const walk = require('walk-sync')
const replace = require('replace')
const FINDER = /{{\s?site\.data\.([a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]+)+)\s*}}/g
const REPLACER = '{% data $1 %}'
async function rewriteFiles (dir) {
const files = walk(dir, { includeBasePath: true })
replace({
regex: FINDER,
replacement: REPLACER,
paths: files,
recursive: true
})
}
async function main () {
const dirs = [
path.join(__dirname, '../../content'),
path.join(__dirname, '../../data'),
path.join(__dirname, '../../translations'),
path.join(__dirname, '../../includes'),
path.join(__dirname, '../../layouts')
]
for (const dir of dirs) {
await rewriteFiles(dir)
}
}
main()
.catch(console.error)
.finally(() => console.log('Done!'))