feat: Add custom chapter transformation for Lily on the Valley source (#1719) (#1910)

This commit is contained in:
Justin COLLON
2025-12-24 13:21:54 +01:00
committed by GitHub
parent 2443d8f7fc
commit fef50e7b62
7 changed files with 70 additions and 4 deletions
@@ -0,0 +1,36 @@
const scriptContent = loadedCheerio('script')
.toArray()
.map(script => loadedCheerio(script).html())
.find(content => content && content.includes('var gib ='));
if (scriptContent) {
const gibMatch = scriptContent.match(/var gib = (\[.*?\])/);
if (gibMatch) {
const gibArray = eval(gibMatch[1]) as string[];
gibArray.forEach(cssClass => {
loadedCheerio(`.${cssClass}`).remove();
});
}
}
loadedCheerio('ruby').remove();
loadedCheerio('section#chapter-content p *').each((_, el) => {
if (loadedCheerio(el).attr('data-fcnc-rev') !== '1') return;
const textContent = loadedCheerio(el).text().trim();
if (textContent) {
loadedCheerio(el).replaceWith(
Array.from(textContent).reverse().join(''),
);
}
});
return (
loadedCheerio('section#chapter-content > div')
.html()
?.normalize()
.replace(/\u00A0/g, ' ')
.replace(/\u2060/g, '')
.replace(/­/g, '') // ­
.replace(/[\u202F\u2007\u200B]/g, '') || ''
);