feat: add filters to NovelBuddy and remove 'SHOW MORE' from novel summaries (#1444)

This commit is contained in:
John Ramberger
2025-01-21 09:06:34 -05:00
committed by GitHub
parent fed546e2df
commit 56a28adb0e
+126 -4
View File
@@ -1,12 +1,13 @@
import { CheerioAPI, load as parseHTML } from 'cheerio';
import { fetchApi } from '@libs/fetch';
import { Plugin } from '@typings/plugin';
import { Filters, FilterTypes } from '@libs/filterInputs';
class NovelBuddy implements Plugin.PluginBase {
id = 'novelbuddy';
name = 'NovelBuddy.io';
site = 'https://novelbuddy.io/';
version = '1.0.1';
version = '1.0.2';
icon = 'src/en/novelbuddy/icon.png';
parseNovels(loadedCheerio: CheerioAPI) {
@@ -31,8 +32,25 @@ class NovelBuddy implements Plugin.PluginBase {
return novels;
}
async popularNovels(pageNo: number): Promise<Plugin.NovelItem[]> {
const url = `${this.site}popular?page=${pageNo}`;
async popularNovels(
pageNo: number,
{ filters }: Plugin.PopularNovelsOptions<Filters>,
): Promise<Plugin.NovelItem[]> {
// create empty query params
const params = new URLSearchParams();
// apply all filters
params.append('sort', filters.orderBy.value.toString());
params.append('status', filters.status.value.toString());
if (filters.genre.value instanceof Array) {
filters.genre.value.forEach(genre => {
params.append('genre[]', genre.toString());
});
}
params.append('q', filters.keyword.value.toString());
params.append('page', pageNo.toString());
const url = `${this.site}search?${params.toString()}`;
const result = await fetchApi(url);
const body = await result.text();
@@ -51,7 +69,7 @@ class NovelBuddy implements Plugin.PluginBase {
path: novelPath,
name: loadedCheerio('.name h1').text().trim() || 'Untitled',
cover: 'https:' + loadedCheerio('.img-cover img').attr('data-src'),
summary: loadedCheerio('.section-body.summary').text().trim(),
summary: loadedCheerio('.section-body.summary .content').text().trim(),
chapters: [],
};
@@ -167,6 +185,110 @@ class NovelBuddy implements Plugin.PluginBase {
const loadedCheerio = parseHTML(body);
return this.parseNovels(loadedCheerio);
}
filters = {
orderBy: {
value: 'views',
label: 'Order by',
options: [
{ label: 'Views', value: 'views' },
{ label: 'Updated At', value: 'updated_at' },
{ label: 'Created At', value: 'created_at' },
{ label: 'Name', value: 'name' },
{ label: 'Rating', value: 'rating' },
],
type: FilterTypes.Picker,
},
keyword: {
value: '',
label: 'Keywords',
type: FilterTypes.TextInput,
},
status: {
value: 'all',
label: 'Status',
options: [
{ label: 'All', value: 'all' },
{ label: 'Ongoing', value: 'ongoing' },
{ label: 'Completed', value: 'completed' },
],
type: FilterTypes.Picker,
},
genre: {
value: [],
label: 'Genres (OR, not AND)',
options: [
{ label: 'Action', value: 'action' },
{ label: 'Action Adventure', value: 'action-adventure' },
{ label: 'Adult', value: 'adult' },
{ label: 'Adventcure', value: 'adventcure' },
{ label: 'Adventure', value: 'adventure' },
{ label: 'Adventurer', value: 'adventurer' },
{ label: 'Bender', value: 'bender' },
{ label: 'Chinese', value: 'chinese' },
{ label: 'Comedy', value: 'comedy' },
{ label: 'Cultivation', value: 'cultivation' },
{ label: 'Drama', value: 'drama' },
{ label: 'Eastern', value: 'eastern' },
{ label: 'Ecchi', value: 'ecchi' },
{ label: 'Fan Fiction', value: 'fan-fiction' },
{ label: 'Fanfiction', value: 'fanfiction' },
{ label: 'Fantas', value: 'fantas' },
{ label: 'Fantasy', value: 'fantasy' },
{ label: 'Game', value: 'game' },
{ label: 'Gender', value: 'gender' },
{ label: 'Gender Bender', value: 'gender-bender' },
{ label: 'Harem', value: 'harem' },
{ label: 'HaremAction', value: 'haremaction' },
{ label: 'Haremv', value: 'haremv' },
{ label: 'Historica', value: 'historica' },
{ label: 'Historical', value: 'historical' },
{ label: 'History', value: 'history' },
{ label: 'Horror', value: 'horror' },
{ label: 'Isekai', value: 'isekai' },
{ label: 'Josei', value: 'josei' },
{ label: 'Lolicon', value: 'lolicon' },
{ label: 'Magic', value: 'magic' },
{ label: 'Martial', value: 'martial' },
{ label: 'Martial Arts', value: 'martial-arts' },
{ label: 'Mature', value: 'mature' },
{ label: 'Mecha', value: 'mecha' },
{ label: 'Military', value: 'military' },
{ label: 'Modern Life', value: 'modern-life' },
{ label: 'Mystery', value: 'mystery' },
{ label: 'Mystery Adventure', value: 'mystery-adventure' },
{ label: 'Psychologic', value: 'psychologic' },
{ label: 'Psychological', value: 'psychological' },
{ label: 'Reincarnation', value: 'reincarnation' },
{ label: 'Romance', value: 'romance' },
{ label: 'Romance Adventure', value: 'romance-adventure' },
{ label: 'Romance Harem', value: 'romance-harem' },
{ label: 'Romancem', value: 'romancem' },
{ label: 'School Life', value: 'school-life' },
{ label: 'Sci-fi', value: 'sci-fi' },
{ label: 'Seinen', value: 'seinen' },
{ label: 'Shoujo', value: 'shoujo' },
{ label: 'Shoujo Ai', value: 'shoujo-ai' },
{ label: 'Shounen', value: 'shounen' },
{ label: 'Shounen Ai', value: 'shounen-ai' },
{ label: 'Slice of Life', value: 'slice-of-life' },
{ label: 'Smut', value: 'smut' },
{ label: 'Sports', value: 'sports' },
{ label: 'Superna', value: 'superna' },
{ label: 'Supernatural', value: 'supernatural' },
{ label: 'System', value: 'system' },
{ label: 'Tragedy', value: 'tragedy' },
{ label: 'Urban', value: 'urban' },
{ label: 'Urban Life', value: 'urban-life' },
{ label: 'Wuxia', value: 'wuxia' },
{ label: 'Xianxia', value: 'xianxia' },
{ label: 'Xuanhuan', value: 'xuanhuan' },
{ label: 'Yaoi', value: 'yaoi' },
{ label: 'Yuri', value: 'yuri' },
],
type: FilterTypes.CheckboxGroup,
},
} satisfies Filters;
}
export default new NovelBuddy();