-
-
Save dumbmoron/3fc6c0c747d791928aba939976fd9304 to your computer and use it in GitHub Desktop.
This file contains 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
import { readFile, writeFile } from 'node:fs/promises'; | |
const oldLogs = JSON.parse(await readFile('./changelog.json')); | |
const allLogs = [ oldLogs.current, ...oldLogs.history ]; | |
const generateFrontmatter = (log) => { | |
let frontmatter = []; | |
frontmatter.push( | |
`title: ${JSON.stringify(log.title)}` | |
); | |
if (log.date) { | |
frontmatter.push( | |
`date: ${JSON.stringify(log.date)}`, | |
); | |
} | |
if (log.banner) { | |
let banner = []; | |
banner.push( | |
`file: ${JSON.stringify(log.banner.file)}`, | |
`alt: ${JSON.stringify(log.banner.alt)}` | |
); | |
frontmatter.push( | |
'banner:', | |
...banner.map(a => ' '.repeat(4) + a) | |
); | |
} | |
return [ | |
'---', | |
...frontmatter, | |
'---', | |
'' | |
].join('\n'); | |
} | |
const reformatContent = (content) => { | |
return content | |
.replace(/\n(?!\n)/g, '\n') | |
.replace(/\*;/g, '-'); | |
} | |
for (const changelog of allLogs) { | |
let md = ''; | |
console.log(changelog) | |
md += generateFrontmatter(changelog); | |
md += reformatContent(changelog.content); | |
await writeFile(`${changelog.version}.md`, md); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment