Skip to content

Commit

Permalink
fix: luogu route parse error (#14170)
Browse files Browse the repository at this point in the history
* fix route parse error

* use parse-date instead of Date

* optimize decode processes

* fix typo

---------
  • Loading branch information
sakurayang authored Jan 15, 2024
1 parent a1c0e75 commit 4ee4194
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/v2/luogu/daily.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
];

Expand Down

0 comments on commit 4ee4194

Please sign in to comment.