fix: 本地宝保留旧页面样式的城市资讯 (#4635)

This commit is contained in:
Ethan Shen
2020-05-02 12:59:45 +08:00
committed by GitHub
parent 7307928e8b
commit 3cd7beccc2
2 changed files with 38 additions and 8 deletions
+3 -1
View File
@@ -336,7 +336,7 @@ Supported sub-sites
### 焦点资讯
<Route author="nczitzk" example="/bendibao/news/bj" path="/bendibao/news/:city" :paramsDesc="['城市缩写']">
<Route author="nczitzk" example="/bendibao/news/bj" path="/bendibao/news/:city" :paramsDesc="['城市缩写,可在该城市页面的 URL 中找到']">
| 城市名 | 缩写 |
| ------ | ---- |
@@ -347,6 +347,8 @@ Supported sub-sites
更多城市请参见 [这里](http://www.bendibao.com/city.htm)
> **香港特别行政区** 和 **澳门特别行政区** 的本地宝城市页面不更新资讯。
</Route>
## 币世界
+35 -7
View File
@@ -4,13 +4,18 @@ const cheerio = require('cheerio');
module.exports = async (ctx) => {
const city = ctx.params.city;
const response = await got({
let response = await got({
method: 'get',
url: `http://${city}.bendibao.com/`,
});
const $ = cheerio.load(response.data);
const list = $('ul.focus-news li')
let $ = cheerio.load(response.data);
const title =
$('title')
.text()
.replace(/-爱上本地宝,生活会更好/, '') + `焦点资讯`;
let list = $('ul.focus-news li')
.map((_, item) => {
item = $(item).find('a');
return {
@@ -20,6 +25,32 @@ module.exports = async (ctx) => {
})
.get();
// Cities share 2 sets of ui.
//
// eg1. http://bj.bendibao.com/
// eg2. http://kel.bendibao.com/
//
// Go to /news to fetch data for the eg2 case.
if (!list.length) {
response = await got({
method: 'get',
url: `http://${city}.bendibao.com/news`,
});
$ = cheerio.load(response.data);
list = $('#listNewsTimeLy div.info')
.map((_, item) => {
item = $(item).find('a');
return {
title: item.text(),
link: item.attr('href'),
};
})
.get();
}
const items = await Promise.all(
list.map(
async (item) =>
@@ -42,10 +73,7 @@ module.exports = async (ctx) => {
);
ctx.state.data = {
title:
$('title')
.text()
.replace(/-爱上本地宝,生活会更好/, '') + `焦点资讯`,
title: title,
link: `http://${city}.bendibao.com/`,
item: items,
};