Last active
November 13, 2018 10:36
-
-
Save paazmaya/4b278ce7f96464ba19e63fa0470b15ae to your computer and use it in GitHub Desktop.
Split single markdown file (list of sprints) to several (one for each sprint)
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
| const fs = require('fs'); | |
| const MATCH_SPRINT = /^## Sprint (\d+):[\S\s]+?demo<\/a>/ugm; | |
| const HEADER_LEVEL = /^##/ugm; | |
| const SUFFIX = /\.md$/; | |
| const original = fs.readFileSync('sprints-2018.md', 'utf8'); | |
| console.log(`Original file has ${original.length} lines`); | |
| const index = []; | |
| let list; | |
| while ((list = MATCH_SPRINT.exec(original)) !== null) { | |
| console.log(list[1]); | |
| const filename = `sprints/sprint-${String(list[1]).trim()}.md`; | |
| const data = list[0].replace(HEADER_LEVEL, '#'); | |
| fs.writeFileSync(filename, data, 'utf8'); | |
| index.push(`* [Sprint ${list[1]}](${filename.replace(SUFFIX, '')})`); | |
| } | |
| const content = `# Sprints | |
| ${index.join('\n')} | |
| `; | |
| fs.writeFileSync('sprints.md', content, 'utf8'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment