From 9316f8a6e17dac2886df7346fb5e0dc95ef295f2 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 4 Jun 2024 20:11:11 +0800 Subject: [PATCH] fix: use article's first long paragraph as excerpt if description not found --- packages/readabilityjs/Readability.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/readabilityjs/Readability.js b/packages/readabilityjs/Readability.js index f8db3d884..0cff46998 100644 --- a/packages/readabilityjs/Readability.js +++ b/packages/readabilityjs/Readability.js @@ -3101,13 +3101,18 @@ Readability.prototype = { this._postProcessContent(articleContent); // If we haven't found an excerpt in the article's metadata, use the article's - // first paragraph as the excerpt. This is used for displaying a preview of + // first long paragraph (more than 200 characters) as the excerpt. This is used for displaying a preview of // the article's content. if (!metadata.excerpt) { var paragraphs = articleContent.getElementsByTagName("p"); - if (paragraphs.length > 0) { - metadata.excerpt = paragraphs[0].textContent.trim(); - } + paragraphs.forEach((p) => { + const text = p.textContent.trim(); + + if (text.length > 200) { + metadata.excerpt = text + return + } + }); } if (!metadata.siteName) { // Fallback to hostname