mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route): add Line Today (#8311)
This commit is contained in:
@@ -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']"/>
|
||||
|
||||
@@ -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']"/>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/today/:edition?/:tab?': ['nczitzk'],
|
||||
};
|
||||
@@ -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?',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/today/:edition?/:tab?', require('./today'));
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user