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,7 +1,6 @@
|
||||
import { CheerioAPI, load } from 'cheerio';
|
||||
import { fetchApi, fetchFile } from '@libs/fetch';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@typings/plugin';
|
||||
import { Filters, FilterTypes } from '@libs/filterInputs';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
import dayjs from 'dayjs';
|
||||
@@ -12,7 +11,6 @@ class HarkenEliwoodPlugin implements Plugin.PluginBase {
|
||||
icon = 'src/fr/harkeneliwood/icon.png';
|
||||
site = 'https://harkeneliwood.wordpress.com';
|
||||
version = '1.0.0';
|
||||
filters: Filters | undefined = undefined;
|
||||
|
||||
async getCheerio(url: string): Promise<CheerioAPI> {
|
||||
const r = await fetchApi(url, {
|
||||
@@ -23,19 +21,13 @@ class HarkenEliwoodPlugin implements Plugin.PluginBase {
|
||||
return $;
|
||||
}
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
{
|
||||
showLatestNovels,
|
||||
filters,
|
||||
}: Plugin.PopularNovelsOptions<typeof this.filters>,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
async popularNovels(pageNo: number): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo > 1) return [];
|
||||
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
let novel: Plugin.NovelItem;
|
||||
let url = this.site;
|
||||
let $ = await this.getCheerio(url + '/projets/');
|
||||
const url = this.site;
|
||||
const $ = await this.getCheerio(url + '/projets/');
|
||||
$('#content .entry-content [href]')
|
||||
// We don't collect items for Facebook and Twitter.
|
||||
.not('[rel="nofollow noopener noreferrer"]')
|
||||
@@ -60,14 +52,14 @@ class HarkenEliwoodPlugin implements Plugin.PluginBase {
|
||||
name: 'Sans titre',
|
||||
};
|
||||
|
||||
let $ = await this.getCheerio(this.site + novelPath);
|
||||
const $ = await this.getCheerio(this.site + novelPath);
|
||||
novel.name = $('#content h1.entry-title').text().trim();
|
||||
novel.cover =
|
||||
$('#content .entry-content p img').first().attr('src') || defaultCover;
|
||||
novel.summary = this.getSummary($('#content .entry-content').text());
|
||||
novel.author = this.getAuthor($('#content .entry-content').text());
|
||||
novel.status = NovelStatus.Ongoing;
|
||||
let chapters: Plugin.ChapterItem[] = [];
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
$('#content .entry-content p a').each((i, elem) => {
|
||||
const chapterName = $(elem).text().trim();
|
||||
const chapterUrl = $(elem).attr('href');
|
||||
@@ -88,14 +80,13 @@ class HarkenEliwoodPlugin implements Plugin.PluginBase {
|
||||
}
|
||||
|
||||
getSummary(text: string) {
|
||||
let resume: string = '';
|
||||
const regexResume1: RegExp = /Synopsis :([\s\S]*)Traduction anglaise/i;
|
||||
const regexResume2: RegExp = /Synopsis :([\s\S]*)Raw :/i;
|
||||
const regexResume3: RegExp =
|
||||
/Synopsis 1 :([\s\S]*)Synopsis 2 :([\s\S]*)Raw :/i;
|
||||
const regexResume4: RegExp = /Synopsis :([\s\S]*)Prélude/i;
|
||||
const regexResume5: RegExp = /Synospis :([\s\S]*)Original /i;
|
||||
const regexResume6: RegExp = /([\s\S]*)Raw :/i;
|
||||
let resume = '';
|
||||
const regexResume1 = /Synopsis :([\s\S]*)Traduction anglaise/i;
|
||||
const regexResume2 = /Synopsis :([\s\S]*)Raw :/i;
|
||||
const regexResume3 = /Synopsis 1 :([\s\S]*)Synopsis 2 :([\s\S]*)Raw :/i;
|
||||
const regexResume4 = /Synopsis :([\s\S]*)Prélude/i;
|
||||
const regexResume5 = /Synospis :([\s\S]*)Original /i;
|
||||
const regexResume6 = /([\s\S]*)Raw :/i;
|
||||
|
||||
const match1: RegExpExecArray | null = regexResume1.exec(text);
|
||||
const match2: RegExpExecArray | null = regexResume2.exec(text);
|
||||
@@ -151,12 +142,9 @@ class HarkenEliwoodPlugin implements Plugin.PluginBase {
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo !== 1) return [];
|
||||
|
||||
let popularNovels = this.popularNovels(1, {
|
||||
showLatestNovels: true,
|
||||
filters: undefined,
|
||||
});
|
||||
const popularNovels = this.popularNovels(1);
|
||||
|
||||
let novels = (await popularNovels).filter(novel =>
|
||||
const novels = (await popularNovels).filter(novel =>
|
||||
novel.name
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
|
||||
Reference in New Issue
Block a user