Skip to content

Commit

Permalink
feat(route/medium): add medium feeds by official rss
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Jan 6, 2025
1 parent 2f4653b commit 20fc160
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/routes/medium/feed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Route, ViewType } from '@/types';
import parser from '@/utils/rss-parser';
import { parseDate } from '@/utils/parse-date';
import InvalidParameterError from '@/errors/types/invalid-parameter';

export const route: Route = {
path: '/feed/:user',
categories: ['blog'],
view: ViewType.SocialMedia,
example: '/medium/feed/zhgchgli',
parameters: { user: 'Username of the Medium' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['medium.com/@:user'],
target: '/feed/:user',
},
],
name: 'Medium Feed',
maintainers: ['pseudoyu'],
handler,
};

async function handler(ctx) {
const user = ctx.req.param('user');

if (!user) {
throw new InvalidParameterError('Invalid user');
}

const feed = await parser.parseURL(`https://medium.com/feed/@${user}`);

return {
title: feed.title ?? 'Medium',
description: feed.description ?? `${user}'s Medium`,
link: feed.link ?? `https://medium.com/@${user}`,
image: feed.image?.url ?? '',
item: feed.items.map((item) => ({
title: item.title ?? 'Untitled',
description: item['content:encoded'] ?? item.content ?? '',
link: item.link ?? '',
pubDate: item.pubDate ? parseDate(item.pubDate) : undefined,
guid: item.guid ?? '',
author: item.creator ?? user,
})),
};
}

0 comments on commit 20fc160

Please sign in to comment.