utils update, links in src

This commit is contained in:
tree🌴 2024-02-13 14:12:54 +01:00
parent 4d8a8bb63f
commit 004e7a18db
6 changed files with 146 additions and 103 deletions

View file

@ -16,10 +16,10 @@ You can read more in our [documentation](https://docs.web3privacy.info/news/week
<!-- ISSUES-START --> <!-- ISSUES-START -->
| Week | Period | Deadline | Curator | | Week | Period | Deadline | Curator | Links |
| --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| [2024-07](/data/2024/week07.md) | Feb 12 - Feb 18 | Feb 18 | Mykola | | [2024-07](/data/2024/week07.md) | Feb 12 - Feb 18 | Feb 18 | Mykola | [Edit](https://github.com/web3privacy/news/edit/main/data/2024/week07.md) |
| [2024-06](/data/2024/week06.md) | Feb 5 - Feb 11 | ✅ [published](https://news.web3privacy.info/2024-06) | Tree | | [2024-06](/data/2024/week06.md) | Feb 5 - Feb 11 | ✅ [published](https://news.web3privacy.info/2024-06) | Tree | [Paragraph](https://paragraph.xyz/@privacynews/2024-06), [Mirror](https://mirror.xyz/0x0f1F3DAf416B74DB3DE55Eb4D7513a80F4841073/YeescUmT44QN7Hv4a9L6GuK6LZS0N5VO-4g7NnYHNbo) |
| [2024-05](/data/2024/week05.md) | Jan 29 - Feb 4 | ✅ [published](https://news.web3privacy.info/2024-05) | - | | [2024-05](/data/2024/week05.md) | Jan 29 - Feb 4 | ✅ [published](https://news.web3privacy.info/2024-05) | - | [Paragraph](https://paragraph.xyz/@privacynews/2024-05) |
<!-- ISSUES-END --> <!-- ISSUES-END -->

View file

@ -1,5 +1,7 @@
--- ---
published: https://paragraph.xyz/@privacynews/2024-05 published: true
links:
paragraph: https://paragraph.xyz/@privacynews/2024-05
--- ---
### Research ### Research

View file

@ -1,6 +1,9 @@
--- ---
curator: Tree curator: Tree
published: https://paragraph.xyz/@privacynews/2024-06 published: true
links:
paragraph: https://paragraph.xyz/@privacynews/2024-06
mirror: https://mirror.xyz/0x0f1F3DAf416B74DB3DE55Eb4D7513a80F4841073/YeescUmT44QN7Hv4a9L6GuK6LZS0N5VO-4g7NnYHNbo
--- ---
Welcome to the historical debut - the **first edition** (#1) of [Week In The Privacy News](https://news.web3privacy.info/). Welcome to the historical debut - the **first edition** (#1) of [Week In The Privacy News](https://news.web3privacy.info/).

View file

@ -1,8 +1,8 @@
import { join } from "https://deno.land/std@0.208.0/path/mod.ts"; import { join } from "https://deno.land/std@0.208.0/path/mod.ts";
import { emptyDir } from "https://deno.land/std@0.196.0/fs/empty_dir.ts"; import { emptyDir } from "https://deno.land/std@0.196.0/fs/empty_dir.ts";
import { setWeek, nextMonday, format, addDays } from 'npm:date-fns'; import { addDays, format, nextMonday, setWeek } from "npm:date-fns";
import { marked } from 'npm:marked'; import { marked } from "npm:marked";
import matter from 'npm:front-matter'; import matter from "npm:front-matter";
const SRC_DIR = "./data"; const SRC_DIR = "./data";
const DEST_DIR = "./dist"; const DEST_DIR = "./dist";
@ -19,35 +19,43 @@ async function build() {
console.log(`Processing year: ${year}`); console.log(`Processing year: ${year}`);
for await (const dirEntry of Deno.readDir(yearDir)) { for await (const dirEntry of Deno.readDir(yearDir)) {
const [fn, ext] = dirEntry.name.split("."); const [fn, ext] = dirEntry.name.split(".");
const weekMatch = fn.match(/^week(\d{2})$/) const weekMatch = fn.match(/^week(\d{2})$/);
if (!weekMatch || ext !== "md") { if (!weekMatch || ext !== "md") {
continue; continue;
} }
const week = weekMatch[1] const week = weekMatch[1];
const mdPath = join(SRC_DIR, year, dirEntry.name); const mdPath = join(SRC_DIR, year, dirEntry.name);
const source = await Deno.readTextFile(mdPath); const source = await Deno.readTextFile(mdPath);
const issue = { const issue = {
week: `${year}-${week}`, week: `${year}-${week}`,
period: calcPeriod(year, week), period: calcPeriod(year, week),
} };
await renderData(issue, source) await renderData(issue, source);
issues.push(issue) issues.push(issue);
} }
} }
await emptyDir(DEST_DIR); await emptyDir(DEST_DIR);
const imgDir = join(DEST_DIR, "img") const imgDir = join(DEST_DIR, "img");
await emptyDir(imgDir) await emptyDir(imgDir);
// get images // get images
for (const issue of issues) { for (const issue of issues) {
await genImage(`https://news.web3privacy.info/image/${issue.week}?${new Date().valueOf()}`, join(imgDir, `${issue.week}.png`)) await genImage(
`https://news.web3privacy.info/image/${issue.week}?${
new Date().valueOf()
}`,
join(imgDir, `${issue.week}.png`),
);
} }
// make cover // make cover
await genImage(`https://news.web3privacy.info/cover`, join(imgDir, 'cover.png')) await genImage(
`https://news.web3privacy.info/cover`,
join(imgDir, "cover.png"),
);
const outputFn = join(DEST_DIR, "index.json"); const outputFn = join(DEST_DIR, "index.json");
await writeJSONFile(outputFn, issues); await writeJSONFile(outputFn, issues);
@ -57,7 +65,10 @@ async function renderData(issue, source) {
const fm = matter(source); const fm = matter(source);
const parsed = marked.parse(fm.body); const parsed = marked.parse(fm.body);
return Object.assign(issue, fm.attributes, { newsMd: fm.body, newsHtml: parsed }); return Object.assign(issue, fm.attributes, {
newsMd: fm.body,
newsHtml: parsed,
});
//const fm = matter(issue.source) //const fm = matter(issue.source)
//console.log(fm) //console.log(fm)
@ -66,10 +77,14 @@ async function renderData(issue, source) {
} }
function calcPeriod(year, week) { function calcPeriod(year, week) {
const weekStart = setWeek(nextMonday(new Date(Number(year), 0, 4)), Number(week), { const weekStart = setWeek(
nextMonday(new Date(Number(year), 0, 4)),
Number(week),
{
weekStartsOn: 1, weekStartsOn: 1,
firstWeekContainsDate: 4, firstWeekContainsDate: 4,
}); },
);
const weekEnd = addDays(weekStart, 6); const weekEnd = addDays(weekStart, 6);
return [weekStart, weekEnd]; return [weekStart, weekEnd];
@ -82,13 +97,13 @@ async function writeJSONFile(fn, data) {
async function genImage(url, fn) { async function genImage(url, fn) {
const imgResp = await fetch("https://html2svg.gwei.cz", { const imgResp = await fetch("https://html2svg.gwei.cz", {
method: 'POST', method: "POST",
body: JSON.stringify({ body: JSON.stringify({
url, url,
format: "png", format: "png",
width: 1920, width: 1920,
height: 960, height: 960,
}) }),
}); });
if (imgResp.body) { if (imgResp.body) {

View file

@ -1,33 +1,48 @@
import { setWeek, nextMonday, format, addDays } from 'npm:date-fns'; import { addDays, format, nextMonday, setWeek } from "npm:date-fns";
const issues = JSON.parse(await Deno.readTextFile('./dist/index.json')) function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
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")}`,
issue.published ? `✅ [published](https://news.web3privacy.info/${issue.week})` : format(new Date(issue.period[1]), "MMM d"),
issue.curator || '-'
]
lines.push('| ' + props.join(' | ') + ' |')
} }
const out = lines.join("\n") const issues = JSON.parse(await Deno.readTextFile("./dist/index.json"));
const lines = [];
lines.push("| Week | Period | Deadline | Curator | Links |");
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")
}`,
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(" | ") + " |");
}
const out = lines.join("\n");
//console.log(out) //console.log(out)
const readmeSrc = await Deno.readTextFile('./README.md') const readmeSrc = await Deno.readTextFile("./README.md");
const readmeOut = readmeSrc.replace( const readmeOut = readmeSrc.replace(
/<!-- ISSUES-START -->[\s\S]+<!-- ISSUES-END -->/m, /<!-- ISSUES-START -->[\s\S]+<!-- ISSUES-END -->/m,
`<!-- ISSUES-START -->\n\n${out}\n\n<!-- ISSUES-END -->` `<!-- ISSUES-START -->\n\n${out}\n\n<!-- ISSUES-END -->`,
) );
await Deno.writeTextFile('./README.md', readmeOut) await Deno.writeTextFile("./README.md", readmeOut);
console.log(`README.md modified. Done.`) console.log(`README.md modified. Done.`);

View file

@ -6,6 +6,10 @@ import config from '../config.yaml';
const [ year, week ] = issue.week.split('-'); const [ year, week ] = issue.week.split('-');
const current = false; const current = false;
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
--- ---
@ -22,7 +26,11 @@ const current = false;
<div class="grow"></div> <div class="grow"></div>
<div class="mt-2 sm:mt-0 flex gap-4 items-center"> <div class="mt-2 sm:mt-0 flex gap-4 items-center">
{issue.published && {issue.published &&
<a href={issue.published}>Paragraph</a> <div class="flex gap-4">
{Object.keys(issue.links).map((lk) =>
<a href={issue.links[lk]}>{capitalizeFirstLetter(lk)}</a>
)}
</div>
<a href=`https://github.com/web3privacy/news/blob/main/data/${year}/week${week}.md`>Source</a> <a href=`https://github.com/web3privacy/news/blob/main/data/${year}/week${week}.md`>Source</a>
} }
{!issue.published && {!issue.published &&