Files
RSSHub/lib/v2/bsky/posts.js
T
2024-02-28 16:25:59 +08:00

43 lines
1.5 KiB
JavaScript

import { parseDate } from '@/utils/parse-date';
const { resolveHandle, getProfile, getAuthorFeed } = require('./utils');
import { art } from '@/utils/render';
const path = require('path');
module.exports = async (ctx) => {
const { handle } = ctx.params;
const DID = await resolveHandle(handle, ctx.cache.tryGet);
const profile = await getProfile(DID, ctx.cache.tryGet);
const authorFeed = await getAuthorFeed(DID, ctx.cache.tryGet);
const items = authorFeed.feed.map(({ post }) => ({
title: post.record.text.split('\n')[0],
description: art(path.join(__dirname, 'templates/post.art'), {
text: post.record.text.replaceAll('\n', '<br>'),
embed: post.embed,
// embed.$type "app.bsky.embed.record#view" and "app.bsky.embed.recordWithMedia#view"
// are not handled
}),
author: post.author.displayName,
pubDate: parseDate(post.record.createdAt),
link: `https://bsky.app/profile/${post.author.handle}/post/${post.uri.split('app.bsky.feed.post/')[1]}`,
upvotes: post.likeCount,
comments: post.replyCount,
}));
ctx.set('data', {
title: `${profile.displayName} (@${profile.handle}) — Bluesky`,
description: profile.description?.replaceAll('\n', ' '),
link: `https://bsky.app/profile/${profile.handle}`,
image: profile.banner,
icon: profile.avatar,
logo: profile.avatar,
item: items,
});
ctx.set('json', {
DID,
profile,
authorFeed,
});
};