feat(route): add Line Today (#8311)

This commit is contained in:
Ethan Shen
2022-01-22 16:03:12 +00:00
committed by GitHub
parent 97c076256b
commit c68b131772
6 changed files with 127 additions and 0 deletions
+14
View File
@@ -385,6 +385,20 @@ Provides a better reading experience (full text articles) over the official one.
<RouteEn author="loganrockmore" example="/letterboxd/user/followingdiary/demiadejuyigbe" path="/letterboxd/user/followingdiary/:username" :paramsDesc="['username']" />
## Line
### Today
<RouteEn author="nczitzk" example="/line/today" path="/line/today/:edition?/:tab?" :paramsDesc="['Edition, see below, Taiwan by default', 'Tag, can be found in URL, top by default']">
Edition
| Taiwan | Thailand | Indonesia | Hong Kong |
| ------ | -------- | --------- | --------- |
| tw | th | id | hk |
</RouteEn>
## MakeUseOf
<RouteEn author="nczitzk" example="/makeuseof" path="/makeuseof/:category?" :paramsDesc="['Category, Trending by default']"/>
+14
View File
@@ -627,6 +627,20 @@ Tag
<Route author="loganrockmore" example="/letterboxd/user/followingdiary/demiadejuyigbe" path="/letterboxd/user/followingdiary/:username" :paramsDesc="['username']" />
## Line
### Today
<Route author="nczitzk" example="/line/today" path="/line/today/:edition?/:tab?" :paramsDesc="['版本,见下表,默认为 Taiwan', '标签, 可在对应标签页的地址中找到, 默认为 top']">
Edition
| Taiwan | Thailand | Indonesia | Hong Kong |
| ------ | -------- | --------- | --------- |
| tw | th | id | hk |
</Route>
## MakeUseOf
<Route author="nczitzk" example="/makeuseof" path="/makeuseof/:category?" :paramsDesc="['分类,默认为 Trending']"/>
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/today/:edition?/:tab?': ['nczitzk'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'line.me': {
_name: 'LINE Today',
'.': [
{
title: 'LINE Today',
docs: 'https://docs.rsshub.app/new-media.html#line-today',
source: ['/'],
target: '/line/today/:edition?/:tab?',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/today/:edition?/:tab?', require('./today'));
};
+80
View File
@@ -0,0 +1,80 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const edition = ctx.params.edition || 'tw';
const tab = ctx.params.tab || 'top';
const rootUrl = 'https://today.line.me';
const tabUrl = `${rootUrl}/api/v6/portals/${edition}/page/${tab}`;
const recommendationUrl = `${rootUrl}/webapi/api/v6/recommendation/articles/listings/mytoday_rec:id?offset=0&length=50&country=${edition}&gender=&age=&excludeNoThumbnail=0&containMainSnapshot=0`;
const currentUrl = `${rootUrl}/${edition}/v2/tab/${tab}`;
let title = 'Recommendation',
moduleUrl;
if (tab !== 'recommendation') {
const moduleResponse = await got({
method: 'get',
url: tabUrl,
});
const listing = moduleResponse.data.modules.filter((item) => item.source === 'CATEGORY_MOST_VIEW')[0].listings[0];
title = moduleResponse.data.name;
moduleUrl =
`${rootUrl}/webapi/trending/category/mostView/listings/${listing.id}?` +
`offset=0&length=50&country=${edition}&targetContent=${listing.params.targetContent}` +
`&categories=${listing.params.categories}&trendingEventPeriod=${listing.params.trendingEventPeriod}`;
}
const response = await got({
method: 'get',
url: tab === 'recommendation' ? recommendationUrl : moduleUrl,
});
const list = response.data.items.map((item) => ({
title: item.title,
link: `${rootUrl}/${edition}/v2/article/${item.url.hash}`,
pubDate: parseDate(item.publishTimeUnix),
}));
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);
content('img').each(function () {
content(this).parent().find('.placeholder').remove();
content(this).attr('src', content(this).attr('data-src').replace('w644', 'w1200'));
content(this).removeAttr('data-src');
content(this).removeAttr('data-srcset');
});
content('iframe').each(function () {
content(this).attr('src', content(this).attr('data-src'));
content(this).removeAttr('data-src');
});
item.description = content('.articleContent').html();
item.author = content('meta[property="author"]').attr('content');
return item;
})
)
);
ctx.state.data = {
title: `${title} - Line Today`,
link: currentUrl,
item: items,
};
};