Add TopLiba (#1003)
* test * cleanup deleted unused `fetchFile` import replaced fetch with `fetchApi` * eslint * fix * fix multi * Hmm, what to do next. * test URLSearchParams * fix
This commit is contained in:
@@ -1,34 +1,40 @@
|
||||
import list from './sources.json' with { type: 'json' };
|
||||
import { readFileSync } from 'fs';
|
||||
import path from 'path';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, join } from 'path';
|
||||
|
||||
const folder = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export const generateAll = function () {
|
||||
return list.map(metadata => {
|
||||
try {
|
||||
const { filters } = require(`./filters/${metadata.id}`);
|
||||
metadata.filters = filters;
|
||||
} catch (e) {}
|
||||
return list.map(source => {
|
||||
const exist = existsSync(join(folder, 'filters', source.id + '.json'));
|
||||
if (exist) {
|
||||
const filters = readFileSync(
|
||||
join(folder, 'filters', source.id + '.json'),
|
||||
);
|
||||
source.filters = JSON.parse(filters);
|
||||
}
|
||||
console.log(
|
||||
`[readwn] Generating: ${metadata.id}${' '.repeat(20 - metadata.id.length)} ${metadata.filters ? '🔎with filters🔍' : '🚫no filters🚫'}`,
|
||||
`[readwn] Generating: ${source.id}${' '.repeat(20 - source.id.length)} ${source.filters ? '🔎with filters🔍' : '🚫no filters🚫'}`,
|
||||
);
|
||||
return generator(metadata);
|
||||
return generator(source);
|
||||
});
|
||||
};
|
||||
|
||||
const generator = function generator(metadata) {
|
||||
const readwnTemplate = readFileSync('./scripts/multisrc/readwn/template.ts', {
|
||||
const generator = function generator(source) {
|
||||
const readwnTemplate = readFileSync(join(folder, 'template.ts'), {
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
|
||||
const pluginScript = `
|
||||
${readwnTemplate}
|
||||
const plugin = new ReadwnPlugin(${JSON.stringify(metadata)});
|
||||
const plugin = new ReadwnPlugin(${JSON.stringify(source)});
|
||||
export default plugin;
|
||||
`.trim();
|
||||
|
||||
return {
|
||||
lang: 'english',
|
||||
filename: metadata.sourceName,
|
||||
filename: source.sourceName,
|
||||
pluginScript,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -90,7 +90,7 @@ async function getFilters(name: string, url: string) {
|
||||
?.replace('-0.html', ''),
|
||||
}),
|
||||
);
|
||||
let nextPage = $('.pagination > li:last-child > a').attr('href');
|
||||
const nextPage = $('.pagination > li:last-child > a').attr('href');
|
||||
if (nextPage) {
|
||||
const allpage = parseInt(nextPage.replace(/[^0-9]/g, '') || '0', 10);
|
||||
for (let pageNo = 0; pageNo < allpage; pageNo++) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Filters, FilterTypes } from '@libs/filterInputs';
|
||||
import { Filters } from '@libs/filterInputs';
|
||||
import { Plugin } from '@typings/plugin';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
import { load as parseHTML } from 'cheerio';
|
||||
|
||||
Reference in New Issue
Block a user