mirror of
https://github.com/web3privacy/news.git
synced 2024-10-15 18:06:26 +02:00
utils update, links in src
This commit is contained in:
parent
4d8a8bb63f
commit
004e7a18db
6 changed files with 146 additions and 103 deletions
10
README.md
10
README.md
|
@ -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 -->
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
---
|
---
|
||||||
published: https://paragraph.xyz/@privacynews/2024-05
|
published: true
|
||||||
|
links:
|
||||||
|
paragraph: https://paragraph.xyz/@privacynews/2024-05
|
||||||
---
|
---
|
||||||
|
|
||||||
### Research
|
### Research
|
||||||
|
|
|
@ -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/).
|
||||||
|
|
155
utils/build.js
155
utils/build.js
|
@ -1,100 +1,115 @@
|
||||||
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";
|
||||||
|
|
||||||
async function build() {
|
async function build() {
|
||||||
let issues = [];
|
let issues = [];
|
||||||
for await (const dirEntry of Deno.readDir(SRC_DIR)) {
|
for await (const dirEntry of Deno.readDir(SRC_DIR)) {
|
||||||
if (!dirEntry.isDirectory || !dirEntry.name.match(/^\d{4}$/)) {
|
if (!dirEntry.isDirectory || !dirEntry.name.match(/^\d{4}$/)) {
|
||||||
continue;
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//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 issue = {
|
||||||
const imgDir = join(DEST_DIR, "img")
|
week: `${year}-${week}`,
|
||||||
await emptyDir(imgDir)
|
period: calcPeriod(year, week),
|
||||||
|
};
|
||||||
|
|
||||||
// get images
|
await renderData(issue, source);
|
||||||
for (const issue of issues) {
|
issues.push(issue);
|
||||||
await genImage(`https://news.web3privacy.info/image/${issue.week}?${new Date().valueOf()}`, join(imgDir, `${issue.week}.png`))
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// make cover
|
await emptyDir(DEST_DIR);
|
||||||
await genImage(`https://news.web3privacy.info/cover`, join(imgDir, 'cover.png'))
|
const imgDir = join(DEST_DIR, "img");
|
||||||
|
await emptyDir(imgDir);
|
||||||
|
|
||||||
const outputFn = join(DEST_DIR, "index.json");
|
// get images
|
||||||
await writeJSONFile(outputFn, issues);
|
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) {
|
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)
|
||||||
//console.log(parsed)
|
//console.log(parsed)
|
||||||
//return
|
//return
|
||||||
}
|
}
|
||||||
|
|
||||||
function calcPeriod(year, week) {
|
function calcPeriod(year, week) {
|
||||||
const weekStart = setWeek(nextMonday(new Date(Number(year), 0, 4)), Number(week), {
|
const weekStart = setWeek(
|
||||||
weekStartsOn: 1,
|
nextMonday(new Date(Number(year), 0, 4)),
|
||||||
firstWeekContainsDate: 4,
|
Number(week),
|
||||||
});
|
{
|
||||||
const weekEnd = addDays(weekStart, 6);
|
weekStartsOn: 1,
|
||||||
|
firstWeekContainsDate: 4,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const weekEnd = addDays(weekStart, 6);
|
||||||
|
|
||||||
return [ weekStart, weekEnd ];
|
return [weekStart, weekEnd];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writeJSONFile(fn, data) {
|
async function writeJSONFile(fn, data) {
|
||||||
console.log(`File written: ${fn}`);
|
console.log(`File written: ${fn}`);
|
||||||
return Deno.writeTextFile(fn, JSON.stringify(data, null, 2));
|
return Deno.writeTextFile(fn, JSON.stringify(data, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
const file = await Deno.open(fn, { write: true, create: true });
|
const file = await Deno.open(fn, { write: true, create: true });
|
||||||
await imgResp.body.pipeTo(file.writable);
|
await imgResp.body.pipeTo(file.writable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
build();
|
build();
|
||||||
|
|
|
@ -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.`);
|
||||||
|
|
|
@ -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 &&
|
||||||
|
|
Loading…
Reference in a new issue