diff --git a/docs/other.md b/docs/other.md index 0d6bb4704f..81be2a622f 100644 --- a/docs/other.md +++ b/docs/other.md @@ -396,3 +396,9 @@ type 为 all 时,category 参数不支持 cost 和 free ### 房源 + +## はてな + +### はてな匿名ダイアリー - 人気記事アーカイブ + + diff --git a/lib/router.js b/lib/router.js index 4bb13bc3af..8dc7cd7ba6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1848,6 +1848,9 @@ router.get('/4gamers/tag/:tag', require('./routes/4gamers/tag')); // 大麦网 router.get('/damai/activity/:city/:category/:subcategory/:keyword?', require('./routes/damai/activity')); +// はてな匿名ダイアリー +router.get('/hatena/anonymous_diary/archive', require('./routes/hatena/anonymous_diary/archive')); + // kaggle router.get('/kaggle/discussion/:forumId/:sort?', require('./routes/kaggle/discussion')); diff --git a/lib/routes/hatena/anonymous_diary/archive.js b/lib/routes/hatena/anonymous_diary/archive.js new file mode 100644 index 0000000000..2644af574a --- /dev/null +++ b/lib/routes/hatena/anonymous_diary/archive.js @@ -0,0 +1,61 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); + +function getPubDate(yyyyMMddhhmmss) { + const yyyy = yyyyMMddhhmmss.slice(0, 4); + const MM = yyyyMMddhhmmss.slice(4, 6); + const dd = yyyyMMddhhmmss.slice(6, 8); + const hh = yyyyMMddhhmmss.slice(8, 10); + const mm = yyyyMMddhhmmss.slice(10, 12); + const ss = yyyyMMddhhmmss.slice(12, 14); + return new Date(`${yyyy}-${MM}-${dd}T${hh}:${mm}:${ss}+0900`); +} + +module.exports = async (ctx) => { + const baseURL = 'https://anond.hatelabo.jp'; + + const archiveIndex = await got({ + method: 'get', + url: url.resolve(baseURL, '/archive'), + }); + + const latestURL = url.resolve( + baseURL, + cheerio + .load(archiveIndex.data)('.archives a') + .first() + .attr('href') + ); + const response = await got({ + method: 'get', + url: latestURL, + }); + + const $ = cheerio.load(response.data); + const list = $('.archives li'); + + ctx.state.data = { + title: $('title').text(), + link: latestURL, + language: 'ja', + item: + list && + list + .map((idx, item) => { + item = $(item); + const a = item.find('a').first(); + const yyyyMMddhhmmss = a.attr('href').replace('/', ''); + return { + title: a.text(), + description: item + .find('blockquote p') + .first() + .text(), + link: url.resolve(baseURL, a.attr('href')), + pubDate: getPubDate(yyyyMMddhhmmss).toUTCString(), + }; + }) + .get(), + }; +};