From 004e7a18dbc6bbcf14397a54c953d169d05d7c64 Mon Sep 17 00:00:00 2001 From: tree Date: Tue, 13 Feb 2024 14:12:54 +0100 Subject: [PATCH] utils update, links in src --- README.md | 10 +- data/2024/week05.md | 4 +- data/2024/week06.md | 5 +- utils/build.js | 155 ++++++++++++++++-------------- utils/readme.js | 65 ++++++++----- web/src/components/WeekNews.astro | 10 +- 6 files changed, 146 insertions(+), 103 deletions(-) diff --git a/README.md b/README.md index 662ba8d..75c4e91 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,10 @@ You can read more in our [documentation](https://docs.web3privacy.info/news/week -| Week | Period | Deadline | Curator | -| --- | --- | --- | --- | -| [2024-07](/data/2024/week07.md) | Feb 12 - Feb 18 | Feb 18 | Mykola | -| [2024-06](/data/2024/week06.md) | Feb 5 - Feb 11 | ✅ [published](https://news.web3privacy.info/2024-06) | Tree | -| [2024-05](/data/2024/week05.md) | Jan 29 - Feb 4 | ✅ [published](https://news.web3privacy.info/2024-05) | - | +| Week | Period | Deadline | Curator | Links | +| --- | --- | --- | --- | --- | +| [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 | [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) | - | [Paragraph](https://paragraph.xyz/@privacynews/2024-05) | diff --git a/data/2024/week05.md b/data/2024/week05.md index 5e8135c..ba14e1a 100644 --- a/data/2024/week05.md +++ b/data/2024/week05.md @@ -1,5 +1,7 @@ --- -published: https://paragraph.xyz/@privacynews/2024-05 +published: true +links: + paragraph: https://paragraph.xyz/@privacynews/2024-05 --- ### Research diff --git a/data/2024/week06.md b/data/2024/week06.md index 9d907b9..bdc1530 100644 --- a/data/2024/week06.md +++ b/data/2024/week06.md @@ -1,6 +1,9 @@ --- 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/). diff --git a/utils/build.js b/utils/build.js index 9fc8a79..ae1bf94 100644 --- a/utils/build.js +++ b/utils/build.js @@ -1,100 +1,115 @@ 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 { setWeek, nextMonday, format, addDays } from 'npm:date-fns'; -import { marked } from 'npm:marked'; -import matter from 'npm:front-matter'; +import { addDays, format, nextMonday, setWeek } from "npm:date-fns"; +import { marked } from "npm:marked"; +import matter from "npm:front-matter"; const SRC_DIR = "./data"; const DEST_DIR = "./dist"; async function build() { - let issues = []; - for await (const dirEntry of Deno.readDir(SRC_DIR)) { - if (!dirEntry.isDirectory || !dirEntry.name.match(/^\d{4}$/)) { - continue; - } - //const [fn, ext] = dirEntry.name.split("."); - const year = dirEntry.name; - const yearDir = join(SRC_DIR, year); - console.log(`Processing year: ${year}`); - for await (const dirEntry of Deno.readDir(yearDir)) { - const [fn, ext] = dirEntry.name.split("."); - const weekMatch = fn.match(/^week(\d{2})$/) - if (!weekMatch || ext !== "md") { - continue; - } - const week = weekMatch[1] - const mdPath = join(SRC_DIR, year, dirEntry.name); - const source = await Deno.readTextFile(mdPath); - - const issue = { - week: `${year}-${week}`, - period: calcPeriod(year, week), - } - - await renderData(issue, source) - issues.push(issue) - } + let issues = []; + for await (const dirEntry of Deno.readDir(SRC_DIR)) { + if (!dirEntry.isDirectory || !dirEntry.name.match(/^\d{4}$/)) { + continue; } + //const [fn, ext] = dirEntry.name.split("."); + const year = dirEntry.name; + const yearDir = join(SRC_DIR, year); + console.log(`Processing year: ${year}`); + for await (const dirEntry of Deno.readDir(yearDir)) { + const [fn, ext] = dirEntry.name.split("."); + const weekMatch = fn.match(/^week(\d{2})$/); + if (!weekMatch || ext !== "md") { + continue; + } + const week = weekMatch[1]; + const mdPath = join(SRC_DIR, year, dirEntry.name); + const source = await Deno.readTextFile(mdPath); - await emptyDir(DEST_DIR); - const imgDir = join(DEST_DIR, "img") - await emptyDir(imgDir) + const issue = { + week: `${year}-${week}`, + period: calcPeriod(year, week), + }; - // get images - for (const issue of issues) { - await genImage(`https://news.web3privacy.info/image/${issue.week}?${new Date().valueOf()}`, join(imgDir, `${issue.week}.png`)) + await renderData(issue, source); + issues.push(issue); } + } - // make cover - await genImage(`https://news.web3privacy.info/cover`, join(imgDir, 'cover.png')) + await emptyDir(DEST_DIR); + const imgDir = join(DEST_DIR, "img"); + await emptyDir(imgDir); - const outputFn = join(DEST_DIR, "index.json"); - await writeJSONFile(outputFn, issues); + // get images + for (const issue of issues) { + await genImage( + `https://news.web3privacy.info/image/${issue.week}?${ + new Date().valueOf() + }`, + join(imgDir, `${issue.week}.png`), + ); + } + + // make cover + await genImage( + `https://news.web3privacy.info/cover`, + join(imgDir, "cover.png"), + ); + + const outputFn = join(DEST_DIR, "index.json"); + await writeJSONFile(outputFn, issues); } async function renderData(issue, source) { - const fm = matter(source); + const fm = matter(source); - const parsed = marked.parse(fm.body); - return Object.assign(issue, fm.attributes, { newsMd: fm.body, newsHtml: parsed }); + const parsed = marked.parse(fm.body); + return Object.assign(issue, fm.attributes, { + newsMd: fm.body, + newsHtml: parsed, + }); - //const fm = matter(issue.source) - //console.log(fm) - //console.log(parsed) - //return + //const fm = matter(issue.source) + //console.log(fm) + //console.log(parsed) + //return } function calcPeriod(year, week) { - const weekStart = setWeek(nextMonday(new Date(Number(year), 0, 4)), Number(week), { - weekStartsOn: 1, - firstWeekContainsDate: 4, - }); - const weekEnd = addDays(weekStart, 6); + const weekStart = setWeek( + nextMonday(new Date(Number(year), 0, 4)), + Number(week), + { + weekStartsOn: 1, + firstWeekContainsDate: 4, + }, + ); + const weekEnd = addDays(weekStart, 6); - return [ weekStart, weekEnd ]; -} + return [weekStart, weekEnd]; +} async function writeJSONFile(fn, data) { - console.log(`File written: ${fn}`); - return Deno.writeTextFile(fn, JSON.stringify(data, null, 2)); + console.log(`File written: ${fn}`); + return Deno.writeTextFile(fn, JSON.stringify(data, null, 2)); } async function genImage(url, fn) { - const imgResp = await fetch("https://html2svg.gwei.cz", { - method: 'POST', - body: JSON.stringify({ - url, - format: "png", - width: 1920, - height: 960, - }) - }); + const imgResp = await fetch("https://html2svg.gwei.cz", { + method: "POST", + body: JSON.stringify({ + url, + format: "png", + width: 1920, + height: 960, + }), + }); - if (imgResp.body) { - const file = await Deno.open(fn, { write: true, create: true }); - await imgResp.body.pipeTo(file.writable); - } + if (imgResp.body) { + const file = await Deno.open(fn, { write: true, create: true }); + await imgResp.body.pipeTo(file.writable); + } } -build(); \ No newline at end of file +build(); diff --git a/utils/readme.js b/utils/readme.js index ee54199..e4afddf 100644 --- a/utils/readme.js +++ b/utils/readme.js @@ -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')) - -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(' | ') + ' |') +function capitalizeFirstLetter(string) { + return string.charAt(0).toUpperCase() + string.slice(1); } -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) -const readmeSrc = await Deno.readTextFile('./README.md') +const readmeSrc = await Deno.readTextFile("./README.md"); const readmeOut = readmeSrc.replace( - /[\s\S]+/m, - `\n\n${out}\n\n` -) + /[\s\S]+/m, + `\n\n${out}\n\n`, +); -await Deno.writeTextFile('./README.md', readmeOut) +await Deno.writeTextFile("./README.md", readmeOut); -console.log(`README.md modified. Done.`) \ No newline at end of file +console.log(`README.md modified. Done.`); diff --git a/web/src/components/WeekNews.astro b/web/src/components/WeekNews.astro index d8f53db..8169896 100644 --- a/web/src/components/WeekNews.astro +++ b/web/src/components/WeekNews.astro @@ -6,6 +6,10 @@ import config from '../config.yaml'; const [ year, week ] = issue.week.split('-'); const current = false; +function capitalizeFirstLetter(string) { + return string.charAt(0).toUpperCase() + string.slice(1); +} + --- @@ -22,7 +26,11 @@ const current = false;
{issue.published && - Paragraph +
+ {Object.keys(issue.links).map((lk) => + {capitalizeFirstLetter(lk)} + )} +
Source } {!issue.published &&