fix(french): novhell chapters using Gutenberg template (#2499)
Co-authored-by: Balrog57 <193098123+Balrog57@users.noreply.github.com>
This commit is contained in:
@@ -36,7 +36,7 @@ class NovhellPlugin implements Plugin.PluginBase {
|
||||
name = 'Novhell';
|
||||
icon = 'src/fr/novhell/icon.png';
|
||||
site = 'https://novhell.org';
|
||||
version = '1.0.4';
|
||||
version = '1.0.5';
|
||||
|
||||
async getCheerio(url: string): Promise<CheerioAPI> {
|
||||
return load(
|
||||
@@ -209,6 +209,34 @@ class NovhellPlugin implements Plugin.PluginBase {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
// Newer chapters use a Gutenberg block template with no `section`
|
||||
// elements: title in the columns block holding the `h4`, body in the
|
||||
// longest columns block of `article .entry-content`.
|
||||
const entry = $('article .entry-content').first();
|
||||
if (entry.length) {
|
||||
let titleHtml = '';
|
||||
let bodyHtml = '';
|
||||
let bodyLength = 0;
|
||||
entry.children('div.wp-block-columns').each((_, element) => {
|
||||
const block = $(element);
|
||||
if (block.find('h4').length) {
|
||||
if (!titleHtml) titleHtml = $.html(element) || '';
|
||||
return;
|
||||
}
|
||||
const textLength = block.text().replace(/\s+/g, ' ').trim().length;
|
||||
if (textLength > bodyLength) {
|
||||
bodyLength = textLength;
|
||||
bodyHtml = $.html(element) || '';
|
||||
}
|
||||
});
|
||||
const content = titleHtml + bodyHtml;
|
||||
const parsedContent = load(content);
|
||||
if (
|
||||
parsedContent.text().replace(/\s+/g, ' ').trim().length >= 200 ||
|
||||
parsedContent('img').length
|
||||
)
|
||||
return content;
|
||||
}
|
||||
throw new Error('No readable chapter content found');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user