🐛 adds commit, fixes cron
All checks were successful
Update RSS / update-rss (push) Successful in 5m14s

This commit is contained in:
Jan Andrle 2024-06-27 10:52:51 +02:00
parent 837cea046d
commit 597e21895a
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
2 changed files with 24 additions and 5 deletions

View File

@ -2,7 +2,7 @@ name: Update RSS
on:
workflow_dispatch:
schedule:
- cron: '0 3 * * *' # daily at 3am
- cron: '57 10 * * *' # daily at 10:57
jobs:
update-rss:
@ -14,4 +14,4 @@ jobs:
node-version: lts/*
cache: 'npm'
- run: npm ci
- run: npx nodejsscript cli.js pull
- run: npx nodejsscript cli.mjs pull --git

25
cli.mjs
View File

@ -2,6 +2,10 @@
/* 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 paths= {
sitemap: "sitemap.json",
rss: "rss.xml",
};
/**
* @typedef {Object} Article
* @property {string} title
@ -25,16 +29,31 @@ $.api()
.version(version)
.describe(description)
.command("pull", "Update article list")
.action(async function pull(){
.option("--git", "Update git repository")
.action(async function pull({ git: is_git= false }){
const json= await sitemap();
toRSS(json);
if(is_git)
gitCommit(Object.values(paths));
$.exit(0);
})
.parse();
function gitCommit(files, des= "not specified"){
if(!s.run`git diff --numstat`.trim())
return echo("Nothig todo");
echo("Diff to save");
s.run`git config user.name "Bot"`;
s.run`git config user.email "${"zc.murtnec@naj.elrdna".split("").reverse().join("")}"`;
s.run`git add ${files}`;
s.run`git commit -m "Updated by bot ${des}"`;
s.run`git push`;
s.run`git config --remove-section user`;
}
/** @param {Sitemap} json */
async function toRSS(json){
const path= "rss.xml";
const path= paths.rss;
const host= "https://pagenotfound.cz";
const articles= json.articles.map(function({ title, perex, author, loc, drop }){
return [
@ -64,7 +83,7 @@ async function toRSS(json){
}
import { JSDOM } from "jsdom";
async function sitemap(){
const path= "sitemap.json";
const path= paths.sitemap;
/** @type {Sitemap} */
const json= s.test("-f", path) ? s.cat(path).xargs(JSON.parse) : { drops: [], articles: [] };