#!/usr/bin/env nodejsscript /* jshint esversion: 11,-W097, -W040, module: true, node: true, expr: true, undef: true *//* global echo, $, pipe, s, fetch, cyclicLoop */ /** * @typedef T_RSSITEM * @type {{ title: string, link: string, date: string }} * */ /** * @param {string} title * @param {string} url * @param {(response: string)=> T_RSSITEM[]} parseItems * @returns {Promise} * */ export function html2rss(title, url, parseItems){ return fetch(url) .then(response=> response.text()) .then(pipe( parseItems, toRSS )); function toRSS(items){ const articles_rss= items.map(function({ title, date, link }){ return [ "", ""+title+"", ""+link+"", ""+date+"", "" ].join("\n"); }); return [ ``, ``, "", `${title}`, `${url}`, ...articles_rss, "", "" ].join("\n"); } }