🐛 improved to fulfill the validator
All checks were successful
Update RSS / update-rss (push) Successful in 5m14s

see https://validator.w3.org/feed/check.cgi?url=https%3A%2F%2Fgitea.jaandrle.cz%2Fjaandrle%2Fpagenotfound-cli%2Fraw%2Fbranch%2Fmain%2Frss.xml
This commit is contained in:
2024-07-11 15:51:28 +02:00
parent a576caff53
commit 71acab3ce5
5 changed files with 191 additions and 119 deletions

33
cli.mjs
View File

@ -1,7 +1,7 @@
#!/usr/bin/env -S npx nodejsscript
/* jshint esversion: 11,-W097, -W040, module: true, node: true, expr: true, undef: true *//* global echo, $, pipe, s, fetch, cyclicLoop */
const url_drops= "https://pagenotfound.cz/drop/";
const { version, description }= s.cat("package.json").xargs(JSON.parse);
const { version, description, homepage }= s.cat("package.json").xargs(JSON.parse);
/**
* @typedef {Object} Article
* @property {string} title
@ -25,6 +25,21 @@ const { version, description }= s.cat("package.json").xargs(JSON.parse);
* @property {Sitemap} json
* @property {string[]} changed Changed files
* */
const pubDate= (function pubDateInner(){ // pubDate must be an RFC-822 date-time
const intl= new Intl.DateTimeFormat("en-gb", {
/* Wed, 02 Oct 2002 */ weekday: "short", day: "2-digit", month: "short", year: "numeric",
/* 08:00:00 */ hour12: false, hour: "2-digit", minute: "2-digit", second: "2-digit",
/* EST */ timeZoneName: "longOffset", timeZone: "UTC",
});
/** @param {string} date */
return date=> {
const D= new Date(date);
const d= intl.format(D);
// remove redundant second comma to make it RFC-822
const red_comma_i= d.indexOf(",", d.indexOf(",")+1);
return d.slice(0, red_comma_i) + d.slice(red_comma_i+1);
};
})();
$.api()
.version(version)
@ -67,21 +82,31 @@ async function toRSS({ json, changed }){
...[
`<title>${title}</title>`,
`<link>${host+loc}</link>`,
`<guid>${host+loc}</guid>`,
`<description>${perex}</description>`,
`<author>${author}</author>`,
`<pubDate>${json.drops.find(d=> d.drop === drop).date}</pubDate>`,
`<dc:creator>${author}</dc:creator>`,
`<pubDate>${pubDate(json.drops.find(d=> d.drop === drop).date)}</pubDate>`,
`<category>${drop}</category>`,
].map(l=> "\t"+l),
"</item>"
].map(l=> "\t"+l).join("\n");
});
const description = [
"Page not found jsme založili z touhy po zábavné, kvalitní a inovativní žurnalistice.",
"Chceme vám tu nabízet komplexní long ready, nečekané bonusy, multimediální obsah",
"a hlavně texty, které nám samotným v ostatních médiích chybí. Budujte spolu s námi",
"komunitu Page not found, dejte nám zpětnou vazbu na první drop, přihlaste se",
"k odebírání newsletterů. Společně s vámi budeme moct naše cíle plnit rychleji."
].join(" ");
s.echo([
`<?xml version="1.0" encoding="UTF-8" ?>`,
`<rss version="2.0">`,
`<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">`,
"<channel>",
` <title>Pagenotfound.cz</title>`,
` <link>${host}</link>`,
` <description>${description}</description>`,
` <atom:link href="${homepage}/raw/branch/main/rss.xml" rel="self" type="application/rss+xml" />`,
...articles,
"</channel>",
"</rss>"