This commit is contained in:
@@ -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, '') || ''
|
||||
);
|
||||
@@ -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();
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
"sourceSite": "https://lilyonthevalley.com",
|
||||
"sourceName": "Lily on the Valley",
|
||||
"options": {
|
||||
"customJs": {
|
||||
"chapterTransform": "custom/lillyonthevalley/chapterTransform.js"
|
||||
},
|
||||
"versionIncrements": 1,
|
||||
"browsePage": "stories"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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() || '';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user