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 -->
| 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) |
<!-- 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

View file

@ -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/).

View file

@ -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();

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'))
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(
/<!-- ISSUES-START -->[\s\S]+<!-- ISSUES-END -->/m,
`<!-- ISSUES-START -->\n\n${out}\n\n<!-- ISSUES-END -->`
)
/<!-- ISSUES-START -->[\s\S]+<!-- ISSUES-END -->/m,
`<!-- 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 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="mt-2 sm:mt-0 flex gap-4 items-center">
{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>
}
{!issue.published &&