From 215f7ba5772c6c1a1f31c9855e52a5aa3eb39755 Mon Sep 17 00:00:00 2001 From: Sharique Hassan Malik <146327065+Sharique-Hassan-Malik@users.noreply.github.com> Date: Thu, 3 Dec 2026 17:11:37 +0500 Subject: [PATCH] feat(english): add The Sun Is Cold source thesuniscold.translatednovels.com is a WordPress translation blog with four novels, listed only in its menu, so the plugin lists them; novel pages, chapter links and chapter text come from the public REST API. Chapter index pages mix a latest list with the archive, so chapters are sorted by number when most have one; side stories go last. 108 Maidens of Destiny starts at chapter 23 because the site links chapters 1-22 to another translator. --- plugins/english/thesuniscold.ts | 214 +++++++++++++++++++++ public/static/src/en/thesuniscold/icon.png | Bin 0 -> 3643 bytes 2 files changed, 214 insertions(+) create mode 100644 plugins/english/thesuniscold.ts create mode 100644 public/static/src/en/thesuniscold/icon.png diff --git a/plugins/english/thesuniscold.ts b/plugins/english/thesuniscold.ts new file mode 100644 index 0000000000..853c13317d --- /dev/null +++ b/plugins/english/thesuniscold.ts @@ -0,0 +1,214 @@ +import { fetchApi } from '@libs/fetch'; +import { Filters, FilterTypes } from '@libs/filterInputs'; +import { + checkResponse, + createPluginError, + PluginError, +} from '@libs/pluginError'; +import { Plugin } from '@/types/plugin'; +import { load as parseHTML } from 'cheerio'; + +/** + * thesuniscold.translatednovels.com is a WordPress translation blog with four + * novels. Each novel is a page listing its chapters as links; chapters are + * pages or posts. The site lists its novels only in its menu, so they are + * listed here; everything else comes from the public REST API. + */ +const NOVELS: Plugin.NovelItem[] = [ + { + name: '108 Maidens of Destiny', + path: '108-maidens-of-destiny', + cover: + 'https://i0.wp.com/thesuniscold.translatednovels.com/wp-content/uploads/2017/01/108-bigger-212x300.png?resize=212%2C300', + }, + { name: 'Maiden Galaxy', path: 'maiden-galaxy' }, + { + name: 'Investiture of the Star Generals', + path: 'investiture-of-the-star-generals', + cover: + 'https://i0.wp.com/thesuniscold.translatednovels.com/wp-content/uploads/2025/02/92075s.jpg?resize=187%2C272&ssl=1', + }, + { + name: 'Back to the Apocalypse', + path: 'projects/back-to-the-apocalypse', + cover: + 'https://i0.wp.com/thesuniscold.translatednovels.com/wp-content/uploads/2017/02/baijing-264x300.jpg?resize=264%2C300', + }, +]; + +type WpItem = { + title: { rendered: string }; + content: { rendered: string }; +}; + +const clean = (s: unknown): string => + String(s ?? '') + .replace(/\s+/g, ' ') + .trim(); + +/** + * A chapter number, only when "chapter" is near the digits, so a side story + * such as "Extra 3: ..." is not taken for chapter 3. + */ +const chapterNumber = (name: string, path: string): number | null => { + const m = + name.match(/(?:chapter|chap|ch)[^0-9]{0,3}(\d+(?:\.\d+)?)/i) || + path.match(/chapter[-_]?(\d+(?:\.\d+)?)/i); + if (m) return parseFloat(m[1]); + if (/chapter/i.test(name + ' ' + path)) { + const m2 = (name + ' ' + path).match(/(\d+(?:\.\d+)?)/); + if (m2) return parseFloat(m2[1]); + } + return null; +}; + +class TheSunIsColdPlugin implements Plugin.PluginBase { + id = 'thesuniscold'; + name = 'The Sun Is Cold'; + icon = 'src/en/thesuniscold/icon.png'; + site = 'https://thesuniscold.translatednovels.com/'; + version = '1.0.0'; + + filters = { + sort: { + type: FilterTypes.Picker, + label: 'Sort', + value: 'site', + options: [ + { label: 'Site order', value: 'site' }, + { label: 'Title A-Z', value: 'asc' }, + { label: 'Title Z-A', value: 'desc' }, + ], + }, + } satisfies Filters; + + private async api(path: string): Promise { + const url = this.site + 'wp-json/wp/v2/' + path; + const r = await fetchApi(url); + checkResponse(r); + try { + return (await r.json()) as WpItem[]; + } catch { + throw createPluginError(PluginError.InvalidResponse, { url }); + } + } + + private toPath(url: string | undefined): string | null { + if (!url) return null; + const host = this.site.replace(/^https?:\/\//, ''); + const u = url.replace(/^https?:\/\//, ''); + return u.startsWith(host) + ? u.slice(host.length).replace(/(^\/+|\/+$)/g, '') + : null; + } + + async popularNovels( + pageNo: number, + { filters }: Plugin.PopularNovelsOptions, + ): Promise { + if (pageNo !== 1) return []; + const list = NOVELS.slice(); + const sort = filters?.sort?.value || 'site'; + if (sort !== 'site') { + list.sort((a, b) => a.name.localeCompare(b.name)); + if (sort === 'desc') list.reverse(); + } + return list; + } + + async searchNovels( + searchTerm: string, + pageNo: number, + ): Promise { + if (pageNo !== 1) return []; + const q = searchTerm.toLowerCase(); + return NOVELS.filter(n => n.name.toLowerCase().includes(q)); + } + + async parseNovel(novelPath: string): Promise { + const slug = novelPath.replace(/\/+$/, '').split('/').pop() || ''; + const pages = await this.api('pages?slug=' + encodeURIComponent(slug)); + if (pages.length !== 1) { + throw createPluginError(PluginError.NovelNotFound, { + url: this.site + novelPath, + }); + } + const $ = parseHTML(pages[0].content.rendered); + const found: Plugin.ChapterItem[] = []; + const seen: Record = {}; + $('a').each((_, el) => { + const path = this.toPath($(el).attr('href')); + if (!path || seen[path]) return; + if (!path.startsWith(novelPath + '/') && !/^archives\//.test(path)) + return; + const name = clean($(el).text()); + if (!name) return; + seen[path] = true; + found.push({ name, path }); + }); + // The index pages mix a "latest" list with the full archive, so page + // order is not reading order: sort by chapter number when most chapters + // have one; the others go last, in page order. + const numbers = found.map(c => chapterNumber(c.name, c.path)); + let chapters = found; + if ( + found.length > 3 && + numbers.filter(n => n !== null).length >= found.length * 0.6 + ) { + chapters = found + .map((c, i) => ({ c, n: numbers[i] ?? Infinity, i })) + .sort((a, b) => a.n - b.n || a.i - b.i) + .map(x => ({ ...x.c, chapterNumber: numbers[x.i] ?? undefined })); + } + + const novel: Plugin.SourceNovel = { + path: novelPath, + name: clean(parseHTML(pages[0].title.rendered).root().text()), + chapters, + }; + const img = $('img').first(); + const cover = img.attr('data-lazy-src') || img.attr('src'); + if (cover) novel.cover = cover; + const summary = $('p') + .filter( + (_, p) => !$(p).find('a').length && clean($(p).text()).length > 40, + ) + .first() + .text() + .trim(); + if (summary) novel.summary = summary; + return novel; + } + + async parseChapter(chapterPath: string): Promise { + const archive = chapterPath.match(/^archives\/(\d+)$/); + let item: WpItem | undefined; + if (archive) { + const url = this.site + 'wp-json/wp/v2/posts/' + archive[1]; + const r = await fetchApi(url); + checkResponse(r, { notFoundCode: PluginError.ChapterNotFound }); + item = (await r.json()) as WpItem; + } else { + const slug = chapterPath.replace(/\/+$/, '').split('/').pop() || ''; + for (const kind of ['pages', 'posts']) { + const found = await this.api( + kind + '?slug=' + encodeURIComponent(slug), + ); + if (found.length === 1) { + item = found[0]; + break; + } + } + } + if (!item?.content?.rendered) { + throw createPluginError(PluginError.ChapterNotFound, { + url: this.site + chapterPath, + }); + } + return item.content.rendered; + } + + resolveUrl = (path: string): string => this.site + path; +} + +export default new TheSunIsColdPlugin(); diff --git a/public/static/src/en/thesuniscold/icon.png b/public/static/src/en/thesuniscold/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..920e22b38517ef04ceae41ac73fef8f795e5c194 GIT binary patch literal 3643 zcmai%^;Z)N7sm%O7%>4qNk0;UF$9#7oRox&5D5us218onAsj7IO3Ua;Ba$Km zX{AG@kpWUK??3RqKivDh=iFcJIXBMz#2FcAgK0Qv00013R|jc)t#50qNxhb$Lr5sk^2sNFM!2SwLRg>7$_ zBR(*j#oeYY6Y70!`l-_5i*_99j(~<)d0mk{3*O11WD9jKxj#uqNYtE3T%BfFSpDM+ z+u_zuu%Vjo=oU5y1#M;q|_w2Zz1 zJdI8P$H=_>X=w?yv?|QW;onfLD;|(pqy6+TtW%e(pA^IkiUcewaGg$dRk8!v@0vMg zpC%?p36fg#gGj4f+IMH?3hy^^dmP&XU0fqvLh1j;ZM>fNW-+7+^+=DbMA*t=GoUga z>o3Yp$8bgi$>m`ZZirWK~vOUKN248cz8@1Ubz_P*R=*Er~8Jh zmC507-C~X74cT@9^(YMmh0AFOqb@m8ZAIMm>qTbX<@abwu>V=K|2Lw{^tux^^ZS=Z zVLub+A;n@1{nNzVR3V=&6tAoVMXkfAE?4P6%Ls9$^(?5|Bh(Fcd)b?^QI�Uf zZdzfo(>eotfZ4tBitEW=2u-e~-Sh8jq5n2ZqrY^Mf*elp`59wy|3_NKx;RtQ>DKy# zXnFCn!Iaa=znd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