diff --git a/public/_headers b/public/_headers index 2a5f7428..91574bd4 100644 --- a/public/_headers +++ b/public/_headers @@ -3,3 +3,6 @@ /api/activitypub/actor Content-Type: application/activity+json + +/api/activitypub/note/* + Content-Type: application/activity+json diff --git a/src/pages/api/activitypub/note/[id].ts b/src/pages/api/activitypub/note/[id].ts new file mode 100644 index 00000000..11c3d2d6 --- /dev/null +++ b/src/pages/api/activitypub/note/[id].ts @@ -0,0 +1,33 @@ +import getAllPosts from '@utils/getAllPosts'; +import type { APIRoute } from 'astro'; + +export const getStaticPaths = async () => { + const posts = await getAllPosts(); + return posts.map((post) => ({ params: { id: post.url!.substring(7).replaceAll('/', '_') } })); +}; + +export const GET: APIRoute = async ({ params }) => { + const allPosts = await getAllPosts(); + const post = allPosts.find((item) => item.url === `/posts/${params.id!.replaceAll('_', '/')}`)!; + + return new Response( + JSON.stringify({ + '@context': [ + 'https://www.w3.org/ns/activitystreams', + { + HashTag: 'as:HashTag', + }, + ], + id: `https://blog.yunyi.beiyan.us/api/activitypub/note/${post.url}`, + type: 'Note', + attributedTo: 'https://blog.yunyi.beiyan.us/api/activitypub/actor', + cc: ['https://blog.yunyi.beiyan.us/api/activitypub/followers'], + content: `
发布了新的博文:${
+ post.frontmatter.title
+ }
${post.frontmatter.description || ''}