fix(route): 本地宝焦点资讯 (#8889)
This commit is contained in:
parent
2d9cf45fad
commit
ae051c95cf
|
|
@ -2866,7 +2866,7 @@ router.get('/ptpress/book/:type?', lazyloadRouteHandler('./routes/ptpress/book')
|
|||
router.get('/uniqlo/stylingbook/:category?', lazyloadRouteHandler('./routes/uniqlo/stylingbook'));
|
||||
|
||||
// 本地宝焦点资讯
|
||||
router.get('/bendibao/news/:city', lazyloadRouteHandler('./routes/bendibao/news'));
|
||||
// router.get('/bendibao/news/:city', lazyloadRouteHandler('./routes/bendibao/news'));
|
||||
|
||||
// unit-image
|
||||
router.get('/unit-image/films/:type?', lazyloadRouteHandler('./routes/unit-image/films'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/news/:city': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -1,12 +1,16 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const city = ctx.params.city;
|
||||
|
||||
const rootUrl = `http://${city}.bendibao.com`;
|
||||
|
||||
let response = await got({
|
||||
method: 'get',
|
||||
url: `http://${city}.bendibao.com/`,
|
||||
url: rootUrl,
|
||||
});
|
||||
|
||||
let $ = cheerio.load(response.data);
|
||||
|
|
@ -15,15 +19,18 @@ module.exports = async (ctx) => {
|
|||
.text()
|
||||
.replace(/-爱上本地宝,生活会更好/, '') + `焦点资讯`;
|
||||
|
||||
let list = $('ul.focus-news li')
|
||||
.map((_, item) => {
|
||||
let items = $('ul.focus-news li')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item).find('a');
|
||||
|
||||
const link = item.attr('href');
|
||||
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
link: link.indexOf('http') === 0 ? link : `${rootUrl}${link}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
});
|
||||
|
||||
// Cities share 2 sets of ui.
|
||||
//
|
||||
|
|
@ -32,7 +39,7 @@ module.exports = async (ctx) => {
|
|||
//
|
||||
// Go to /news to fetch data for the eg2 case.
|
||||
|
||||
if (!list.length) {
|
||||
if (!items.length) {
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: `http://${city}.bendibao.com/news`,
|
||||
|
|
@ -40,37 +47,47 @@ module.exports = async (ctx) => {
|
|||
|
||||
$ = cheerio.load(response.data);
|
||||
|
||||
list = $('#listNewsTimeLy div.info')
|
||||
.map((_, item) => {
|
||||
items = $('#listNewsTimeLy div.info')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item).find('a');
|
||||
|
||||
const link = item.attr('href');
|
||||
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
link: link.indexOf('http') === 0 ? link : `${rootUrl}${link}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
});
|
||||
}
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
try {
|
||||
const detailResponse = await got({ method: 'get', url: item.link });
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
// Some links lead to mobile-view pages.
|
||||
// eg. http://m.bj.bendibao.com/news/273517.html
|
||||
// Divs for contents are different from which in desktop-view pages.
|
||||
|
||||
item.description = content('div.content').html() || content('div.content-box').html();
|
||||
item.description = content('div.content').html() ?? content('div.content-box').html();
|
||||
|
||||
// Spans for publish dates are the same cases as above.
|
||||
|
||||
item.pubDate = new Date(
|
||||
(content('span.time')
|
||||
.text()
|
||||
.replace(/发布时间:/, '') || content('span.public_time').text()) + ' GMT+8'
|
||||
).toUTCString();
|
||||
item.pubDate = timezone(
|
||||
parseDate(
|
||||
content('span.time')
|
||||
.text()
|
||||
.replace(/发布时间:/, '') ?? content('span.public_time').text()
|
||||
),
|
||||
+8
|
||||
);
|
||||
|
||||
return item;
|
||||
} catch (e) {
|
||||
|
|
@ -82,7 +99,7 @@ module.exports = async (ctx) => {
|
|||
|
||||
ctx.state.data = {
|
||||
title,
|
||||
link: `http://${city}.bendibao.com/`,
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'bendibao.com': {
|
||||
_name: '本地宝',
|
||||
'.': [
|
||||
{
|
||||
title: '焦点资讯',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#ben-di-bao-jiao-dian-zi-xun',
|
||||
source: '/',
|
||||
target: '/bendibao/news/:city',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/news/:city', require('./news'));
|
||||
};
|
||||
Loading…
Reference in New Issue