fix: date parsing bug in jwc.ts (#15326)

* 添加了新的RSSHub路由,支持Radar ,以及修改了对应的文档

新增了针对南昌大学教务处通知的RSSHub路由,支持Radar。
同时修改了RSShub文档

* Removed redundant settings and fixed the year.

删去了多余的代码,更正了正确的年份

* 修改radar.js来修复问题

原来的radar无法正确识别网站,原来是url错误了,现在已经更改

* Update jwc.js

* Refactor jwc.ts and remove unused files

* Update dependencies

* Refactor jwc.ts and remove unused files

* Refactor jwc.ts and update newsDate calculation

* Optimized date retrieval code: consolidated year and month retrieval into a single line

* style: auto format

* Refactor jwc.ts: Consolidate date retrieval code

* Revert "Refactor jwc.ts: Consolidate date retrieval code"

This reverts commit 353f70745cff2eff950d115a518b9f5750a4b1c7.

* Revert "Optimized date retrieval code: consolidated year and month retrieval into a single line"

This reverts commit e38bc31ab412b79842e74b8c86a1fe39277e2ca4.

* Refactor jwc.ts: Consolidate date retrieval code and optimize newsDate calculation

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
teapot1de 2024-04-23 18:15:56 +08:00 committed by GitHub
parent 7c8239b20a
commit d2e8cd65c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 2 deletions

View File

@ -31,6 +31,9 @@ async function handler() {
const baseUrl = 'https://jwc.ncu.edu.cn';
const response = await got(baseUrl);
const $ = load(response.body);
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const currentMonth = currentDate.getMonth() + 1;
const list = $('.box3 .inner ul.img-list li');
@ -38,6 +41,7 @@ async function handler() {
title: '南昌大学教务处',
link: baseUrl,
description: '南昌大学教务处',
item:
list &&
list.toArray().map((item) => {
@ -46,12 +50,19 @@ async function handler() {
const date = el.text().split('】')[0].replace('【', '').trim();
const title = linkEl.attr('title');
const link = `${baseUrl}/${linkEl.attr('href')}`;
const month = date.slice(0, 2);
const newsDate = parseDate(date, 'MM-DD');
const newsMonth = newsDate.getMonth() + 1;
// If the news month is greater than the current month, subtract 1 from the year
const year = newsMonth > currentMonth ? currentYear - 1 : currentYear;
newsDate.setFullYear(year);
return {
title,
link,
pubDate: parseDate(date, 'MM-DD').setFullYear(month < 6 ? new Date().getFullYear() - 1 : new Date().getFullYear()),
pubDate: newsDate,
};
}),
};