🐛 ⚡ adds commit, fixes cron
All checks were successful
Update RSS / update-rss (push) Successful in 5m14s
All checks were successful
Update RSS / update-rss (push) Successful in 5m14s
This commit is contained in:
parent
837cea046d
commit
597e21895a
@ -2,7 +2,7 @@ name: Update RSS
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 3 * * *' # daily at 3am
|
- cron: '57 10 * * *' # daily at 10:57
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update-rss:
|
update-rss:
|
||||||
@ -14,4 +14,4 @@ jobs:
|
|||||||
node-version: lts/*
|
node-version: lts/*
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npx nodejsscript cli.js pull
|
- run: npx nodejsscript cli.mjs pull --git
|
||||||
|
25
cli.mjs
25
cli.mjs
@ -2,6 +2,10 @@
|
|||||||
/* jshint esversion: 11,-W097, -W040, module: true, node: true, expr: true, undef: true *//* global echo, $, pipe, s, fetch, cyclicLoop */
|
/* 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 url_drops= "https://pagenotfound.cz/drop/";
|
||||||
const { version, description }= s.cat("package.json").xargs(JSON.parse);
|
const { version, description }= s.cat("package.json").xargs(JSON.parse);
|
||||||
|
const paths= {
|
||||||
|
sitemap: "sitemap.json",
|
||||||
|
rss: "rss.xml",
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Article
|
* @typedef {Object} Article
|
||||||
* @property {string} title
|
* @property {string} title
|
||||||
@ -25,16 +29,31 @@ $.api()
|
|||||||
.version(version)
|
.version(version)
|
||||||
.describe(description)
|
.describe(description)
|
||||||
.command("pull", "Update article list")
|
.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();
|
const json= await sitemap();
|
||||||
toRSS(json);
|
toRSS(json);
|
||||||
|
if(is_git)
|
||||||
|
gitCommit(Object.values(paths));
|
||||||
$.exit(0);
|
$.exit(0);
|
||||||
})
|
})
|
||||||
.parse();
|
.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 */
|
/** @param {Sitemap} json */
|
||||||
async function toRSS(json){
|
async function toRSS(json){
|
||||||
const path= "rss.xml";
|
const path= paths.rss;
|
||||||
const host= "https://pagenotfound.cz";
|
const host= "https://pagenotfound.cz";
|
||||||
const articles= json.articles.map(function({ title, perex, author, loc, drop }){
|
const articles= json.articles.map(function({ title, perex, author, loc, drop }){
|
||||||
return [
|
return [
|
||||||
@ -64,7 +83,7 @@ async function toRSS(json){
|
|||||||
}
|
}
|
||||||
import { JSDOM } from "jsdom";
|
import { JSDOM } from "jsdom";
|
||||||
async function sitemap(){
|
async function sitemap(){
|
||||||
const path= "sitemap.json";
|
const path= paths.sitemap;
|
||||||
|
|
||||||
/** @type {Sitemap} */
|
/** @type {Sitemap} */
|
||||||
const json= s.test("-f", path) ? s.cat(path).xargs(JSON.parse) : { drops: [], articles: [] };
|
const json= s.test("-f", path) ? s.cat(path).xargs(JSON.parse) : { drops: [], articles: [] };
|
||||||
|
Loading…
Reference in New Issue
Block a user