Created
July 18, 2023 20:02
-
-
Save agritheory/2b7958caf3e39e7e4acfb1b1b1641d99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// excerpt from package.json | |
// "remark": "^14.0.2", | |
// "remark-link-rewrite": "^1.0.6", | |
// "shelljs": "^0.8.5", | |
function update_urls(folder, repo){ | |
console.log('Update URLs', folder, repo) | |
shelljs.ls(`${folder}*.md`).forEach(file => { | |
readFile(file, (err, fileContent)=>{ | |
remark() | |
.use(RemarkLinkRewrite, { | |
replacer: (url) => { | |
if (url.startsWith('./assets')) { | |
return url.replace('./assets', `/documentation/${repo}/assets`) | |
} | |
return url | |
} | |
}) | |
.process(fileContent) | |
.then(({ value }) => { | |
writeFile(file, value, (err) => { if (err) throw err }) | |
}) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment