fix(route): hk01 get fulltext and refactor to V2 (#9937)
* fix(route): hk01 get fulltext and refactor to V2 * Update lib/v2/hk01/channel.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/v2/hk01/issue.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix: teaser pubDate
This commit is contained in:
@@ -1528,23 +1528,23 @@ category 对应的关键词有
|
||||
|
||||
### 热门
|
||||
|
||||
<Route author="hoilc" example="/hk01/hot" path="/hk01/hot" radar="1" rssbud="1"/>
|
||||
<Route author="hoilc Fatpandac" example="/hk01/hot" path="/hk01/hot" radar="1" rssbud="1"/>
|
||||
|
||||
### 栏目
|
||||
|
||||
<Route author="hoilc" example="/hk01/zone/11" path="/hk01/zone/:id" :paramsDesc="['栏目 id, 可在 URL 中找到']" radar="1" rssbud="1"/>
|
||||
<Route author="hoilc Fatpandac" example="/hk01/zone/11" path="/hk01/zone/:id" :paramsDesc="['栏目 id, 可在 URL 中找到']" radar="1" rssbud="1"/>
|
||||
|
||||
### 子栏目
|
||||
|
||||
<Route author="hoilc" example="/hk01/channel/391" path="/hk01/channel/:id" :paramsDesc="['子栏目 id, 可在 URL 中找到']" radar="1" rssbud="1"/>
|
||||
<Route author="hoilc Fatpandac" example="/hk01/channel/391" path="/hk01/channel/:id" :paramsDesc="['子栏目 id, 可在 URL 中找到']" radar="1" rssbud="1"/>
|
||||
|
||||
### 专题
|
||||
|
||||
<Route author="hoilc" example="/hk01/issue/649" path="/hk01/issue/:id" :paramsDesc="['专题 id, 可在 URL 中找到']" radar="1" rssbud="1"/>
|
||||
<Route author="hoilc Fatpandac" example="/hk01/issue/649" path="/hk01/issue/:id" :paramsDesc="['专题 id, 可在 URL 中找到']" radar="1" rssbud="1"/>
|
||||
|
||||
### 标签
|
||||
|
||||
<Route author="hoilc" example="/hk01/tag/2787" path="/hk01/tag/:id" :paramsDesc="['标签 id, 可在 URL 中找到']" radar="1" rssbud="1"/>
|
||||
<Route author="hoilc Fatpandac" example="/hk01/tag/2787" path="/hk01/tag/:id" :paramsDesc="['标签 id, 可在 URL 中找到']" radar="1" rssbud="1"/>
|
||||
|
||||
## 香港電台
|
||||
|
||||
|
||||
@@ -1589,41 +1589,6 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
},
|
||||
'hk01.com': {
|
||||
_name: '香港01',
|
||||
www: [
|
||||
{
|
||||
title: '最 Hit',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
|
||||
source: ['/hot', '/'],
|
||||
target: '/hk01/hot',
|
||||
},
|
||||
{
|
||||
title: 'zone',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
|
||||
source: '/zone/:id/:title',
|
||||
target: '/hk01/zone/:id',
|
||||
},
|
||||
{
|
||||
title: 'channel',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
|
||||
source: '/channel/:id/:title',
|
||||
target: '/hk01/channel/:id',
|
||||
},
|
||||
{
|
||||
title: 'issue',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
|
||||
source: '/issue/:id/:title',
|
||||
target: '/hk01/issue/:id',
|
||||
},
|
||||
{
|
||||
title: 'tag',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
|
||||
source: '/tag/:id/:title',
|
||||
target: '/hk01/tag/:id',
|
||||
},
|
||||
],
|
||||
},
|
||||
'popiapp.cn': {
|
||||
_name: 'Popi 提问箱',
|
||||
www: [
|
||||
|
||||
+5
-5
@@ -2201,11 +2201,11 @@ router.get('/mcbbs/post/:tid/:authorid?', lazyloadRouteHandler('./routes/mcbbs/p
|
||||
router.get('/pocket/trending', lazyloadRouteHandler('./routes/pocket/trending'));
|
||||
|
||||
// HK01
|
||||
router.get('/hk01/zone/:id', lazyloadRouteHandler('./routes/hk01/zone'));
|
||||
router.get('/hk01/channel/:id', lazyloadRouteHandler('./routes/hk01/channel'));
|
||||
router.get('/hk01/issue/:id', lazyloadRouteHandler('./routes/hk01/issue'));
|
||||
router.get('/hk01/tag/:id', lazyloadRouteHandler('./routes/hk01/tag'));
|
||||
router.get('/hk01/hot', lazyloadRouteHandler('./routes/hk01/hot'));
|
||||
// router.get('/hk01/zone/:id', lazyloadRouteHandler('./routes/hk01/zone'));
|
||||
// router.get('/hk01/channel/:id', lazyloadRouteHandler('./routes/hk01/channel'));
|
||||
// router.get('/hk01/issue/:id', lazyloadRouteHandler('./routes/hk01/issue'));
|
||||
// router.get('/hk01/tag/:id', lazyloadRouteHandler('./routes/hk01/tag'));
|
||||
// router.get('/hk01/hot', lazyloadRouteHandler('./routes/hk01/hot'));
|
||||
|
||||
// 码农周刊
|
||||
router.get('/manong-weekly', lazyloadRouteHandler('./routes/manong-weekly/issues'));
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const response = await got(`https://web-data.api.hk01.com/v2/page/category/${id}`);
|
||||
const data = response.data;
|
||||
const list = data.sections[0].items;
|
||||
|
||||
ctx.state.data = {
|
||||
title: `香港01 - ${data.category.publishName}`,
|
||||
description: data.meta.metaDesc,
|
||||
link: data.category.publishUrl,
|
||||
item: list.map((item) => ({
|
||||
title: item.data.title,
|
||||
author: item.data.authors && item.data.authors.map((e) => e.publishName).join(', '),
|
||||
description: `<p>${item.data.description}…</p><img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`,
|
||||
pubDate: new Date(item.data.lastModifyTime * 1000),
|
||||
link: item.data.canonicalUrl,
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const response = await got(`https://web-data.api.hk01.com/v2/page/issue/${id}`);
|
||||
const data = response.data;
|
||||
const list = data.issue.blocks[0].articles;
|
||||
|
||||
ctx.state.data = {
|
||||
title: `香港01 - ${data.issue.title}`,
|
||||
description: data.meta.metaDesc,
|
||||
link: data.issue.publishUrl,
|
||||
item: list.map((item) => ({
|
||||
title: item.data.title,
|
||||
author: item.data.authors && item.data.authors.map((e) => e.publishName).join(', '),
|
||||
description: `<p>${item.data.description}…</p><img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`,
|
||||
pubDate: new Date(item.data.lastModifyTime * 1000),
|
||||
link: item.data.canonicalUrl,
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const response = await got(`https://web-data.api.hk01.com/v2/page/category/${id}`);
|
||||
const data = response.data;
|
||||
const list = data.sections[0].items;
|
||||
|
||||
await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(`https://www.hk01.com/${item.data.mainCategory}/${item.data.articleId}`, async () => {
|
||||
const detailResponse = await got(item.data.canonicalUrl);
|
||||
const $ = cheerio.load(detailResponse.data);
|
||||
|
||||
$('article > div.view-tracker').remove();
|
||||
$('article > div.flex.flex-col').remove();
|
||||
|
||||
item.data.description = $('article').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `香港01 - ${data.category.publishName}`,
|
||||
description: data.meta.metaDesc,
|
||||
link: data.category.publishUrl,
|
||||
item: list.map((item) => ({
|
||||
title: item.data.title,
|
||||
author: item.data.authors && item.data.authors.map((e) => e.publishName).join(', '),
|
||||
description: `<p>${item.data.description}</p><img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`,
|
||||
pubDate: parseDate(item.data.lastModifyTime * 1000),
|
||||
link: item.data.canonicalUrl,
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await got('https://web-data.api.hk01.com/v2/page/hot/');
|
||||
@@ -13,7 +14,7 @@ module.exports = async (ctx) => {
|
||||
title: item.data.title,
|
||||
author: item.data.authors && item.data.authors.map((e) => e.publishName).join(', '),
|
||||
description: `<p>${item.data.description}</p><img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`,
|
||||
pubDate: new Date(item.data.lastModifyTime * 1000),
|
||||
pubDate: parseDate(item.data.lastModifyTime * 1000),
|
||||
link: item.data.canonicalUrl,
|
||||
})),
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const response = await got(`https://web-data.api.hk01.com/v2/page/issue/${id}`);
|
||||
const data = response.data;
|
||||
const list = data.issue.blocks[0].articles;
|
||||
|
||||
await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(`https://www.hk01.com/${item.data.mainCategory}/${item.data.articleId}`, async () => {
|
||||
const detailResponse = await got(item.data.canonicalUrl);
|
||||
const $ = cheerio.load(detailResponse.data);
|
||||
|
||||
$('div.lazyload-placeholder').remove();
|
||||
$('article > div.view-tracker').remove();
|
||||
$('article > div.flex.flex-col').remove();
|
||||
|
||||
item.data.description = $('article').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `香港01 - ${data.issue.title}`,
|
||||
description: data.meta.metaDesc,
|
||||
link: data.issue.publishUrl,
|
||||
item: list.map((item) => ({
|
||||
title: item.data.title,
|
||||
author: item.data.authors && item.data.authors.map((e) => e.publishName).join(', '),
|
||||
description: `<img style="width: 100%" src="${item.data.mainImage.cdnUrl}" /><p>${item.data.description}</p>`,
|
||||
pubDate: parseDate(item.data.lastModifyTime * 1000),
|
||||
link: item.data.canonicalUrl,
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
'/channel/:id': ['hoilc', 'Fatpandac'],
|
||||
'/hot': ['hoilc', 'Fatpandac'],
|
||||
'/issue/:id': ['hoilc', 'Fatpandac'],
|
||||
'/tag/:id': ['hoilc', 'Fatpandac'],
|
||||
'/zone/:id': ['hoilc', 'Fatpandac'],
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
module.exports = {
|
||||
'hk01.com': {
|
||||
_name: '香港01',
|
||||
www: [
|
||||
{
|
||||
title: '最 Hit',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
|
||||
source: ['/hot', '/'],
|
||||
target: '/hk01/hot',
|
||||
},
|
||||
{
|
||||
title: 'zone',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
|
||||
source: '/zone/:id/:title',
|
||||
target: '/hk01/zone/:id',
|
||||
},
|
||||
{
|
||||
title: 'channel',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
|
||||
source: '/channel/:id/:title',
|
||||
target: '/hk01/channel/:id',
|
||||
},
|
||||
{
|
||||
title: 'issue',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
|
||||
source: '/issue/:id/:title',
|
||||
target: '/hk01/issue/:id',
|
||||
},
|
||||
{
|
||||
title: 'tag',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
|
||||
source: '/tag/:id/:title',
|
||||
target: '/hk01/tag/:id',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/channel/:id', require('./channel'));
|
||||
router.get('/hot', require('./hot'));
|
||||
router.get('/issue/:id', require('./issue'));
|
||||
router.get('/tag/:id', require('./tag'));
|
||||
router.get('/zone/:id', require('./zone'));
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
@@ -15,7 +16,7 @@ module.exports = async (ctx) => {
|
||||
title: item.data.title,
|
||||
author: item.data.authors && item.data.authors.map((e) => e.publishName).join(', '),
|
||||
description: `<p>${item.data.description}</p><img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`,
|
||||
pubDate: new Date(item.data.lastModifyTime * 1000),
|
||||
pubDate: parseDate(item.data.lastModifyTime * 1000),
|
||||
link: item.data.canonicalUrl,
|
||||
})),
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
@@ -19,12 +20,12 @@ module.exports = async (ctx) => {
|
||||
case 1:
|
||||
author = item.data.authors && item.data.authors.map((e) => e.publishName).join(', ');
|
||||
description = `<p>${item.data.description}</p><img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`;
|
||||
pubDate = new Date(item.data.lastModifyTime * 1000);
|
||||
pubDate = parseDate(item.data.lastModifyTime * 1000);
|
||||
break;
|
||||
case 2:
|
||||
author = item.data.zonePublishName;
|
||||
description = `${item.data.teaser.map((e) => '<p>' + e + '</p>').join('')}<img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`;
|
||||
pubDate = new Date();
|
||||
pubDate = parseDate(item.data.lastModifyTime * 1000);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
Reference in New Issue
Block a user