diff --git a/docs/other.md b/docs/other.md index c674113c7..c54064f1d 100644 --- a/docs/other.md +++ b/docs/other.md @@ -39,6 +39,12 @@ pageClass: routes 见 [#app-store-mac-app-store](/program-update.html#app-store-mac-app-store) +## archdaily + +### 首页 + + + ## AutoTrader ### 搜索结果 diff --git a/lib/router.js b/lib/router.js index 4943eca0f..66282cac8 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1464,4 +1464,7 @@ router.get('/tprtc/cqzr', require('./routes/tprtc/cqzr')); router.get('/tprtc/qyzc', require('./routes/tprtc/qyzc')); router.get('/tprtc/news', require('./routes/tprtc/news')); +// ArchDaily +router.get('/archdaily', require('./routes/archdaily/home')); + module.exports = router; diff --git a/lib/routes/archdaily/home.js b/lib/routes/archdaily/home.js new file mode 100644 index 000000000..07a0b5d67 --- /dev/null +++ b/lib/routes/archdaily/home.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const parser = require('@/utils/rss-parser'); + +module.exports = async (ctx) => { + const feed = await parser.parseURL('https://feeds.feedburner.com/ArchdailyCN'); + + const ProcessFeed = async (link) => { + const response = await got({ + method: 'get', + url: link, + }); + + const $ = cheerio.load(response.data); + + // 还原图片地址 + $('img').each((index, elem) => { + const $elem = $(elem); + $elem.attr('referrerpolicy', 'no-referrer'); + }); + + // 提取内容 + return $('#single-content').html(); + }; + + const items = await Promise.all( + feed.items.map(async (item) => { + const cache = await ctx.cache.get(item.link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const description = await ProcessFeed(item.link); + + const single = { + title: item.title, + description, + pubDate: item.pubDate, + link: item.link, + author: item.author, + }; + ctx.cache.set(item.link, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: feed.title, + link: feed.link, + description: feed.description, + item: items, + }; +};