diff --git a/README.md b/README.md index 261bbb98a..8685b472a 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,9 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 * Konachan.com Anime Wallpapers * posts * Popular Recent Posts +* yande.re + * posts + * Popular Recent Posts ## 鸣谢 diff --git a/docs/README.md b/docs/README.md index d6a55b8a4..2555933f9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -949,3 +949,33 @@ key: 产品密钥 * 过去一周:[https://rsshub.app/konachan/post/popular_recent/1w](https://rsshub.app/konachan/post/popular_recent/1w) * 过去一月:[https://rsshub.app/konachan/post/popular_recent/1m](https://rsshub.app/konachan/post/popular_recent/1m) * 过去一年:[https://rsshub.app/konachan/post/popular_recent/1y](https://rsshub.app/konachan/post/popular_recent?period=1y) + +## yande.re + +### Posts + +路由: + +* `/yande.re/post` +* `/yande.re/post/:tags` + +举例: + +* [https://rsshub.app/yande.re/post](https://rsshub.app/yande.re/post) +* [https://rsshub.app/yande.re/post/the_idolm%40ster](https://rsshub.app/yande.re/post/the_idolm%40ster) +* [https://rsshub.app/yande.re/post/kantai_collection](https://rsshub.app/yande.re/post/kantai_collection) +* [https://rsshub.app/yande.re/post/love_live%21](https://rsshub.app/yande.re/post/love_live%21) + +### Popular Recent Posts + +路由: + +* `/yande.re/post/popular_recent` 默认过去 24 小时 +* `/yande.re/post/popular_recent/:period` + +举例: + +* 过去 24 小时:[https://rsshub.app/yande.re/post/popular_recent/1d](https://rsshub.app/yande.re/post/popular_recent/1d) +* 过去一周:[https://rsshub.app/yande.re/post/popular_recent/1w](https://rsshub.app/yande.re/post/popular_recent/1w) +* 过去一月:[https://rsshub.app/yande.re/post/popular_recent/1m](https://rsshub.app/yande.re/post/popular_recent/1m) +* 过去一年:[https://rsshub.app/yande.re/post/popular_recent/1y](https://rsshub.app/yande.re/post/popular_recent?period=1y) diff --git a/router.js b/router.js index d19b5dccf..818d9e6a9 100644 --- a/router.js +++ b/router.js @@ -249,4 +249,10 @@ router.get('/konachan/post/popular_recent', require('./routes/konachan/post_popu router.get('/konachan/post/:tags', require('./routes/konachan/post')); router.get('/konachan/post/popular_recent/:period', require('./routes/konachan/post_popular_recent')); +// yande.re +router.get('/yande.re/post', require('./routes/yande.re/post')); +router.get('/yande.re/post/popular_recent', require('./routes/yande.re/post_popular_recent')); +router.get('/yande.re/post/:tags', require('./routes/yande.re/post')); +router.get('/yande.re/post/popular_recent/:period', require('./routes/yande.re/post_popular_recent')); + module.exports = router; diff --git a/routes/yande.re/post.js b/routes/yande.re/post.js new file mode 100644 index 000000000..5aff0bdcd --- /dev/null +++ b/routes/yande.re/post.js @@ -0,0 +1,55 @@ +const axios = require('../../utils/axios'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const { tags = '' } = ctx.params; + + const response = await axios({ + method: 'get', + url: `https://yande.re/post.json?tags=${tags}`, + headers: { + 'User-Agent': config.ua, + }, + }); + + const posts = response.data; + + let title = 'yande.re'; + if (tags) { + title = decodeURIComponent(tags) + ' - ' + title; + } + + ctx.state.data = { + title, + link: 'https://yande.re/post', + item: posts.map((post) => { + const content = (url) => { + let result = ``; + if (post.source) { + result += `source`; + } + if (post.parent_id) { + result += `parent`; + } + return result; + }; + + const created_at = post.created_at * 1e3; + + return { + title: post.tags, + id: `${ctx.path}#${post.id}`, + guid: `${ctx.path}#${post.id}`, + link: `https://yande.re/post/show/${post.id}`, + author: post.author, + published: new Date(created_at).toISOString(), + pubDate: new Date(created_at).toUTCString(), + description: content(post.sample_url), + summary: content(post.sample_url), + content: content(post.file_url), + image: post.file_url, + category: post.tags.split(/\s+/), + }; + }), + }; +}; diff --git a/routes/yande.re/post_popular_recent.js b/routes/yande.re/post_popular_recent.js new file mode 100644 index 000000000..e798f81ed --- /dev/null +++ b/routes/yande.re/post_popular_recent.js @@ -0,0 +1,62 @@ +const axios = require('../../utils/axios'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const { period = '1d' } = ctx.params; + + const response = await axios({ + method: 'get', + url: 'https://yande.re/post/popular_recent.json', + headers: { + 'User-Agent': config.ua, + }, + params: { + period, + }, + }); + + const posts = response.data; + + const titles = { + '1d': 'Exploring last 24 hours ', + '1w': 'Exploring last week', + '1m': 'Exploring last month', + '1y': 'Exploring last year', + }; + + const title = titles[period] || titles['1d']; + + ctx.state.data = { + title: `${title} - yande.re`, + link: 'https://yande.re/post/popular_recent', + item: posts.map((post) => { + const content = (url) => { + let result = ``; + if (post.source) { + result += `source`; + } + if (post.parent_id) { + result += `parent`; + } + return result; + }; + + const created_at = post.created_at * 1e3; + + return { + title: post.tags, + id: `${ctx.path}#${post.id}`, + guid: `${ctx.path}#${post.id}`, + link: `https://yande.re/post/show/${post.id}`, + author: post.author, + published: new Date(created_at).toISOString(), + pubDate: new Date(created_at).toUTCString(), + description: content(post.sample_url), + summary: content(post.sample_url), + content: content(post.file_url), + image: post.file_url, + category: post.tags.split(/\s+/), + }; + }), + }; +};