diff --git a/docs/blog.md b/docs/blog.md index 1a2456a09..d1aad3f94 100644 --- a/docs/blog.md +++ b/docs/blog.md @@ -211,3 +211,13 @@ pageClass: routes ### 文章 + +## 雨苁博客 + +### 首页 + + + +### 分类 + + diff --git a/lib/v2/ddosi/category.js b/lib/v2/ddosi/category.js new file mode 100644 index 000000000..f30409055 --- /dev/null +++ b/lib/v2/ddosi/category.js @@ -0,0 +1,42 @@ +const envs = process.env; +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const url = 'https://www.ddosi.org/category'; + const userAgent = envs.UA || 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'; + const category = ctx.params.category; + const response = await got({ + method: 'get', + url: `${url}/${category}/`, + headers: { + 'User-Agent': userAgent, + Referer: url, + }, + }); + const $ = cheerio.load(response.data); + const list = $('main>article').get(); + + const items = list.map((i) => { + const item = $(i); + + const href = item.find('a:first-child').attr('href'); + const title = item.find('.entry-title a').text(); + const description = item.find('.entry-content p').text(); + const date = parseDate(item.find('.meta-date a time').attr('datetime')); + + return { + title: String(title), + description: String(description), + pubDate: date, + link: String(href), + }; + }); + + ctx.state.data = { + title: `雨苁-${category}`, + link: `${url}/${category}/`, + item: items, + }; +}; diff --git a/lib/v2/ddosi/index.js b/lib/v2/ddosi/index.js new file mode 100644 index 000000000..b2b5f0d54 --- /dev/null +++ b/lib/v2/ddosi/index.js @@ -0,0 +1,41 @@ +const envs = process.env; +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const url = 'https://www.ddosi.org/'; + const userAgent = envs.UA || 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'; + const response = await got({ + method: 'get', + url: String(url), + headers: { + 'User-Agent': userAgent, + Referer: url, + }, + }); + const $ = cheerio.load(response.data); + const list = $('main>article').get(); + + const items = list.map((i) => { + const item = $(i); + + const href = item.find('a:first-child').attr('href'); + const title = item.find('.entry-title a').text(); + const description = item.find('.entry-content p').text(); + const date = parseDate(item.find('.meta-date a time').attr('datetime')); + + return { + title: String(title), + description: String(description), + pubDate: date, + link: String(href), + }; + }); + + ctx.state.data = { + title: `雨苁`, + link: String(url), + item: items, + }; +}; diff --git a/lib/v2/ddosi/maintainer.js b/lib/v2/ddosi/maintainer.js new file mode 100644 index 000000000..144bbea40 --- /dev/null +++ b/lib/v2/ddosi/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/': ['XinRoom'], + '/category/:category': ['XinRoom'], +}; diff --git a/lib/v2/ddosi/radar.js b/lib/v2/ddosi/radar.js new file mode 100644 index 000000000..a1595e336 --- /dev/null +++ b/lib/v2/ddosi/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'www.ddosi.org': { + _name: '🔰雨苁ℒ🔰', + '.': [ + { + title: '首页', + docs: 'https://docs.rsshub.app/blog.html#yu-cong-bo-ke-shou-ye', + source: ['/'], + target: '/ddosi/', + }, + { + title: '分类', + docs: 'https://docs.rsshub.app/blog.html#yu-cong-bo-ke-fen-lei', + source: ['/category/:category/'], + target: '/ddosi/category/:category', + }, + ], + }, +}; diff --git a/lib/v2/ddosi/router.js b/lib/v2/ddosi/router.js new file mode 100644 index 000000000..ca9b06bb7 --- /dev/null +++ b/lib/v2/ddosi/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/category/:category?', require('./category')); + router.get('/', require('./index')); +};