diff --git a/.prettierignore b/.prettierignore index d9ea5e3..0bdfd9d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,3 @@ node_modules .js +plugins/multisrc/fictioneer/custom diff --git a/plugins/multisrc/fictioneer/custom/lillyonthevalley/chapterTransform.js b/plugins/multisrc/fictioneer/custom/lillyonthevalley/chapterTransform.js new file mode 100644 index 0000000..77d900f --- /dev/null +++ b/plugins/multisrc/fictioneer/custom/lillyonthevalley/chapterTransform.js @@ -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, '') || '' + ); \ No newline at end of file diff --git a/plugins/multisrc/fictioneer/generator.js b/plugins/multisrc/fictioneer/generator.js index da53d43..452a878 100644 --- a/plugins/multisrc/fictioneer/generator.js +++ b/plugins/multisrc/fictioneer/generator.js @@ -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(); diff --git a/plugins/multisrc/fictioneer/sources.json b/plugins/multisrc/fictioneer/sources.json index 9ecd3b8..103a100 100644 --- a/plugins/multisrc/fictioneer/sources.json +++ b/plugins/multisrc/fictioneer/sources.json @@ -21,6 +21,10 @@ "sourceSite": "https://lilyonthevalley.com", "sourceName": "Lily on the Valley", "options": { + "customJs": { + "chapterTransform": "custom/lillyonthevalley/chapterTransform.js" + }, + "versionIncrements": 1, "browsePage": "stories" } }, diff --git a/plugins/multisrc/fictioneer/template.ts b/plugins/multisrc/fictioneer/template.ts index 8ca8084..2ac2688 100644 --- a/plugins/multisrc/fictioneer/template.ts +++ b/plugins/multisrc/fictioneer/template.ts @@ -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() || ''; } diff --git a/tsconfig.json b/tsconfig.json index 2b36321..ba1dfc9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -118,5 +118,18 @@ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, - "exclude": ["./plugins/**/*.broken.ts", "./.js/**/*", "scripts", "docs"] + "exclude": [ + "./plugins/**/*.broken.ts", + "./.js/**/*", + "scripts/**", + "docs/**", + "./src/*.*", + "./*.*", + "public/**", + ".github/**", + ".husky/**", + "node_modules/**", + "./src/**", + "./plugins/multisrc/*" + ] } diff --git a/tsconfig.production.json b/tsconfig.production.json index f611c99..17a7a62 100644 --- a/tsconfig.production.json +++ b/tsconfig.production.json @@ -122,6 +122,7 @@ ".github/**", ".husky/**", "node_modules/**", - "./src/**" + "./src/**", + "./plugins/multisrc/*" ] }