Skip to content

Commit

Permalink
/api/[name]にアクセスされたときにNoteオブジェクトを返す
Browse files Browse the repository at this point in the history
  • Loading branch information
nagutabby committed Jan 21, 2025
1 parent 9471252 commit 86813b4
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/routes/api/articles/[name]/+server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import type { RequestHandler } from '@sveltejs/kit';
import { getDetail, type Blog } from '$lib/microcms';

export const GET: RequestHandler = async ({ params, request }) => {
const acceptHeader = request.headers.get('Accept');
if (acceptHeader) {
console.log('acceptHeader: ', acceptHeader);
export const GET: RequestHandler = async ({ params }) => {
const { name } = params;
let articleData: Blog | null;

// 記事データの取得
if (name) {
articleData = await getDetail(name);
if (!articleData) {
return new Response('Article not found', { status: 404 });
}
} else {
return new Response('Article not found', { status: 404 });
}
return new Response(null, {

// Noteオブジェクトの定義
const note = {
"id": `https://blog.nagutabby.uk/api/articles/${name}`,
"type": "Note",
"attributedTo": "https://blog.nagutabby.uk/actor",
"name": articleData.title,
"content": `<p>${articleData.title}</p><a href="https://blog.nagutabby.uk/articles/${name}" target="_blank">https://blog.nagutabby.uk/articles/${name}</a>`,
"published": articleData.publishedAt,
"url": `https://blog.nagutabby.uk/api/articles/${name}`,
"to": ["https://www.w3.org/ns/activitystreams#Public"]
};

return new Response(JSON.stringify(note), {
status: 200,
headers: {
'Content-Type': 'application/activity+json'
Expand Down

0 comments on commit 86813b4

Please sign in to comment.