fix(route): zaker wrong link (#8776)

This commit is contained in:
Tony
2022-01-23 03:24:12 +07:00
committed by GitHub
parent 2aa347d1a7
commit f2a2d11268
8 changed files with 96 additions and 141 deletions

View File

@@ -1120,17 +1120,13 @@ Supported sub-sites:
## ZAKER
### source
### 分类
<Route author="LogicJake" example="/zaker/source/12291" path="/zaker/source/:id" :paramsDesc="['source id可在 URL 中找到']"/>
### channel
<Route author="kt286" example="/zaker/channel/13" path="/zaker/source/:id" :paramsDesc="['channel id可在 URL 中找到']"/>
<Route author="LogicJake kt286 TonyRL" example="/zaker/channel/13" path="/zaker/channel/:id?" :paramsDesc="['channel id可在 URL 中找到,默认为 1']"/>
### 精读
<Route author="AlexdanerZe" example="/zaker/focusread" path="/zaker/focusread" />
<Route author="AlexdanerZe TonyRL" example="/zaker/focusread" path="/zaker/focusread" />
## 爱范儿 ifanr

View File

@@ -1606,9 +1606,9 @@ router.get('/checkee/:dispdate', lazyloadRouteHandler('./routes/checkee/index'))
// 艾瑞
router.get('/iresearch/report', lazyloadRouteHandler('./routes/iresearch/report'));
// ZAKER
router.get('/zaker/:type/:id', lazyloadRouteHandler('./routes/zaker/source'));
router.get('/zaker/focusread', lazyloadRouteHandler('./routes/zaker/focusread'));
// ZAKER migrated to v2
// router.get('/zaker/:type/:id', lazyloadRouteHandler('./routes/zaker/source'));
// router.get('/zaker/focusread', lazyloadRouteHandler('./routes/zaker/focusread'));
// Matters
router.get('/matters/latest/:type?', lazyloadRouteHandler('./routes/matters/latest'));

View File

@@ -1,65 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseRelativeDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const link = `http://www.myzaker.com/?pos=selected_article`;
const response = await got.get(link);
const $ = cheerio.load(response.data);
const title = $('.main-title').text();
const list = $('div.content-block')
.slice(0, 10)
.map(function () {
const info = {
title: $(this).find('.article-title').text(),
link: $(this).find('.article-wrap > a').attr('href'),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const itemUrl = 'http:' + info.link;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
url: itemUrl,
method: 'get',
headers: {
Referer: link,
},
});
const $ = cheerio.load(response.data);
const description = $('div.article_content div').html() || '原文已被删除';
const date = $('span.time').text();
const single = {
title,
link: itemUrl,
description,
pubDate: timezone(parseRelativeDate(date), +8),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
const outfilter = out.filter((t) => t.description !== '原文已被删除');
ctx.state.data = {
title: `${title}-ZAKER精读新闻`,
link,
item: outfilter,
};
};

View File

@@ -1,66 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseRelativeDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const type = ctx.params.type || 'source';
const id = ctx.params.id;
const link = `http://www.myzaker.com/${type}/${id}`;
const response = await got.get(link);
const $ = cheerio.load(response.data);
const title = $('.main-title').text();
const list = $('div.content-block')
.slice(0, 10)
.map(function () {
const info = {
title: $(this).find('.article-title').text(),
link: $(this).find('.article-wrap > a').attr('href'),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const itemUrl = 'http:' + info.link;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
url: itemUrl,
method: 'get',
headers: {
Referer: link,
},
});
const $ = cheerio.load(response.data);
const description = $('div.article_content div').html() || '原文已被删除';
const date = $('span.time').text();
const single = {
title,
link: itemUrl,
description,
pubDate: timezone(parseRelativeDate(date), +8),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `${title}-ZAKER新闻`,
link,
item: out,
};
};

65
lib/v2/zaker/index.js Normal file
View File

@@ -0,0 +1,65 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseRelativeDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const type = ctx.params.type ?? 'channel';
const id = ctx.params.id ?? 1;
const rootUrl = 'http://www.myzaker.com';
const link = type === 'focusread' ? `${rootUrl}/?pos=selected_article` : `${rootUrl}/${type}/${id}`;
const response = await got({
url: link,
headers: {
Referer: rootUrl,
},
});
const $ = cheerio.load(response.data);
const feedTitle = $('head title').text();
let items = $('div.content-block')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.find('.article-title').text(),
link: 'http:' + item.find('.article-wrap > a').attr('href').replace('http://', ''),
};
})
.get();
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const response = await got({
url: item.link,
headers: {
Referer: link,
},
});
const $ = cheerio.load(response.data);
item.description = $('div.article_content div').html() ?? '原文已被删除';
item.author = $('a.article-auther.line').text();
item.category = $('.lebel-list')
.find('a')
.toArray()
.map((item) => $(item).text());
const date = $('span.time').text() ?? undefined;
if (date) {
item.pubDate = timezone(parseRelativeDate(date), +8);
}
return item;
})
)
);
ctx.state.data = {
title: type === 'focusread' ? 'ZAKER 精读新闻' : feedTitle,
link,
item: items.filter((t) => t.description !== '原文已被删除'),
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/:type/:id?': ['LogicJake', 'kt286', 'AlexdanerZe', 'TonyRL'],
};

19
lib/v2/zaker/radar.js Normal file
View File

@@ -0,0 +1,19 @@
module.exports = {
'myzaker.com': {
_name: 'ZAKER',
'.': [
{
title: '分类',
docs: 'https://docs.rsshub.app/new-media.html#zaker',
source: ['/:type/:id'],
target: '/zaker/:type/:id',
},
{
title: '精读',
docs: 'https://docs.rsshub.app/new-media.html#zaker',
source: ['/'],
target: '/zaker/focusread',
},
],
},
};

3
lib/v2/zaker/router.js Normal file
View File

@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:type/:id?', require('./index'));
};