Skip to content

Commit

Permalink
✨ Note
Browse files Browse the repository at this point in the history
  • Loading branch information
BeiyanYunyi committed Oct 27, 2023
1 parent c7a2cb6 commit b14ee65
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions public/_headers
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

/api/activitypub/actor
Content-Type: application/activity+json

/api/activitypub/note/*
Content-Type: application/activity+json
33 changes: 33 additions & 0 deletions src/pages/api/activitypub/note/[id].ts
Original file line number Diff line number Diff line change
@@ -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: `<p>发布了新的博文:<a href="https://blog.yunyi.beiyan.us${post.url}">${
post.frontmatter.title
}</a><br>${post.frontmatter.description || ''}</p>`,
published: new Date(post.frontmatter.date).toISOString(),
to: ['https://www.w3.org/ns/activitystreams#Public'],
url: `https://blog.yunyi.beiyan.us${post.url}`,
}),
);
};

0 comments on commit b14ee65

Please sign in to comment.