feat(yande.re):enclosure url (#2909)

This commit is contained in:
SettingDust
2019-08-22 19:36:06 +08:00
committed by DIYgod
parent 52342a2a9f
commit a04ed379c2
+29 -32
View File
@@ -4,7 +4,6 @@ module.exports = async (ctx) => {
const { period = '1d' } = ctx.params;
const response = await got({
method: 'get',
url: 'https://yande.re/post/popular_recent.json',
params: {
period,
@@ -14,45 +13,43 @@ module.exports = async (ctx) => {
const posts = response.data;
const titles = {
'1d': 'Exploring last 24 hours ',
'1w': 'Exploring last week',
'1m': 'Exploring last month',
'1y': 'Exploring last year',
'1d': 'Last 24 hours',
'1w': 'Last week',
'1m': 'Last month',
'1y': 'Last year',
};
const title = titles[period] || titles['1d'];
const mime = {
jpg: 'jpeg',
png: 'png',
};
const title = titles[period];
ctx.state.data = {
title: `${title} - yande.re`,
link: 'https://yande.re/post/popular_recent',
item: posts.map((post) => {
const content = (url) => {
let result = `<img referrerpolicy="no-referrer" src="${url}" />`;
link: `https://yande.re/post/popular_recent?period=${period}`,
item: posts.map((post) => ({
title: `${post.tags} Rating:${post.rating} Score:${post.score}`,
id: `${ctx.path}#${post.id}`,
guid: `${ctx.path}#${post.id}`,
link: `https://yande.re/post/show/${post.id}`,
author: post.author,
pubDate: new Date(post.created_at * 1e3).toUTCString(),
description: (() => {
const result = [`<img referrerpolicy="no-referrer" src="${post.sample_url}" />`];
result.push(`<p>Rating:${post.rating}</p> <p>Score:${post.score}</p>`);
if (post.source) {
result += `<a href="${post.source}">source</a>`;
result.push(`<a href="${post.source}">Source</a>`);
}
if (post.parent_id) {
result += `<a href="https://yande.re/post/show/${post.parent_id}">parent</a>`;
result.push(`<a href="https://yande.re/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://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: { html: content(post.file_url) },
image: post.file_url,
category: post.tags.split(/\s+/),
};
}),
return result.join('');
})(),
enclosure_url: post.file_url,
enclosure_type: `image/${mime[post.file_ext]}`,
category: post.tags.split(/\s+/),
})),
};
};