Files
RSSHub/lib/v2/luogu/daily.js
Gerardyang 04d421b1f4 fix(route): fix luogu route date parse regex (#11200)
* fix(route): fix luogu route date parse regex

```
text:       "洛谷日报 第 417 期 2022 年 11 月 1 日"
regex:                                     \d{4} 年 \d{2} 月 \d{2} 日
                                                                              ^
                                                                       error here
```

* change DD to D and MM to M in date format.

* fix regex to match month which is before Oct
2022-11-04 19:17:45 +09:00

34 lines
1.1 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id ?? 47327;
const link = `https://www.luogu.com.cn/discuss/${id}`;
const response = await got(link);
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 { data: dailyResponse } = await got(dailyLink);
const $daily = cheerio.load(dailyResponse);
const item = [
{
title,
description: $daily('#article-content').html(),
link,
author: firstPost.find('p').eq(1).text(),
guid: `${link}#${issueHeading}`,
pubDate: parseDate(issueHeading.match(/(\d{4} 年 \d{1,2} 月 \d{1,2} 日)/)[1], 'YYYY 年 M 月 D 日'),
},
];
ctx.state.data = {
title: '洛谷日报',
link,
item,
};
};