diff --git a/docs/other.md b/docs/other.md index 645ec5ad2..82e34acb0 100644 --- a/docs/other.md +++ b/docs/other.md @@ -515,6 +515,12 @@ type 为 all 时,category 参数不支持 cost 和 free +## 法律白話文運動 + +### 最新文章 + + + ## 飞地 ### 分类 diff --git a/lib/router.js b/lib/router.js index 7925d5c65..f6e43e796 100644 --- a/lib/router.js +++ b/lib/router.js @@ -135,6 +135,9 @@ router.get('/douban/explore/column/:id', require('./routes/douban/explore_column router.get('/douban/people/:userid/status', require('./routes/douban/people/status.js')); router.get('/douban/topic/:id/:sort?', require('./routes/douban/topic.js')); +// 法律白話文運動 +router.get('/plainlaw/archives', require('./routes/plainlaw/archives.js')); + // 煎蛋 router.get('/jandan/:sub_model', require('./routes/jandan/pic')); diff --git a/lib/routes/plainlaw/archives.js b/lib/routes/plainlaw/archives.js new file mode 100644 index 000000000..0df710cbd --- /dev/null +++ b/lib/routes/plainlaw/archives.js @@ -0,0 +1,42 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const currentDate = new Date(); + const year = currentDate.getFullYear(); + const url = `https://plainlaw.me/${year}`; + + const res = await got.get(url); + const $ = cheerio.load(res.data); + const list = $('article').get(); + + const out = await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + const title = $('h3.title > a').text(); + const address = $('h3.title > a').attr('href'); + const cache = await ctx.cache.get(address); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const res = await got.get(address); + const capture = cheerio.load(res.data); + capture('div.inline-post.clearfix').remove(); + const banner = capture('div.hero').html(); + const contents = banner + capture('div.dable-content-wrapper').html(); + const single = { + title, + description: contents, + link: address, + guid: address, + }; + ctx.cache.set(address, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + ctx.state.data = { + title: '法律白話文運動', + link: url, + item: out, + }; +};