RainofSnow: Manual Date Parse (#1160)

* manual date parse

* optimize regex

* remove s spaces

* superfast

* even faster
This commit is contained in:
K1ngfish3r
2024-08-22 22:53:59 +08:00
committed by GitHub
parent 34b32cd5e7
commit ee126b20d8
+30 -8
View File
@@ -9,7 +9,7 @@ class Rainofsnow implements Plugin.PagePlugin {
name = 'Rainofsnow'; name = 'Rainofsnow';
icon = 'src/en/rainofsnow/icon.png'; icon = 'src/en/rainofsnow/icon.png';
site = 'https://rainofsnow.com/'; site = 'https://rainofsnow.com/';
version = '1.1.0'; version = '1.1.1';
parseNovels(loadedCheerio: CheerioAPI) { parseNovels(loadedCheerio: CheerioAPI) {
const novels: Plugin.NovelItem[] = []; const novels: Plugin.NovelItem[] = [];
@@ -97,18 +97,40 @@ class Rainofsnow implements Plugin.PagePlugin {
const chapter: Plugin.ChapterItem[] = []; const chapter: Plugin.ChapterItem[] = [];
loadedCheerio('#chapter .march1 li').each((i, el) => { loadedCheerio('#chapter .march1 li').each((i, el) => {
const name = loadedCheerio(el).find('.chapter').first().text().trim();
const releaseTime = new Date(
loadedCheerio(el).find('small').text().trim(),
).toISOString();
const path = loadedCheerio(el) const path = loadedCheerio(el)
.find('a') .find('a')
.attr('href') .attr('href')
?.slice(this.site.length); ?.slice(this.site.length);
if (!path) return;
const name = loadedCheerio(el).find('.chapter').first().text().trim();
const date = loadedCheerio(el).find('small').text().trim().toLowerCase();
const months = [
'jan',
'feb',
'mar',
'apr',
'may',
'jun',
'jul',
'aug',
'sep',
'oct',
'nov',
'dec',
];
const regex = /([a-z]+) (..?), (.+)/;
const [, monthName, day, year] = regex.exec(date) || [];
const month = months.indexOf(monthName.slice(0, 3));
const releaseTime =
monthName && month !== -1
? new Date(+year, month, +day).toISOString()
: null;
if (path && name) { chapter.push({
chapter.push({ name, path, releaseTime }); name,
} path,
releaseTime,
});
}); });
return chapter; return chapter;