Skip to content

Commit

Permalink
fix(route): fix route chiculture that can not parse date correctly so…
Browse files Browse the repository at this point in the history
…metimes (DIYgod#12161)

* fix(route): chiculture can not parse date correctly sometimes

* fix: radar target
  • Loading branch information
5upernova-heng authored Mar 23, 2023
1 parent e470fb6 commit 142d307
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3703,7 +3703,7 @@ router.get('/gab/popular/:sort?', lazyloadRouteHandler('./routes/gab/explore'));
router.get('/phrack', lazyloadRouteHandler('./routes/phrack/index'));

// 通識·現代中國
router.get('/chiculture/topic/:category?', lazyloadRouteHandler('./routes/chiculture/topic'));
// router.get('/chiculture/topic/:category?', lazyloadRouteHandler('./routes/chiculture/topic'));

// CQUT News
router.get('/cqut/news', lazyloadRouteHandler('./routes/universities/cqut/cqut-news'));
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/chiculture/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/topic/:category?': ['nczitzk'],
};
16 changes: 16 additions & 0 deletions lib/v2/chiculture/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
'chiculture.org.hk': {
_name: '通識・現代中國',
'.': [
{
title: '議題熱話',
docs: 'https://docs.rsshub.app/new-media.html#tong-shi-・-xian-dai-zhong-guo',
source: ['/tc/hot-topics'],
target: (_, url) => {
const searchParams = new URL(url).searchParams;
return `/chiculture${searchParams.has('category') ? `/${searchParams.get('category')}` : ''}`;
},
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/chiculture/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/topic/:category?', require('./topic'));
};
12 changes: 7 additions & 5 deletions lib/routes/chiculture/topic.js → lib/v2/chiculture/topic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const got = require('@/utils/got');
const date = require('@/utils/date');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const category = ctx.params.category || '';
Expand All @@ -15,7 +16,7 @@ module.exports = async (ctx) => {
const list = response.data.data.map((item) => ({
title: item.title,
pubDate: item.tags,
link: `${rootUrl}/${item.url}`,
link: `${rootUrl}${item.url}`,
}));

const items = await Promise.all(
Expand All @@ -30,16 +31,17 @@ module.exports = async (ctx) => {
const pubDate = detailResponse.data.match(/上載日期:(.*)<\/p>/);

if (pubDate) {
item.pubDate = date(pubDate[1]);
item.pubDate = parseDate(pubDate[1]);
} else if (item.title.indexOf('一周時事通識') > -1) {
for (const tag of item.pubDate) {
if (tag.title.match(/^\d{4}年$/)) {
item.pubDate = date(`${tag.title.replace('年', '')}-${item.title.replace(//g, '').split('- ')[1].split('/').reverse().join('-')}`);
const monthDayStr = item.title.split('- ')[1] ? item.title.split('- ')[1] : item.title.split('-')[1];
item.pubDate = timezone(parseDate(monthDayStr, 'D/M'), +8);
break;
}
}
} else if (item.title.match(/^\d{4}年新聞回顧$/)) {
item.pubDate = date(`${item.title.split('年')[0]}-12-31`);
item.pubDate = parseDate(`${item.title.split('年')[0]}-12-31`);
} else {
item.pubDate = '';
}
Expand Down

0 comments on commit 142d307

Please sign in to comment.