Skip to content

Commit 7c223b9

Browse files
iparamonaunleush
authored andcommitted
[Articlebody] Allow to choose between HTML and TXT formats (#607)
* [Articlebody] Allow to choose between HTML and TXT formats * reinstate spaces when texting paragraphs
1 parent bff11d5 commit 7c223b9

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

plugins/links/article/article.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ export default {
88

99
const articleHtml = utils.encodeText(meta.charset, readability.getHTML());
1010
const $p = cheerio.load(articleHtml)('p');
11+
const articleText = $p.text();
1112

12-
if ($p.text()) {
13+
if (articleText) {
1314
return {
14-
articlebody: articleHtml
15+
articlebody: __readabilityEnabled === 'html' ? articleHtml : articleText.replace(/\.([^\.\d\s\n\r\'\"\”\)\]])/g, '. $1')
1516
}
1617
}
1718
},

plugins/links/article/check-article.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ export default {
1414
|| meta.twitter?.card === 'summary_large_image'
1515
|| meta.article))
1616

17-
&& (options.getRequestOptions('readability.articlebody', false) || CONFIG.providerOptions?.app?.allow_readability === true)) {
17+
&& (options.getRequestOptions('readability.articlebody') || CONFIG.providerOptions?.app?.allow_readability === true)) {
1818

19-
if (ld?.articlebody && /\/>/.test(ld.articlebody)) {
19+
const article_format = (options.getRequestOptions('readability.articlebody') === 'html'
20+
|| CONFIG.providerOptions?.app?.allow_readability === true) ? 'html' : 'txt';
21+
22+
if (ld?.articlebody && (article_format !== 'html' || /\/>/.test(ld.articlebody))) {
2023
return {
2124
articlebody: ld.articlebody
2225
}
2326
} else if (options.getProviderOptions('app.allow_readability')) {
2427
return {
25-
__readabilityEnabled: true
28+
__readabilityEnabled: article_format
2629
}
2730
}
2831
}

plugins/links/article/reader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default {
22

3-
getData: function(articlebody) {
4-
if (CONFIG.providerOptions?.app?.allow_readability === true && !CONFIG.SKIP_IFRAMELY_RENDERS) {
3+
getData: function(__readabilityEnabled, articlebody) {
4+
if (__readabilityEnabled === 'html' && CONFIG.providerOptions?.app?.allow_readability === true && !CONFIG.SKIP_IFRAMELY_RENDERS) {
55
return {
66
safe_html: articlebody
77
}

0 commit comments

Comments
 (0)