rss: add Konachan.com Anime Wallpapers (#208)

* rss: add Konachan.com Anime Wallpapers

* switch to ctx.params
This commit is contained in:
阿卡琳
2018-05-27 17:12:19 +08:00
committed by DIYgod
parent 01159b023b
commit 2c268759b2
5 changed files with 155 additions and 0 deletions
+3
View File
@@ -121,6 +121,9 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
* 分类
* GitHub
* 用户仓库
* Konachan.com Anime Wallpapers
* posts
* Popular Recent Posts
## 鸣谢
+29
View File
@@ -920,3 +920,32 @@ key: 产品密钥
| 热门话题 | 科技动态 | 开发者资讯 | 区块链快讯 |
| -------- | -------- | ---------- | ---------- |
| topic | news | technews | blockchain |
## Konachan.com Anime Wallpapers
### Posts
路由:
* `/konachan/post`
* `/konachan/post/:tags`
举例:
* [https://rsshub.app/konachan/post](https://rsshub.app/konachan/post)
* [https://rsshub.app/konachan/post/touhou](https://rsshub.app/konachan/post/touhou)
* [https://rsshub.app/konachan/post/panties+rating%3Asafe](https://rsshub.app/konachan/post/panties+rating%3Asafe)
### Popular Recent Posts
路由:
* `/konachan/post/popular_recent` 默认过去 24 小时
* `/konachan/post/popular_recent/:period`
举例:
* 过去 24 小时:[https://rsshub.app/konachan/post/popular_recent/1d](https://rsshub.app/konachan/post/popular_recent/1d)
* 过去一周:[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)
+6
View File
@@ -243,4 +243,10 @@ if (config.github && config.github.access_token) {
logger.warn('GitHub RSS is disabled for lacking config.');
}
// konachan
router.get('/konachan/post', require('./routes/konachan/post'));
router.get('/konachan/post/popular_recent', require('./routes/konachan/post_popular_recent'));
router.get('/konachan/post/:tags', require('./routes/konachan/post'));
router.get('/konachan/post/popular_recent/:period', require('./routes/konachan/post_popular_recent'));
module.exports = router;
+55
View File
@@ -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://konachan.com/post.json?tags=${tags}`,
headers: {
'User-Agent': config.ua,
},
});
const posts = response.data;
let title = 'Konachan.com Anime Wallpapers';
if (tags) {
title = decodeURIComponent(tags) + ' - ' + title;
}
ctx.state.data = {
title,
link: 'https://konachan.com/post',
item: posts.map((post) => {
const content = (url) => {
let result = `<img src="${url}" />`;
if (post.source) {
result += `<a href="${post.source}">source</a>`;
}
if (post.parent_id) {
result += `<a href="https://konachan.com/post/show/${post.parent_id}">parent</a>`;
}
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://konachan.com/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+/),
};
}),
};
};
+62
View File
@@ -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://konachan.com/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} - Konachan.com Anime Wallpapers`,
link: 'https://konachan.com/post/popular_recent',
item: posts.map((post) => {
const content = (url) => {
let result = `<img src="${url}" />`;
if (post.source) {
result += `<a href="${post.source}">source</a>`;
}
if (post.parent_id) {
result += `<a href="https://konachan.com/post/show/${post.parent_id}">parent</a>`;
}
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://konachan.com/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+/),
};
}),
};
};