Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: luogu route parse error #14170

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 josnRaw = injectionScript.match(/window\._feInjection = JSON\.parse\(decodeURIComponent\("(.*?)"\)\);/)[1];
const jsonDecode = JSON.parse(decodeURIComponent(josnRaw));
sakurayang marked this conversation as resolved.
Show resolved Hide resolved

const mdRaw = jsonDecode.currentData.post.content;

const dailyLink = mdRaw.match(/<([^>]*)>/)[1];
sakurayang marked this conversation as resolved.
Show resolved Hide resolved
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