diff --git a/docs/blog.md b/docs/blog.md index 840987fcb..13abe997b 100644 --- a/docs/blog.md +++ b/docs/blog.md @@ -159,6 +159,18 @@ pageClass: routes +## 大眼仔旭 + +### 分类 + + + +| 微软应用 | 安卓应用 | 教程资源 | 其他资源 | +| ------- | ------- | -------- | ----- | +| windows | android | tutorial | other | + + + ## 華康字型故事 @@ -268,7 +280,11 @@ pageClass: routes ### 文章 + ::: tip 提示 + 在路由末尾处加上 `?limit=限制获取数目` 来限制获取条目数量,默认值为`20` -::: + +::: + diff --git a/lib/v2/dayanzai/index.js b/lib/v2/dayanzai/index.js new file mode 100644 index 000000000..cb5027abb --- /dev/null +++ b/lib/v2/dayanzai/index.js @@ -0,0 +1,58 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const rootUrl = 'http://www.dayanzai.me/'; + +module.exports = async (ctx) => { + const { category, fulltext } = ctx.params; + const currentUrl = rootUrl + category; + const response = await got.get(currentUrl); + const $ = cheerio.load(response.data); + const lists = $('div.c-box > div > div.c-zx-list > ul > li'); + const reg = /日期:(.*?(\s\(.*?\))?)\s/; + const list = lists + .map((index, item) => { + item = $(item).find('div'); + let date = reg.exec(item.find('div.r > p.other').text())[1]; + if (date.indexOf('周') !== -1 || date.indexOf('月') !== -1) { + date = /\((.*?)\)/.exec(date)[1]; + date = parseDate(date, 'MM-DD'); + } else if (date.indexOf('年') !== -1) { + date = /\((.*?)\)/.exec(date)[1]; + date = parseDate(date, 'YYYY-MM-DD'); + } else { + date = parseRelativeDate(date); + } + return { + title: item.find('div.r > p.r-top > span > a').text(), + pubDate: timezone(date, +8), + description: item.find('div.r > p.desc').text(), + link: item.find('div.r > p.r-top > span > a').attr('href'), + }; + }) + .get(); + let items; + if (fulltext === 'y') { + items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got.get(item.link); + const content = cheerio.load(detailResponse.data); + item.description = content('div.intro-box').html(); + return item; + }) + ) + ); + } else { + items = list; + } + + ctx.state.data = { + title: `大眼仔旭 ${category}`, + link: currentUrl, + description: `大眼仔旭 ${category} RSS`, + item: items, + }; +}; diff --git a/lib/v2/dayanzai/maintainer.js b/lib/v2/dayanzai/maintainer.js new file mode 100644 index 000000000..d7de196cc --- /dev/null +++ b/lib/v2/dayanzai/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/dayanzai/:category/:fulltext?': ['nitezs'], +}; diff --git a/lib/v2/dayanzai/radar.js b/lib/v2/dayanzai/radar.js new file mode 100644 index 000000000..0709bde68 --- /dev/null +++ b/lib/v2/dayanzai/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'dayanzai.me': { + _name: '大眼仔旭', + '.': [ + { + title: '大眼仔旭', + docs: 'https://docs.rsshub.app/bbs.html#dayanzai', + source: ['/:category', '/:category/*'], + target: '/dayanzai/:category', + }, + ], + }, +}; diff --git a/lib/v2/dayanzai/router.js b/lib/v2/dayanzai/router.js new file mode 100644 index 000000000..f3679ab42 --- /dev/null +++ b/lib/v2/dayanzai/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category/:fulltext?', require('./index')); +};