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, '') || ''
);
+10 -2
View File
@@ -1,4 +1,4 @@
import { readFileSync } from 'fs';
import { existsSync, readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
@@ -20,8 +20,16 @@ const generator = function generator(source) {
encoding: 'utf-8',
});
const chapterTransformJsOrPath = source.options?.customJs?.chapterTransform;
const chapterTransformPath = chapterTransformJsOrPath
? join(folder, chapterTransformJsOrPath)
: '';
const chapterTransformJs = existsSync(chapterTransformPath)
? readFileSync(chapterTransformPath, { encoding: 'utf-8' })
: chapterTransformJsOrPath;
const pluginScript = `
${readNovelFullTemplate}
${readNovelFullTemplate.replace('// chapterTransformJs HERE', chapterTransformJs || '')}
const plugin = new FictioneerPlugin(${JSON.stringify(source)});
export default plugin;
`.trim();
+4
View File
@@ -21,6 +21,10 @@
"sourceSite": "https://lilyonthevalley.com",
"sourceName": "Lily on the Valley",
"options": {
"customJs": {
"chapterTransform": "custom/lillyonthevalley/chapterTransform.js"
},
"versionIncrements": 1,
"browsePage": "stories"
}
},
+3
View File
@@ -135,6 +135,9 @@ class FictioneerPlugin implements Plugin.PluginBase {
const body = await req.text();
const loadedCheerio = loadCheerio(body);
// chapterTransformJs HERE
return loadedCheerio('section#chapter-content > div').html() || '';
}