Files
RSSHub/lib/v2/mygopen/index.js
2021-11-27 08:50:29 +00:00

30 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const label = ctx.params.label ?? '';
const rootUrl = 'https://www.mygopen.com';
const currentUrl = `${rootUrl}${label ? `/search/label/${label}` : ''}`;
const apiUrl = `${rootUrl}/feeds/posts/default${label ? `/-/${label}` : ''}?alt=json-in-script&max-results=${ctx.query.limit ? parseInt(ctx.query.limit) : 50}`;
const response = await got({
method: 'get',
url: apiUrl,
});
const items = JSON.parse(response.data.match(/gdata\.io\.handleScriptLoaded\((.*)\);/)[1]).feed.entry.map((item) => ({
title: item.title.$t,
description: item.content.$t,
pubDate: parseDate(item.published.$t),
link: item.link.pop().href,
}));
ctx.state.data = {
title: `MyGoPen${label ? `: ${label}` : ''}`,
link: currentUrl,
item: items,
description: '詐騙與謠言頻傳的年代「MyGoPen這是假消息」提醒網路使用者隨時要用謹慎懷疑的態度面對網路上的消息。',
};
};