1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/script/content-migrations/octicon-tag.js
Vanessa Yuen 3df90fc9b8 Hello git history spelunker!
Are you looking for something? Here is all of the GitHub Docs history in one single commit. Enjoy! 🎉
2020-09-27 14:10:11 +02:00

40 lines
846 B
JavaScript
Executable File

#!/usr/bin/env node
const path = require('path')
const walk = require('walk-sync')
const replace = require('replace')
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!'))