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 -->
|
||||
|
||||
| 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 -->
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
---
|
||||
published: https://paragraph.xyz/@privacynews/2024-05
|
||||
published: true
|
||||
links:
|
||||
paragraph: https://paragraph.xyz/@privacynews/2024-05
|
||||
---
|
||||
|
||||
### Research
|
||||
|
|
|
@ -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/).
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
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";
|
||||
|
@ -19,35 +19,43 @@ async function build() {
|
|||
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})$/)
|
||||
const weekMatch = fn.match(/^week(\d{2})$/);
|
||||
if (!weekMatch || ext !== "md") {
|
||||
continue;
|
||||
}
|
||||
const week = weekMatch[1]
|
||||
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)
|
||||
await renderData(issue, source);
|
||||
issues.push(issue);
|
||||
}
|
||||
}
|
||||
|
||||
await emptyDir(DEST_DIR);
|
||||
const imgDir = join(DEST_DIR, "img")
|
||||
await emptyDir(imgDir)
|
||||
const imgDir = join(DEST_DIR, "img");
|
||||
await emptyDir(imgDir);
|
||||
|
||||
// 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 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'))
|
||||
await genImage(
|
||||
`https://news.web3privacy.info/cover`,
|
||||
join(imgDir, "cover.png"),
|
||||
);
|
||||
|
||||
const outputFn = join(DEST_DIR, "index.json");
|
||||
await writeJSONFile(outputFn, issues);
|
||||
|
@ -57,7 +65,10 @@ async function renderData(issue, source) {
|
|||
const fm = matter(source);
|
||||
|
||||
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)
|
||||
//console.log(fm)
|
||||
|
@ -66,10 +77,14 @@ async function renderData(issue, source) {
|
|||
}
|
||||
|
||||
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,
|
||||
firstWeekContainsDate: 4,
|
||||
});
|
||||
},
|
||||
);
|
||||
const weekEnd = addDays(weekStart, 6);
|
||||
|
||||
return [weekStart, weekEnd];
|
||||
|
@ -82,13 +97,13 @@ async function writeJSONFile(fn, data) {
|
|||
|
||||
async function genImage(url, fn) {
|
||||
const imgResp = await fetch("https://html2svg.gwei.cz", {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
url,
|
||||
format: "png",
|
||||
width: 1920,
|
||||
height: 960,
|
||||
})
|
||||
}),
|
||||
});
|
||||
|
||||
if (imgResp.body) {
|
||||
|
|
|
@ -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 -->\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 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 &&
|
||||
|
|
Loading…
Reference in a new issue