feat: add esquirehk (#6220)
This commit is contained in:
parent
241fc96216
commit
56943d50f0
|
|
@ -156,6 +156,12 @@ pageClass: routes
|
|||
|
||||
</Route>
|
||||
|
||||
## Esquirehk
|
||||
|
||||
### Tag
|
||||
|
||||
<Route author="nczitzk" example="/esquirehk/tag/Fashion" path="/esquirehk/tag/:id" :paramsDesc="['标签,可在对应标签页 URL 中找到']" />
|
||||
|
||||
## GQ
|
||||
|
||||
### GQ 台湾
|
||||
|
|
|
|||
|
|
@ -3512,6 +3512,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
|
|||
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
|
||||
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
|
||||
|
||||
// Esquirehk
|
||||
router.get('/esquirehk/tag/:id', require('./routes/esquirehk/tag'));
|
||||
|
||||
// 国家普通话测试 杭州市
|
||||
router.get('/putonghua', require('./routes/putonghua/hangzhou'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let id = ctx.params.id || 'Fashion';
|
||||
|
||||
id = id.toLowerCase();
|
||||
|
||||
const rootUrl = 'https://www.esquirehk.com';
|
||||
const topics = ['style', 'watch', 'money-investment', 'lifestyle', 'culture', 'mens-talk', 'gear', 'people'];
|
||||
|
||||
let currentUrl = `${rootUrl}/tag/${id}`;
|
||||
if (topics.indexOf(id) > -1) {
|
||||
currentUrl = `${rootUrl}/${id}`;
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('.FeedStory')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
author: item.find('.author').text(),
|
||||
link: `${rootUrl}${item.find('a.Anchor').eq(0).attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('.RelatedBlock').remove();
|
||||
content('.TagContainer').remove();
|
||||
content('.YouMayLikeContainer').remove();
|
||||
content('.SubscriptionContainer').remove();
|
||||
|
||||
content('img').each(function () {
|
||||
const srcset = content(this).attr('srcset');
|
||||
if (srcset) {
|
||||
content(this).removeAttr('srcset');
|
||||
content(this).removeAttr('data-src');
|
||||
content(this).attr('src', `${rootUrl}${srcset.split(',')[1].replace('1032w', '')}`);
|
||||
}
|
||||
});
|
||||
|
||||
item.title = content('.CommonTitle').text();
|
||||
item.description = content('.ArticlePage').html();
|
||||
item.pubDate = new Date(content('.ArticleFeeds-info time').eq(0).attr('data-timestamp') * 1000).toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('title').text()} - Esquirehk`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue