Skip to content

Commit 5ec59b2

Browse files
committed
Address code review
1 parent fdeb4d9 commit 5ec59b2

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

apps/docs/content/docs/api/page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ GET https://yourpage.changes.page/changes.json
7171
]
7272
```
7373

74-
### Get a posts by id
74+
### Get a post by id
7575

7676
This endpoint will return a JSON response of a post by id.
7777

apps/page/pages/api/post/[id].ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { supabaseAdmin } from "@changes-page/supabase/admin";
22
import { IPost } from "@changes-page/supabase/types/page";
3+
import { convertMarkdownToPlainText } from "@changes-page/utils";
34
import type { NextApiRequest, NextApiResponse } from "next";
45
import { allowCors } from "../../../lib/cors";
56
import {
@@ -11,7 +12,7 @@ import { getPageUrl, getPostUrl } from "../../../lib/url";
1112
type IPostWithUrl = Pick<
1213
IPost,
1314
"id" | "title" | "content" | "tags" | "created_at"
14-
> & { url: string };
15+
> & { url: string; plain_text_content: string };
1516

1617
async function handler(
1718
req: NextApiRequest,
@@ -59,14 +60,13 @@ async function handler(
5960
return;
6061
}
6162

62-
const postsWithUrl = posts.map((post) => {
63-
return {
64-
...post,
65-
url: getPostUrl(pageUrl, post),
66-
};
67-
});
63+
const post = posts[0];
6864

69-
res.status(200).json(postsWithUrl[0] ?? null);
65+
res.status(200).json({
66+
...post,
67+
url: getPostUrl(pageUrl, post),
68+
plain_text_content: convertMarkdownToPlainText(post.content),
69+
});
7070
} catch (e: Error | any) {
7171
console.log("Failed to fetch post [Error]", e);
7272
res.status(404).json(null);

0 commit comments

Comments
 (0)