diff --git a/docs/study.md b/docs/study.md index 2dedf43c9..edf81102a 100644 --- a/docs/study.md +++ b/docs/study.md @@ -29,6 +29,20 @@ pageClass: routes +### 精选文章 + + + +| 用户故事 | 地道表达法 | 实用口语 | 语法教室 | 读新闻学英语 | 单词鸡汤 | 扇贝理念 | 英语知识 | 原汁英文 | +| -------- | ---------- | -------- | -------- | ------------ | -------- | -------- | -------- | -------- | +| 1 | 31 | 46 | 34 | 40 | 43 | 16 | 7 | 10 | + +| 学习方法 | 影视剧讲义 | 产品更新 | 精读文章 | 他山之石 | Quora 翻译 | TED 推荐 | 大耳狐小课堂 | 互动话题 | +| -------- | ---------- | -------- | -------- | -------- | ---------- | -------- | ------------ | -------- | +| 13 | 22 | 28 | 4 | 19 | 25 | 37 | 49 | 52 | + + + ## 下厨房 ### 用户作品 diff --git a/lib/router.js b/lib/router.js index fa9078a10..4bb13bc3a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1002,6 +1002,7 @@ router.get('/steamgifts/discussions/:category?', require('./routes/steam/steamgi // 扇贝 router.get('/shanbay/checkin/:id', require('./routes/shanbay/checkin')); +router.get('/shanbay/footprints/:category?', require('./routes/shanbay/footprints')); // Facebook router.get('/facebook/page/:id', require('./routes/facebook/page')); diff --git a/lib/routes/shanbay/footprints.js b/lib/routes/shanbay/footprints.js new file mode 100644 index 000000000..5f0776399 --- /dev/null +++ b/lib/routes/shanbay/footprints.js @@ -0,0 +1,42 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const cat = ctx.params.category; + const host = 'https://www.shanbay.com'; + const url = cat ? `${host}/footprints/?category=${cat}` : `${host}/footprints/`; + const res = await got.get(url); + const $ = cheerio.load(res.data); + const list = $('div.articles div.article-item').get(); + + const out = await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + const time = $('p.article-publish-day').text() + $('span.article-publish-month-year').text(); + const title = $('h3.article-title a').text(); + const itemUrl = host + $('h3.article-title a').attr('href'); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const responses = await got.get(itemUrl); + const $d = cheerio.load(responses.data); + + const single = { + title, + pubDate: new Date(time).toUTCString(), + link: itemUrl, + guid: itemUrl, + description: $d('#content .content').html(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + ctx.state.data = { + title: '扇贝精选文章', + link: url, + item: out, + }; +};