Skip to content

Instantly share code, notes, and snippets.

@dumbmoron
Last active June 29, 2024 17:35
Show Gist options
  • Save dumbmoron/3fc6c0c747d791928aba939976fd9304 to your computer and use it in GitHub Desktop.
Save dumbmoron/3fc6c0c747d791928aba939976fd9304 to your computer and use it in GitHub Desktop.
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