-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b1b215
commit 58bbd5e
Showing
5 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Flex } from '@chakra-ui/react'; | ||
import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from 'next'; | ||
|
||
interface Post { | ||
content: { | ||
rendered: string; | ||
}; | ||
title: { | ||
rendered: string; | ||
}; | ||
} | ||
|
||
export const getStaticPaths = (async () => { | ||
const res = await fetch('https://sneakword.online/wp-json/wp/v2/posts?_fields=id'); | ||
const posts = await res.json(); | ||
const paths = posts.map((post: any) => ({ | ||
params: { id: post.id + '' } | ||
})); | ||
|
||
return { | ||
paths, | ||
fallback: true | ||
}; | ||
}) satisfies GetStaticPaths; | ||
|
||
export const getStaticProps = (async (context: GetStaticPropsContext) => { | ||
const id = context.params!.id; | ||
const res = await fetch(`https://sneakword.online/wp-json/wp/v2/posts/${id}`); | ||
const post = (await res.json()) as Post; | ||
return { | ||
props: { post: post } | ||
}; | ||
}) satisfies GetStaticProps<{ | ||
post: Post; | ||
}>; | ||
|
||
export default function BlogDetailPage({ post }: { post: Post }) { | ||
return ( | ||
<Flex maxWidth={'1250px'} mx={'auto'} w={'full'} p={2}> | ||
<div | ||
className="mark-down" | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
<h1>${post.title.rendered}</h1> | ||
${post.content.rendered}` | ||
}}></div> | ||
</Flex> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Flex, List, ListItem, Stack, Text } from '@chakra-ui/react'; | ||
import type { InferGetStaticPropsType, GetStaticProps } from 'next'; | ||
import Link from 'next/link'; | ||
|
||
type Posts = { | ||
id: string; | ||
title: { | ||
rendered: string; | ||
}; | ||
}[]; | ||
|
||
export const getStaticProps = (async (context) => { | ||
const res = await fetch('https://sneakword.online/wp-json/wp/v2/posts?_fields=title,id'); | ||
const posts = (await res.json()) as Posts; | ||
return { props: { posts }, revalidate: 60 * 60 * 12 }; | ||
}) satisfies GetStaticProps<{ | ||
posts: Posts; | ||
}>; | ||
|
||
export default function Page({ posts }: InferGetStaticPropsType<typeof getStaticProps>) { | ||
console.log(posts); | ||
return ( | ||
<Flex maxWidth={'1200px'} mx={'auto'} w={'full'} p={2} justify={'center'} flexDir={'column'}> | ||
<Stack mt={6}> | ||
<Text as={'h1'} fontSize={'3xl'} fontWeight={'bold'}> | ||
Blogs | ||
</Text> | ||
</Stack> | ||
<List mt={'6'} w={'full'}> | ||
{posts.map((post, idx) => ( | ||
<Link href={`/blogs/${post.id}`} key={idx}> | ||
<ListItem | ||
p={4} | ||
rounded={'md'} | ||
border={'1px solid var(--border-color)'} | ||
fontSize={'xl'} | ||
fontWeight={'medium'} | ||
_hover={{ | ||
bg: 'var(--card-dark-color)', | ||
cursor: 'pointer' | ||
}} | ||
my={3} | ||
bg={'var(--card-color)'}> | ||
{post.title.rendered} | ||
</ListItem> | ||
</Link> | ||
))} | ||
</List> | ||
</Flex> | ||
); | ||
} |