From 9b53436084dff100ca6ea68c843507af92a345e6 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 24 Mar 2020 19:23:05 +0800 Subject: [PATCH] feat: add diygod blog --- docs/blog.md | 10 ++++++ lib/router.js | 4 +++ lib/routes/blogs/diygod/animal-crossing.js | 37 ++++++++++++++++++++++ lib/routes/blogs/diygod/gk.js | 37 ++++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 lib/routes/blogs/diygod/animal-crossing.js create mode 100644 lib/routes/blogs/diygod/gk.js diff --git a/docs/blog.md b/docs/blog.md index 46f304561c..9bc34f621f 100644 --- a/docs/blog.md +++ b/docs/blog.md @@ -36,6 +36,16 @@ pageClass: routes +## Hi, DIYgod + +### DIYgod 的动森日记 + + + +### DIYgod 的可爱的手办们 + + + ## LaTeX 开源小屋 ### 首页 diff --git a/lib/router.js b/lib/router.js index 8de165db94..054710daae 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2424,4 +2424,8 @@ router.get('/checkra1n/releases', require('./routes/checkra1n/releases')); // 四川省科学技术厅 router.get('/sckjt/news/:type?', require('./routes/sckjt/news')); +// Hi, DIYgod +router.get('/blogs/diygod/animal-crossing', require('./routes/blogs/diygod/animal-crossing')); +router.get('/blogs/diygod/gk', require('./routes/blogs/diygod/gk')); + module.exports = router; diff --git a/lib/routes/blogs/diygod/animal-crossing.js b/lib/routes/blogs/diygod/animal-crossing.js new file mode 100644 index 0000000000..4c31dee85e --- /dev/null +++ b/lib/routes/blogs/diygod/animal-crossing.js @@ -0,0 +1,37 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const date = require('@/utils/date'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'https://diygod.me/animal-crossing', + }); + + const data = response.data; + + const $ = cheerio.load(data); + const list = $('h3'); + + ctx.state.data = { + title: 'DIYgod 的动森日记', + link: 'https://diygod.me/animal-crossing', + item: + list && + list + .map((index, item) => { + item = $(item); + let description = ''; + item.nextUntil('h3').each((index, item) => { + description += $(item).html(); + }); + return { + title: item.text(), + description, + link: `https://diygod.me/animal-crossing/#${item.attr('id')}`, + pubDate: date(item.text().split(' ')[1]), + }; + }) + .get(), + }; +}; diff --git a/lib/routes/blogs/diygod/gk.js b/lib/routes/blogs/diygod/gk.js new file mode 100644 index 0000000000..e1f6f89dd4 --- /dev/null +++ b/lib/routes/blogs/diygod/gk.js @@ -0,0 +1,37 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'https://diygod.me/gk', + }); + + const data = response.data; + + const $ = cheerio.load(data); + const list = $('.gk-item'); + + ctx.state.data = { + title: 'DIYgod 的动森日记', + link: 'https://diygod.me/animal-crossing', + item: + list && + list + .map((index, item) => { + item = $(item); + const title = item + .find('.gk-desc p') + .eq(0) + .text() + .slice(3); + return { + title, + description: item.html(), + link: 'https://diygod.me/gk', + guid: title, + }; + }) + .get(), + }; +};