diff --git a/docs/new-media.md b/docs/new-media.md index 078ba0b2e7..af1e8923e4 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -355,6 +355,10 @@ pageClass: routes ## 虎嗅 +### 首页资讯 + + + ### 标签 diff --git a/lib/router.js b/lib/router.js index 897ce2b227..bddaf78914 100644 --- a/lib/router.js +++ b/lib/router.js @@ -995,6 +995,7 @@ router.get('/zimuzu/resource/:id?', require('./routes/zimuzu/resource')); router.get('/huxiu/tag/:id', require('./routes/huxiu/tag')); router.get('/huxiu/search/:keyword', require('./routes/huxiu/search')); router.get('/huxiu/author/:id', require('./routes/huxiu/author')); +router.get('/huxiu/article', require('./routes/huxiu/article')); // Steam router.get('/steam/search/:params', require('./routes/steam/search')); diff --git a/lib/routes/huxiu/article.js b/lib/routes/huxiu/article.js new file mode 100644 index 0000000000..1ecaaaa2b1 --- /dev/null +++ b/lib/routes/huxiu/article.js @@ -0,0 +1,30 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const utils = require('./utils'); + +module.exports = async (ctx) => { + const link = 'https://www.huxiu.com/article'; + const response = await got({ + method: 'get', + url: link, + headers: { + Referer: link, + }, + }); + + const $ = cheerio.load(response.data); + + const list = $('.article-item--normal > a, .article-item--large > a') + .slice(0, 10) + .get() + .map((e) => $(e).attr('href')); + + const items = await utils.ProcessFeed(list, ctx.cache); + + ctx.state.data = { + title: '虎嗅网 - 首页资讯', + link, + description: '聚合优质的创新信息与人群,捕获精选 | 深度 | 犀利的商业科技资讯。在虎嗅,不错过互联网的每个重要时刻。', + item: items, + }; +}; diff --git a/lib/routes/huxiu/tag.js b/lib/routes/huxiu/tag.js index 53f9f82544..333c6c8115 100644 --- a/lib/routes/huxiu/tag.js +++ b/lib/routes/huxiu/tag.js @@ -21,7 +21,7 @@ module.exports = async (ctx) => { const items = await utils.ProcessFeed(list, ctx.cache); - const info = `虎嗅 - ${$('.tag-title').text()}`; + const info = `虎嗅 - ${$('h1').text()}`; ctx.state.data = { title: info, link, diff --git a/lib/routes/huxiu/utils.js b/lib/routes/huxiu/utils.js index 7563cd8d6c..bab1b3bb08 100644 --- a/lib/routes/huxiu/utils.js +++ b/lib/routes/huxiu/utils.js @@ -15,13 +15,19 @@ const ProcessFeed = async (list, cache) => { const $ = cheerio.load(response.data); + $('.article__content') + .find('.lazyImg') + .each((i, e) => { + $(e).attr('src', $(e).attr('_src')); + }); + return { title: $('.article__title') .text() .trim(), description: $('.article__top-img-video') + $('.article__content').html(), - pubDate: date($('.article__bottom-content__right .article__time').text(), 8), - author: $('.article__author-info-box .author-info__username').text(), + pubDate: date($('.article__time').text(), 8), + author: $('.author-info__username').text(), link, }; });