File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed
Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff 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
7676This endpoint will return a JSON response of a post by id.
7777
Original file line number Diff line number Diff line change 11import { supabaseAdmin } from "@changes-page/supabase/admin" ;
22import { IPost } from "@changes-page/supabase/types/page" ;
3+ import { convertMarkdownToPlainText } from "@changes-page/utils" ;
34import type { NextApiRequest , NextApiResponse } from "next" ;
45import { allowCors } from "../../../lib/cors" ;
56import {
@@ -11,7 +12,7 @@ import { getPageUrl, getPostUrl } from "../../../lib/url";
1112type IPostWithUrl = Pick <
1213 IPost ,
1314 "id" | "title" | "content" | "tags" | "created_at"
14- > & { url : string } ;
15+ > & { url : string ; plain_text_content : string } ;
1516
1617async 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 ) ;
You can’t perform that action at this time.
0 commit comments