news/utils
2024-02-13 13:21:19 +01:00
..
build.js update 2024-02-12 15:25:43 +01:00
readme.js readme generator 2024-02-13 13:21:19 +01:00

import { setWeek, nextMonday, format, addDays } from 'npm:date-fns';

const issues = JSON.parse(await Deno.readTextFile('./dist/index.json'))

const lines = []

lines.push('| Week | Period | Deadline | Curator |')
lines.push('| --- | --- | --- | --- |')

for (const issue of issues) {
    const [ year, week ] = issue.week.split('-')
    const props = [
        `[${issue.week}](/data/${year}/week${week}.md)`,
        `${format(new Date(issue.period[0]), "MMM d")} - ${format(new Date(issue.period[1]), "MMM d, yyyy")}`,
        issue.published ? '✅ published' : format(new Date(issue.period[1]), "MMM d"),
        issue.curator || '-'
    ]

    lines.push('| ' + props.join(' | ') + ' |')
}

const out = lines.join("\n")
//console.log(out)

const readmeSrc = await Deno.readTextFile('./README.md')
const readmeOut = readmeSrc.replace(
    /<!-- ISSUES-START -->[\s\S]+<!-- ISSUES-END -->/m,
    `<!-- ISSUES-START -->\n\n${out}\n\n<!-- ISSUES-END -->`
)

await Deno.writeTextFile('./README.md', readmeOut)

console.log(`README.md modified. Done.`)