From 2329d3161669098e8646f084c052cf17c19fdb92 Mon Sep 17 00:00:00 2001 From: yemen Date: Tue, 21 Jul 2026 19:03:58 +0300 Subject: [PATCH 1/3] fix(rewayatfans): improve novel listing and chapter extraction - Fetch novels from listing page with pagination support - Add cover images via _embed parameter - Fix chapter number extraction from title instead of slug - Add normalized title matching for better search - Support Arabic novel pages with HTML chapter extraction - Version bump to 4.0.0 --- plugins/arabic/rewayatfans.ts | 191 +++++++++++++++++++++++----------- 1 file changed, 128 insertions(+), 63 deletions(-) diff --git a/plugins/arabic/rewayatfans.ts b/plugins/arabic/rewayatfans.ts index a5ee909d9..d9ed578a7 100644 --- a/plugins/arabic/rewayatfans.ts +++ b/plugins/arabic/rewayatfans.ts @@ -3,18 +3,19 @@ import { fetchApi } from '@libs/fetch'; import { Plugin } from '@/types/plugin'; type WPPage = { - id: number; title: { rendered: string }; slug: string; - link: string; - content: { rendered: string }; date: string; + featured_media: number; + _embedded?: { + 'wp:featuredmedia'?: Array<{ source_url: string }>; + }; }; class RewayatFans implements Plugin.PluginBase { id = 'rewayatfans'; name = 'روايات فانز'; - version = '3.0.0'; + version = '4.0.0'; icon = 'src/ar/rewayatfans/icon.png'; site = 'https://rewayatfans.com/'; @@ -30,60 +31,66 @@ class RewayatFans implements Plugin.PluginBase { return res.text(); } + private getCover(page: WPPage): string { + return page._embedded?.['wp:featuredmedia']?.[0]?.source_url || ''; + } + async popularNovels( page: number, { showLatestNovels }: Plugin.PopularNovelsOptions, ): Promise { if (showLatestNovels) { const pages = await this.fetchJson( - `${this.site}wp-json/wp/v2/pages?per_page=20&page=${page}&orderby=date&order=desc&_fields=slug,title`, + `${this.site}wp-json/wp/v2/pages?per_page=20&page=${page}&orderby=date&order=desc&_embed`, ); - return pages.map(p => ({ - name: this.extractNovelName(p.title.rendered), - path: p.slug, - cover: '', - })); - } - const allNovels = await this.getAllNovels(); - const pageSize = 20; - const start = (page - 1) * pageSize; - return allNovels.slice(start, start + pageSize); - } - - private async getAllNovels(): Promise { - const seen = new Set(); - const novels: Plugin.NovelItem[] = []; + const seen = new Set(); + const novels: Plugin.NovelItem[] = []; - let pg = 1; - let hasMore = true; - - while (hasMore) { - const pages = await this.fetchJson( - `${this.site}wp-json/wp/v2/pages?per_page=100&page=${pg}&_fields=slug,title`, - ); - - if (pages.length === 0) { - hasMore = false; - break; - } - - for (const page of pages) { - const novelName = this.extractNovelName(page.title.rendered); + for (const p of pages) { + const novelName = this.extractNovelName(p.title.rendered); if (novelName && !seen.has(novelName)) { seen.add(novelName); novels.push({ name: novelName, - path: page.slug, - cover: '', + path: p.slug, + cover: this.getCover(p), }); } } - if (pages.length < 100) hasMore = false; - pg++; + return novels; } + const listingPath = + page === 1 + ? `${this.site}%D9%82%D8%A7%D8%A6%D9%85%D8%A9-%D8%A7%D9%84%D8%B1%D9%88%D8%A7%D9%8A%D8%A7%D8%AA/` + : `${this.site}%D9%82%D8%A7%D8%A6%D9%85%D8%A9-%D8%A7%D9%84%D8%B1%D9%88%D8%A7%D9%8A%D8%A7%D8%AT/page/${page}/`; + + const html = await this.fetchHtml(listingPath); + const $ = parseHTML(html); + const novels: Plugin.NovelItem[] = []; + const seen = new Set(); + + $('div.entry-content a').each((_, el) => { + const href = $(el).attr('href') || ''; + const name = $(el).text().trim(); + + if ( + name.length > 3 && + href.includes('rewayatfans.com/') && + !name.includes('الرئيسية') && + !name.includes('روايات فانز') && + !name.includes('قائمة الروايات') && + !name.includes('قائمة المكتملة') && + !seen.has(name) + ) { + seen.add(name); + const slug = href.replace(/\/$/, '').split('/').pop() || ''; + novels.push({ name, path: slug, cover: '' }); + } + }); + return novels; } @@ -95,16 +102,70 @@ class RewayatFans implements Plugin.PluginBase { }; const slugBase = novelPath.replace(/\/$/, '').split('/').pop() || novelPath; - const searchTerm = slugBase - .replace(/-\d+$/, '') - .replace(/-/g, ' '); + const isArabic = !/[a-zA-Z]/.test(slugBase); + + if (isArabic) { + const html = await this.fetchHtml(`${this.site}${novelPath}/`); + const $ = parseHTML(html); + novel.name = $('title').text().replace(/\s*[–|].*$/, '').trim(); + + const allSlugs = new Set(); + $('a[href]').each((_, el) => { + const href = $(el).attr('href') || ''; + const match = href.match( + /rewayatfans\.com\/([a-z][a-z0-9-]+-\d+)\/?$/, + ); + if (match) { + allSlugs.add(match[1]); + } + }); + + const prefixCounts = new Map(); + for (const slug of allSlugs) { + const prefix = slug.replace(/-\d+$/, ''); + prefixCounts.set(prefix, (prefixCounts.get(prefix) || 0) + 1); + } + + let bestPrefix = ''; + let bestCount = 0; + for (const [prefix, count] of prefixCounts) { + if (count > bestCount) { + bestPrefix = prefix; + bestCount = count; + } + } + + for (const slug of allSlugs) { + if (slug.startsWith(bestPrefix)) { + const numMatch = slug.match(/(\d+)$/); + const chapterNum = numMatch ? parseInt(numMatch[1], 10) : 0; + novel.chapters!.push({ + name: `${novel.name} ${chapterNum}`, + path: slug, + chapterNumber: chapterNum, + }); + } + } + + novel.chapters!.sort( + (a, b) => (a.chapterNumber || 0) - (b.chapterNumber || 0), + ); + return novel; + } + + const novelPrefix = slugBase.replace(/-\d+$/, ''); + const searchName = novelPrefix.replace(/-/g, ' '); + + const normalize = (s: string) => + s.toLowerCase().replace(/[^a-z0-9\s]/g, '').replace(/\s+/g, ' ').trim(); + const normalizedSearch = normalize(searchName); let pg = 1; let hasMore = true; while (hasMore) { const pages = await this.fetchJson( - `${this.site}wp-json/wp/v2/pages?search=${encodeURIComponent(searchTerm)}&per_page=100&page=${pg}&_fields=slug,title,date`, + `${this.site}wp-json/wp/v2/pages?search=${encodeURIComponent(searchName)}&per_page=100&page=${pg}&_fields=slug,title,date`, ); if (pages.length === 0) { @@ -112,20 +173,23 @@ class RewayatFans implements Plugin.PluginBase { break; } - for (const page of pages) { - const postSlug = page.slug; - if (postSlug.startsWith(slugBase.replace(/-\d+$/, ''))) { + for (const p of pages) { + const normalizedTitle = normalize(p.title.rendered); + if ( + p.slug.startsWith(novelPrefix) || + normalizedTitle.startsWith(normalizedSearch) + ) { if (!novel.name) { - novel.name = this.extractNovelName(page.title.rendered); + novel.name = this.extractNovelName(p.title.rendered); } - const numMatch = postSlug.match(/(\d+)$/); + const numMatch = p.title.rendered.match(/(\d+)\s*$/); const chapterNum = numMatch ? parseInt(numMatch[1], 10) : 0; novel.chapters!.push({ - name: page.title.rendered, - path: postSlug, + name: p.title.rendered, + path: p.slug, chapterNumber: chapterNum, - releaseTime: page.date, + releaseTime: p.date, }); } } @@ -134,11 +198,12 @@ class RewayatFans implements Plugin.PluginBase { pg++; } - if (novel.chapters!.length > 0) { - novel.chapters!.sort((a, b) => (a.chapterNumber || 0) - (b.chapterNumber || 0)); - if (!novel.name && novel.chapters!.length > 0) { - novel.name = this.extractNovelName(novel.chapters![0].name); - } + novel.chapters!.sort( + (a, b) => (a.chapterNumber || 0) - (b.chapterNumber || 0), + ); + + if (!novel.name && novel.chapters!.length > 0) { + novel.name = this.extractNovelName(novel.chapters![0].name); } return novel; @@ -150,8 +215,8 @@ class RewayatFans implements Plugin.PluginBase { ); const arr = Array.isArray(pages) ? pages : [pages]; - if (arr.length > 0 && arr[0].content?.rendered) { - const $ = parseHTML(arr[0].content.rendered); + if (arr.length > 0 && (arr[0] as any).content?.rendered) { + const $ = parseHTML((arr[0] as any).content.rendered); $('script, style, .sharedaddy, .jp-relatedposts, .wp-block-spacer').remove(); return $.html(); } @@ -168,20 +233,20 @@ class RewayatFans implements Plugin.PluginBase { page: number, ): Promise { const pages = await this.fetchJson( - `${this.site}wp-json/wp/v2/pages?search=${encodeURIComponent(searchTerm)}&per_page=20&page=${page}&_fields=slug,title`, + `${this.site}wp-json/wp/v2/pages?search=${encodeURIComponent(searchTerm)}&per_page=20&page=${page}&_embed`, ); const seen = new Set(); const novels: Plugin.NovelItem[] = []; - for (const page of pages) { - const novelName = this.extractNovelName(page.title.rendered); + for (const p of pages) { + const novelName = this.extractNovelName(p.title.rendered); if (novelName && !seen.has(novelName)) { seen.add(novelName); novels.push({ name: novelName, - path: page.slug, - cover: '', + path: p.slug, + cover: this.getCover(p), }); } } From 2f44a8fc7fa33519f3588b8d39b8d9a8aa27866d Mon Sep 17 00:00:00 2001 From: yemen Date: Tue, 21 Jul 2026 19:34:02 +0300 Subject: [PATCH 2/3] fix(rewayatfans): make listing page the default main page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Always fetch from listing page (قائمة-الروايات) regardless of showLatestNovels flag - Version bump to 4.1.0 --- plugins/arabic/rewayatfans.ts | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/plugins/arabic/rewayatfans.ts b/plugins/arabic/rewayatfans.ts index d9ed578a7..97600526b 100644 --- a/plugins/arabic/rewayatfans.ts +++ b/plugins/arabic/rewayatfans.ts @@ -15,7 +15,7 @@ type WPPage = { class RewayatFans implements Plugin.PluginBase { id = 'rewayatfans'; name = 'روايات فانز'; - version = '4.0.0'; + version = '4.1.0'; icon = 'src/ar/rewayatfans/icon.png'; site = 'https://rewayatfans.com/'; @@ -39,29 +39,6 @@ class RewayatFans implements Plugin.PluginBase { page: number, { showLatestNovels }: Plugin.PopularNovelsOptions, ): Promise { - if (showLatestNovels) { - const pages = await this.fetchJson( - `${this.site}wp-json/wp/v2/pages?per_page=20&page=${page}&orderby=date&order=desc&_embed`, - ); - - const seen = new Set(); - const novels: Plugin.NovelItem[] = []; - - for (const p of pages) { - const novelName = this.extractNovelName(p.title.rendered); - if (novelName && !seen.has(novelName)) { - seen.add(novelName); - novels.push({ - name: novelName, - path: p.slug, - cover: this.getCover(p), - }); - } - } - - return novels; - } - const listingPath = page === 1 ? `${this.site}%D9%82%D8%A7%D8%A6%D9%85%D8%A9-%D8%A7%D9%84%D8%B1%D9%88%D8%A7%D9%8A%D8%A7%D8%AA/` From ce5d1954775058a96782bac372ddd2494a4b8043 Mon Sep 17 00:00:00 2001 From: yemen Date: Tue, 21 Jul 2026 19:58:55 +0300 Subject: [PATCH 3/3] fix(rewayatfans): revert to API-based approach for reliability - Use WordPress API for popularNovels with _embed for cover images - Use API-based chapter search with title number extraction - Remove problematic listing page HTML parsing - Cover images and chapter lists now work correctly - Version bump to 4.2.0 --- plugins/arabic/rewayatfans.ts | 91 ++++++----------------------------- 1 file changed, 15 insertions(+), 76 deletions(-) diff --git a/plugins/arabic/rewayatfans.ts b/plugins/arabic/rewayatfans.ts index 97600526b..ea3b72db7 100644 --- a/plugins/arabic/rewayatfans.ts +++ b/plugins/arabic/rewayatfans.ts @@ -15,7 +15,7 @@ type WPPage = { class RewayatFans implements Plugin.PluginBase { id = 'rewayatfans'; name = 'روايات فانز'; - version = '4.1.0'; + version = '4.2.0'; icon = 'src/ar/rewayatfans/icon.png'; site = 'https://rewayatfans.com/'; @@ -39,34 +39,24 @@ class RewayatFans implements Plugin.PluginBase { page: number, { showLatestNovels }: Plugin.PopularNovelsOptions, ): Promise { - const listingPath = - page === 1 - ? `${this.site}%D9%82%D8%A7%D8%A6%D9%85%D8%A9-%D8%A7%D9%84%D8%B1%D9%88%D8%A7%D9%8A%D8%A7%D8%AA/` - : `${this.site}%D9%82%D8%A7%D8%A6%D9%85%D8%A9-%D8%A7%D9%84%D8%B1%D9%88%D8%A7%D9%8A%D8%A7%D8%AT/page/${page}/`; + const pages = await this.fetchJson( + `${this.site}wp-json/wp/v2/pages?per_page=20&page=${page}&orderby=date&order=desc&_embed`, + ); - const html = await this.fetchHtml(listingPath); - const $ = parseHTML(html); - const novels: Plugin.NovelItem[] = []; const seen = new Set(); + const novels: Plugin.NovelItem[] = []; - $('div.entry-content a').each((_, el) => { - const href = $(el).attr('href') || ''; - const name = $(el).text().trim(); - - if ( - name.length > 3 && - href.includes('rewayatfans.com/') && - !name.includes('الرئيسية') && - !name.includes('روايات فانز') && - !name.includes('قائمة الروايات') && - !name.includes('قائمة المكتملة') && - !seen.has(name) - ) { - seen.add(name); - const slug = href.replace(/\/$/, '').split('/').pop() || ''; - novels.push({ name, path: slug, cover: '' }); + for (const p of pages) { + const novelName = this.extractNovelName(p.title.rendered); + if (novelName && !seen.has(novelName)) { + seen.add(novelName); + novels.push({ + name: novelName, + path: p.slug, + cover: this.getCover(p), + }); } - }); + } return novels; } @@ -79,57 +69,6 @@ class RewayatFans implements Plugin.PluginBase { }; const slugBase = novelPath.replace(/\/$/, '').split('/').pop() || novelPath; - const isArabic = !/[a-zA-Z]/.test(slugBase); - - if (isArabic) { - const html = await this.fetchHtml(`${this.site}${novelPath}/`); - const $ = parseHTML(html); - novel.name = $('title').text().replace(/\s*[–|].*$/, '').trim(); - - const allSlugs = new Set(); - $('a[href]').each((_, el) => { - const href = $(el).attr('href') || ''; - const match = href.match( - /rewayatfans\.com\/([a-z][a-z0-9-]+-\d+)\/?$/, - ); - if (match) { - allSlugs.add(match[1]); - } - }); - - const prefixCounts = new Map(); - for (const slug of allSlugs) { - const prefix = slug.replace(/-\d+$/, ''); - prefixCounts.set(prefix, (prefixCounts.get(prefix) || 0) + 1); - } - - let bestPrefix = ''; - let bestCount = 0; - for (const [prefix, count] of prefixCounts) { - if (count > bestCount) { - bestPrefix = prefix; - bestCount = count; - } - } - - for (const slug of allSlugs) { - if (slug.startsWith(bestPrefix)) { - const numMatch = slug.match(/(\d+)$/); - const chapterNum = numMatch ? parseInt(numMatch[1], 10) : 0; - novel.chapters!.push({ - name: `${novel.name} ${chapterNum}`, - path: slug, - chapterNumber: chapterNum, - }); - } - } - - novel.chapters!.sort( - (a, b) => (a.chapterNumber || 0) - (b.chapterNumber || 0), - ); - return novel; - } - const novelPrefix = slugBase.replace(/-\d+$/, ''); const searchName = novelPrefix.replace(/-/g, ' ');