diff --git a/docs/README.md b/docs/README.md index 30d178d47..47ecf3ed2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -927,7 +927,14 @@ key: 产品密钥 | -------- | -------- | ---------- | ---------- | | topic | news | technews | blockchain | -## Konachan.com Anime Wallpapers +## Konachan Anime Wallpapers + +::: tip 提示 + +* tags 可以在 [konachan](https://konachan.com/post) 选好后, 复制其 URL 中 tags= 后的参数 +* 路由可选 `/konachan` 或 `/konachan.com` 或 `/konachan.net`, 其中前两者相同, `.net` 是全年龄健康的壁纸 ♡ + +::: ### Posts diff --git a/router.js b/router.js index 818d9e6a9..8067dd010 100644 --- a/router.js +++ b/router.js @@ -245,9 +245,17 @@ if (config.github && config.github.access_token) { // konachan router.get('/konachan/post', require('./routes/konachan/post')); +router.get('/konachan.com/post', require('./routes/konachan/post')); +router.get('/konachan.net/post', require('./routes/konachan/post')); router.get('/konachan/post/popular_recent', require('./routes/konachan/post_popular_recent')); +router.get('/konachan.com/post/popular_recent', require('./routes/konachan/post_popular_recent')); +router.get('/konachan.net/post/popular_recent', require('./routes/konachan/post_popular_recent')); router.get('/konachan/post/:tags', require('./routes/konachan/post')); +router.get('/konachan.com/post/:tags', require('./routes/konachan/post')); +router.get('/konachan.net/post/:tags', require('./routes/konachan/post')); router.get('/konachan/post/popular_recent/:period', require('./routes/konachan/post_popular_recent')); +router.get('/konachan.com/post/popular_recent/:period', require('./routes/konachan/post_popular_recent')); +router.get('/konachan.net/post/popular_recent/:period', require('./routes/konachan/post_popular_recent')); // yande.re router.get('/yande.re/post', require('./routes/yande.re/post')); diff --git a/routes/konachan/post.js b/routes/konachan/post.js index 6c490d64e..8ad183b77 100644 --- a/routes/konachan/post.js +++ b/routes/konachan/post.js @@ -4,9 +4,12 @@ const config = require('../../config'); module.exports = async (ctx) => { const { tags = '' } = ctx.params; + const baseURL = ctx.path.startsWith('/konachan.net') ? 'https://konachan.net' : 'https://konachan.com'; + const response = await axios({ method: 'get', - url: `https://konachan.com/post.json?tags=${tags}`, + baseURL, + url: `/post.json?tags=${tags}`, headers: { 'User-Agent': config.ua, }, @@ -14,22 +17,25 @@ module.exports = async (ctx) => { const posts = response.data; - let title = 'Konachan.com Anime Wallpapers'; + let title = 'Konachan Anime Wallpapers'; if (tags) { title = decodeURIComponent(tags) + ' - ' + title; } ctx.state.data = { title, - link: 'https://konachan.com/post', + link: `${baseURL}/post`, item: posts.map((post) => { const content = (url) => { - let result = ``; + if (url.startsWith('//')) { + url = 'https:' + url; + } + let result = ``; if (post.source) { result += `source`; } if (post.parent_id) { - result += `parent`; + result += `parent`; } return result; }; @@ -40,7 +46,7 @@ module.exports = async (ctx) => { title: post.tags, id: `${ctx.path}#${post.id}`, guid: `${ctx.path}#${post.id}`, - link: `https://konachan.com/post/show/${post.id}`, + link: `${baseURL}/post/show/${post.id}`, author: post.author, published: new Date(created_at).toISOString(), pubDate: new Date(created_at).toUTCString(), diff --git a/routes/konachan/post_popular_recent.js b/routes/konachan/post_popular_recent.js index d937ba8c6..f3ddd0ba1 100644 --- a/routes/konachan/post_popular_recent.js +++ b/routes/konachan/post_popular_recent.js @@ -4,9 +4,12 @@ const config = require('../../config'); module.exports = async (ctx) => { const { period = '1d' } = ctx.params; + const baseURL = ctx.path.startsWith('/konachan.net') ? 'https://konachan.net' : 'https://konachan.com'; + const response = await axios({ method: 'get', - url: 'https://konachan.com/post/popular_recent.json', + baseURL, + url: '/post/popular_recent.json', headers: { 'User-Agent': config.ua, }, @@ -27,16 +30,19 @@ module.exports = async (ctx) => { const title = titles[period] || titles['1d']; ctx.state.data = { - title: `${title} - Konachan.com Anime Wallpapers`, - link: 'https://konachan.com/post/popular_recent', + title: `${title} - Konachan Anime Wallpapers`, + link: `${baseURL}/post/popular_recent`, item: posts.map((post) => { const content = (url) => { - let result = ``; + if (url.startsWith('//')) { + url = 'https:' + url; + } + let result = ``; if (post.source) { result += `source`; } if (post.parent_id) { - result += `parent`; + result += `parent`; } return result; }; @@ -47,7 +53,7 @@ module.exports = async (ctx) => { title: post.tags, id: `${ctx.path}#${post.id}`, guid: `${ctx.path}#${post.id}`, - link: `https://konachan.com/post/show/${post.id}`, + link: `${baseURL}/post/show/${post.id}`, author: post.author, published: new Date(created_at).toISOString(), pubDate: new Date(created_at).toUTCString(),