diff --git a/docs/README.md b/docs/README.md index 7b818b963e..d0beda4c07 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2361,6 +2361,10 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 +### All Poetry + + + ## 中国驻外使领馆 ### 大使馆 diff --git a/docs/en/README.md b/docs/en/README.md index a6d3f57666..0d25ef9b70 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -423,3 +423,7 @@ Supported sub-sites: | Mac | Google | Toys | + +### All Poetry + + diff --git a/lib/router.js b/lib/router.js index f35342ca0d..adca24c7a1 100644 --- a/lib/router.js +++ b/lib/router.js @@ -964,6 +964,9 @@ router.get('/jingdong/zhongchou/:type/:status/:sort', require('./routes/jingdong // 淘宝众筹 router.get('/taobao/zhongchou/:type?', require('./routes/taobao/zhongchou')); +// All Poetry +router.get('/allpoetry/:order?', require('./routes/allpoetry/order')); + // 华尔街见闻 router.get('/wallstreetcn/news/global', require('./routes/wallstreetcn/news')); diff --git a/lib/routes/allpoetry/order.js b/lib/routes/allpoetry/order.js new file mode 100644 index 0000000000..712645b10e --- /dev/null +++ b/lib/routes/allpoetry/order.js @@ -0,0 +1,59 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +module.exports = async (ctx) => { + const { order = 'best' } = ctx.params; + const link = `https://allpoetry.com/poems/about/spotlight-oldpoem?order=${order}}`; + const host = 'https://allpoetry.com/'; + + const response = await axios({ + method: 'get', + url: link, + }); + + const data = response.data; + + const $ = cheerio.load(data); + + const items = await Promise.all( + $('.sub') + .slice(0, 5) + .get() + .map(async (e) => { + let itemUrl = $(e) + .find('h1.title > a') + .attr('href'); + + itemUrl = url.resolve(host, itemUrl); + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const single = { + title: $(e) + .find('h1.title > a') + .text(), + description: $(e) + .find('div.poem_body') + .html(), + link: itemUrl, + author: $(e) + .find('div.bio >a ') + .attr('data-name'), + guid: itemUrl, + }; + + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `All Poetry - ${order.toUpperCase() + order.slice(1)}`, + link, + item: items, + }; +};