fix: Update Chrysanthemum Garden (#1834)

- fix search function
 - removed pagination of search fuction
 - added default cases
 - fix summary
This commit is contained in:
Justin COLLON
2025-10-18 07:09:31 +02:00
committed by GitHub
parent de0a665a59
commit 214643f22e
+64 -50
View File
@@ -9,7 +9,7 @@ class Chrysanthemumgarden implements Plugin.PluginBase {
name = 'Chrysanthemum Garden'; name = 'Chrysanthemum Garden';
icon = 'src/en/chrysanthemumgarden/icon.png'; icon = 'src/en/chrysanthemumgarden/icon.png';
site = 'https://chrysanthemumgarden.com'; site = 'https://chrysanthemumgarden.com';
version = '1.0.0'; version = '1.0.1';
filters: Filters | undefined = undefined; filters: Filters | undefined = undefined;
imageRequestInit?: Plugin.ImageRequestInit | undefined = undefined; imageRequestInit?: Plugin.ImageRequestInit | undefined = undefined;
@@ -37,17 +37,18 @@ class Chrysanthemumgarden implements Plugin.PluginBase {
.includes('Manhua') .includes('Manhua')
) )
return; return;
const href = loadedCheerio(el).find('h2.novel-title > a').attr('href');
if (!href) return;
return { return {
name: loadedCheerio(el).find('h2.novel-title > a').text(), name: loadedCheerio(el).find('h2.novel-title > a').text(),
path: loadedCheerio(el) path: href
.find('h2.novel-title > a') .replace(this.site, '')
.attr('href')
?.replace(this.site, '')
.replace(/^\//, '') .replace(/^\//, '')
.replace(/\/$/, ''), .replace(/\/$/, ''),
cover: loadedCheerio(el) cover:
.find('div.novel-cover > img') loadedCheerio(el)
.attr('data-breeze'), .find('div.novel-cover > img')
.attr('data-breeze') || defaultCover,
}; };
}) })
.toArray() .toArray()
@@ -63,13 +64,16 @@ class Chrysanthemumgarden implements Plugin.PluginBase {
path: novelPath, path: novelPath,
name: loadedCheerio('h1.novel-title').text(), name: loadedCheerio('h1.novel-title').text(),
cover: loadedCheerio('div.novel-cover > img').attr('data-breeze'), cover: loadedCheerio('div.novel-cover > img').attr('data-breeze'),
summary: loadedCheerio('div.entry-content').text(), summary: loadedCheerio('div.entry-content > p')
.map((i, el) => loadedCheerio(el).text())
.toArray()
.join('\n\n'),
}; };
novel.author = loadedCheerio('div.novel-info') const novelInfoHtml = loadedCheerio('div.novel-info').html();
.html() novel.author = novelInfoHtml
.match(/Author:\s*([^<]*)<br>/)?.[1] ? novelInfoHtml.match(/Author:\s*([^<]*)<br>/)?.[1]?.trim()
.trim(); : undefined;
novel.genres = [ novel.genres = [
...loadedCheerio('div.series-genres > a') ...loadedCheerio('div.series-genres > a')
.map((i, el) => loadedCheerio(el).text()) .map((i, el) => loadedCheerio(el).text())
@@ -79,16 +83,19 @@ class Chrysanthemumgarden implements Plugin.PluginBase {
.toArray(), .toArray(),
].join(', '); ].join(', ');
novel.chapters = loadedCheerio('div.chapter-item > a').map((i, el) => { novel.chapters = loadedCheerio('div.chapter-item > a')
return { .map((i, el) => {
name: loadedCheerio(el).text().trim(), const href = loadedCheerio(el).attr('href');
path: loadedCheerio(el) if (!href) return;
.attr('href') return {
?.replace(this.site, '') name: loadedCheerio(el).text().trim(),
.replace(/^\//, '') path: href
.replace(/\/$/, ''), .replace(this.site, '')
}; .replace(/^\//, '')
}); .replace(/\/$/, ''),
};
})
.toArray();
return novel; return novel;
} }
@@ -104,39 +111,46 @@ class Chrysanthemumgarden implements Plugin.PluginBase {
searchTerm: string, searchTerm: string,
pageNo: number, pageNo: number,
): Promise<Plugin.NovelItem[]> { ): Promise<Plugin.NovelItem[]> {
return this.paginate( if (pageNo !== 1) return [];
(await this.getAllNovels()).filter(novel =>
novel.name.toLowerCase().includes(searchTerm.toLowerCase()), const req = await fetchApi(this.site + '/wp-json/cg/novels');
), const body = await req.json();
pageNo,
const allNovels: ChrysanthemumGardenNovelItem[] = (
body as ChrysanthemumGardenNovel[]
).map(
(novel: ChrysanthemumGardenNovel): ChrysanthemumGardenNovelItem => ({
name: novel.name,
path: novel.link
.replace(this.site, '')
.replace(/\/$/, '')
.replace(/^\//, ''),
cover: defaultCover,
}),
);
if (!allNovels) return [];
return allNovels.filter(novel =>
novel.name.toLowerCase().includes(searchTerm.toLowerCase()),
); );
} }
paginate<T>(data: T[], page: number): T[] { async getAllNovels() {}
const startIndex = (page - 1) * 20;
const endIndex = startIndex + 20;
return data.slice(startIndex, endIndex);
}
allNovelsCache: { name: string; path: string; cover: string }[] | undefined;
async getAllNovels() {
if (this.allNovelsCache) return this.allNovelsCache;
const req = await fetchApi(this.site + '/wp-json/melimeli/novels');
const body = await req.json();
this.allNovelsCache = body.map(novel => ({
name: novel.name,
path: novel.link
.replace(this.site, '')
.replace(/\/$/, '')
.replace(/^\//, ''),
cover: defaultCover,
}));
return this.allNovelsCache;
}
resolveUrl = (path: string, isNovel?: boolean) => resolveUrl = (path: string, isNovel?: boolean) =>
this.site + (isNovel ? '/book/' : '/chapter/') + path; this.site + (isNovel ? '/book/' : '/chapter/') + path;
} }
export default new Chrysanthemumgarden(); export default new Chrysanthemumgarden();
interface ChrysanthemumGardenNovel {
name: string;
link: string;
}
interface ChrysanthemumGardenNovelItem {
name: string;
path: string;
cover: string;
}