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,33 +1,39 @@
|
||||
import list from './sources.json' with { type: 'json' };
|
||||
import { readFileSync } from 'fs';
|
||||
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 => {
|
||||
let filters = {};
|
||||
try {
|
||||
filters = require(`./filters/${metadata.id}`);
|
||||
metadata.filters = 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(
|
||||
`[madara] Generating: ${metadata.id}${' '.repeat(20 - metadata.id.length)} ${metadata.filters ? '🔎with filters🔍' : '🚫no filters🚫'}`,
|
||||
`[madara] 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 madaraTemplate = readFileSync('./scripts/multisrc/madara/template.ts', {
|
||||
const generator = function generator(source) {
|
||||
const madaraTemplate = readFileSync(join(folder, 'template.ts'), {
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
|
||||
const pluginScript = `
|
||||
${madaraTemplate}
|
||||
const plugin = new MadaraPlugin(${JSON.stringify(metadata)});
|
||||
const plugin = new MadaraPlugin(${JSON.stringify(source)});
|
||||
export default plugin;
|
||||
`.trim();
|
||||
return {
|
||||
lang: metadata.options?.lang || 'English',
|
||||
filename: metadata.sourceName,
|
||||
lang: source.options?.lang || 'English',
|
||||
filename: source.sourceName,
|
||||
pluginScript,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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 { Cheerio, AnyNode, CheerioAPI, load as parseHTML } from 'cheerio';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
@@ -82,7 +82,7 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
|
||||
getHostname(url: string): string {
|
||||
url = url.split('/')[2];
|
||||
let url_parts = url.split('.');
|
||||
const url_parts = url.split('.');
|
||||
url_parts.pop(); // remove TLD
|
||||
return url_parts.join('.');
|
||||
}
|
||||
@@ -203,7 +203,7 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
});
|
||||
|
||||
loadedCheerio('div.summary__content .code-block,script').remove();
|
||||
let summary =
|
||||
const summary =
|
||||
loadedCheerio('div.summary__content') ||
|
||||
loadedCheerio('#tab-manga-about') ||
|
||||
loadedCheerio('.post-content_item h5:contains("Summary")').next();
|
||||
@@ -250,7 +250,7 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
releaseDate = dayjs().format('LL');
|
||||
}
|
||||
|
||||
let chapterUrl = loadedCheerio(element).find('a').attr('href') || '';
|
||||
const chapterUrl = loadedCheerio(element).find('a').attr('href') || '';
|
||||
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
|
||||
Reference in New Issue
Block a user