news/utils/readme.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-02-13 14:12:54 +01:00
import { addDays, format, nextMonday, setWeek } from "npm:date-fns";
2024-02-13 13:21:19 +01:00
2024-02-13 14:12:54 +01:00
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
2024-02-13 14:27:51 +01:00
let issues = JSON.parse(await Deno.readTextFile("./dist/index.json"));
issues = issues.sort((x, y) => x.period[1] > y.period[1] ? 1 : -1);
2024-02-13 13:21:19 +01:00
2024-02-13 14:12:54 +01:00
const lines = [];
2024-02-13 13:21:19 +01:00
2024-02-13 14:12:54 +01:00
lines.push("| Week | Period | Deadline | Curator | Links |");
lines.push("| --- | --- | --- | --- | --- |");
2024-02-13 13:21:19 +01:00
for (const issue of issues) {
2024-02-13 14:12:54 +01:00
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")
}`,
issue.published
? `✅ [published](https://news.web3privacy.info/${issue.week})`
: format(new Date(issue.period[1]), "MMM d"),
issue.curator || "-",
(issue.published
? (Object.keys(issue.links).map((ln) =>
`[${capitalizeFirstLetter(ln)}](${issue.links[ln]})`
))
: [
`[Edit](https://github.com/web3privacy/news/edit/main/data/${year}/week${week}.md)`,
]).join(", "),
];
lines.push("| " + props.join(" | ") + " |");
2024-02-13 13:21:19 +01:00
}
2024-02-13 14:12:54 +01:00
const out = lines.join("\n");
2024-02-13 13:21:19 +01:00
//console.log(out)
2024-02-13 14:12:54 +01:00
const readmeSrc = await Deno.readTextFile("./README.md");
2024-02-13 13:21:19 +01:00
const readmeOut = readmeSrc.replace(
2024-02-13 14:12:54 +01:00
/<!-- ISSUES-START -->[\s\S]+<!-- ISSUES-END -->/m,
`<!-- ISSUES-START -->\n\n${out}\n\n<!-- ISSUES-END -->`,
);
2024-02-13 13:21:19 +01:00
2024-02-13 14:12:54 +01:00
await Deno.writeTextFile("./README.md", readmeOut);
2024-02-13 13:21:19 +01:00
2024-02-13 14:12:54 +01:00
console.log(`README.md modified. Done.`);