Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Dec 2, 2023
2 parents ad795b1 + 082bb3d commit ef07cfa
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 49 deletions.
6 changes: 4 additions & 2 deletions lib/v2/brave/latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ module.exports = async (ctx) => {

const title = item.text();
const device = item.parent().find('h2').text();
const matchVersion = title.match(/(v[\d.]+)/);
const matchDate = title.match(/\((.*?)\)/);

return {
title: `[${device}] ${title}`,
link: currentUrl,
guid: `${currentUrl}#${device}-${title.match(/(v[\d.]+)/)[1]}`,
guid: `${currentUrl}#${device}-${matchVersion?.[1] ?? title}`,
description: item.next().html(),
pubDate: parseDate(title.match(/\((.*?)\)/)[1].replace(/(st|nd|rd|th)?,/, ''), ['MMMM D YYYY', 'MMM D YYYY']),
pubDate: parseDate(matchDate?.[1].replace(/(st|nd|rd|th)?,/, ''), ['MMMM D YYYY', 'MMM D YYYY']),
};
});

Expand Down
1 change: 1 addition & 0 deletions lib/v2/cna/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
'/:id?': ['nczitzk'],
'/web/:id?': ['dzx-dzx'],
};
6 changes: 6 additions & 0 deletions lib/v2/cna/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ module.exports = {
source: ['/list/:id', '/topic/newstopic/:id'],
target: (params) => `/cna/${params.id.replace('.aspx', '')}`,
},
{
title: '分类(网页爬虫方法)',
docs: 'https://docs.rsshub.app/routes/traditional-media#zhong-yang-tong-xun-she',
source: ['/list/:id'],
target: (params) => `/cna/web/${params.id.replace('.aspx', '')}`,
},
],
},
};
1 change: 1 addition & 0 deletions lib/v2/cna/router.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = (router) => {
router.get('/:id?', require('./'));
router.get('/web/:id?', require('./web/'));
};
62 changes: 62 additions & 0 deletions lib/v2/cna/web/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const id = ctx.params.id || 'aall';

let rootUrl;

if (/^\d+$/.test(id)) {
rootUrl = `https://www.cna.com.tw/topic/newstopic/${id}.aspx`;
} else {
rootUrl = `https://www.cna.com.tw/list/${id}.aspx`;
}
const response = await got({
method: 'get',
url: rootUrl,
});

const $ = cheerio.load(response.data);
const list = $('*:is(.pcBox .caItem, .mainList li a div) h2')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 10)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.parents('a').attr('href'),
pubDate: timezone(parseDate(item.next().text()), +8),
};
});

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const topImage = content('.fullPic').html();

item.description = (topImage === null ? '' : topImage) + content('.paragraph').eq(0).html();
item.category = [
...content("meta[property='article:tag']")
.get()
.map((e) => e.attribs.content),
content('.active > a').text(),
];

return item;
})
)
);

ctx.state.data = {
title: $('title').text(),
link: rootUrl,
item: items,
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
"lint-staged": "15.1.0",
"mockdate": "3.0.5",
"nock": "13.4.0",
"nodemon": "3.0.1",
"nodemon": "3.0.2",
"prettier": "3.1.0",
"remark": "13.0.0",
"remark-frontmatter": "3.0.0",
Expand Down
Loading

0 comments on commit ef07cfa

Please sign in to comment.