From 889022d7dd77fc063707b520bf9783bb11b7f92e Mon Sep 17 00:00:00 2001 From: bugsounet Date: Tue, 7 Nov 2023 01:20:17 +0100 Subject: [PATCH 1/2] Use `html-to-text` instead of regex for transform description --- CHANGELOG.md | 1 + modules/default/newsfeed/newsfeedfetcher.js | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7be7d3d059..58acb9cd23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ _This release is scheduled to be released on 2024-01-01._ ### Updated - Update electron to v27 and update other dependencies as well as github actions +- Update newsfeed: Use `html-to-text` instead of regex for transform description ### Fixed diff --git a/modules/default/newsfeed/newsfeedfetcher.js b/modules/default/newsfeed/newsfeedfetcher.js index 0f1b5d6c6d..0cedc5257c 100644 --- a/modules/default/newsfeed/newsfeedfetcher.js +++ b/modules/default/newsfeed/newsfeedfetcher.js @@ -52,10 +52,22 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings const url = item.url || item.link || ""; if (title && pubdate) { - const regex = /(<([^>]+)>)/gi; - description = description.toString().replace(regex, ""); + Log.log("---"); + Log.log("newsfeed -- Feed: ", description); + // const regex = /(<([^>]+)>)/gi; + // description = description.toString().replace(regex, " "); // Convert HTML entities, codes and tag - description = htmlToText(description, { wordwrap: false }); + + description = htmlToText(description, { + wordwrap: false, + selectors: [ + { selector: "a", options: { ignoreHref: true, noAnchorUrl: true } }, + { selector: "br", format: "inlineSurround", options: { prefix: " " } }, + { selector: "img", format: "skip" } + // { selector: 'p', format: "inlineSurround", options: { prefix: " " } }, + ] + }); + Log.log("newsfeed -- Result:", description); items.push({ title: title, From 3cf78305a7a6e9d6a8052133b5b4ba51fedb7ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bugsounet=20-=20C=C3=A9dric?= Date: Fri, 10 Nov 2023 15:33:35 +0100 Subject: [PATCH 2/2] cleaning --- modules/default/newsfeed/newsfeedfetcher.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/default/newsfeed/newsfeedfetcher.js b/modules/default/newsfeed/newsfeedfetcher.js index 0cedc5257c..0c52e347ce 100644 --- a/modules/default/newsfeed/newsfeedfetcher.js +++ b/modules/default/newsfeed/newsfeedfetcher.js @@ -52,22 +52,15 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings const url = item.url || item.link || ""; if (title && pubdate) { - Log.log("---"); - Log.log("newsfeed -- Feed: ", description); - // const regex = /(<([^>]+)>)/gi; - // description = description.toString().replace(regex, " "); // Convert HTML entities, codes and tag - description = htmlToText(description, { wordwrap: false, selectors: [ { selector: "a", options: { ignoreHref: true, noAnchorUrl: true } }, { selector: "br", format: "inlineSurround", options: { prefix: " " } }, { selector: "img", format: "skip" } - // { selector: 'p', format: "inlineSurround", options: { prefix: " " } }, ] }); - Log.log("newsfeed -- Result:", description); items.push({ title: title,