fix: luogu route parse error (#14170)

* fix route parse error

* use parse-date instead of Date

* optimize decode processes

* fix typo

---------
This commit is contained in:
Gerardyang 2024-01-15 11:23:41 +08:00 committed by GitHub
parent a1c0e75542
commit 4ee41944b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -9,19 +9,24 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
const title = $('head title').text();
const firstPost = $('.am-comment-main .am-comment-bd').first();
const dailyLink = firstPost.find('a').first().attr('href');
const issueHeading = firstPost.find('h1').text().trim();
const injectionScript = $('head script:contains("window._feInjection")').text();
const jsonRaw = injectionScript.match(/window\._feInjection = JSON\.parse\(decodeURIComponent\("(.*?)"\)\);/)[1];
const jsonDecode = JSON.parse(decodeURIComponent(jsonRaw));
const mdRaw = jsonDecode.currentData.post.content;
const dailyLink = mdRaw.match(/<([^>]*)>/)[1];
const { data: dailyResponse } = await got(dailyLink);
const $daily = cheerio.load(dailyResponse);
const issueHeading = $daily('.am-article-title').first().text().trim();
const item = [
{
title,
description: $daily('#article-content').html(),
link,
author: firstPost.find('p').eq(1).text(),
author: jsonDecode.currentData.post.author.name,
guid: `${link}#${issueHeading}`,
pubDate: parseDate(issueHeading.match(/(\d{4} 年 \d{1,2} 月 \d{1,2} 日)/)[1], 'YYYY 年 M 月 D 日'),
pubDate: parseDate(jsonDecode.currentData.post.time),
},
];