Skip to content

Commit 58bbd5e

Browse files
committed
added blogs
1 parent 2b1b215 commit 58bbd5e

File tree

5 files changed

+106
-2
lines changed

5 files changed

+106
-2
lines changed

src/components/Footer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const FooterLinks = () => {
130130
<Flex
131131
gap={isUnder600 ? '1.5rem' : '4rem'}
132132
columnGap={'1rem'}
133+
rowGap={'1rem'}
133134
maxWidth={'1200px'}
134135
margin={'0.5rem auto'}
135136
justifyContent={'center'}

src/lib/constant.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export const ROUTING = {
8181
rooms: '/timetable/rooms',
8282
clash_resolver: '/util/timetable_clashresolver',
8383
room_activities: '/room-activities',
84-
past_papers: '/pastpaper'
84+
past_papers: '/pastpaper',
85+
blogs: '/blogs'
8586
};
8687

8788
export const APIS_ENDPOINTS = {

src/pages/_app.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ export default function App({ Component, pageProps }: AppProps) {
9595
<Component {...pageProps} />
9696
</ChatAppStateProvider.Provider>
9797
{footerPages.includes(router.pathname) && <Footer fixedBottom={false} />}
98-
{router.pathname.includes('/timetable/') && <Footer fixedBottom={false} />}
98+
{(router.pathname.includes('/timetable/') || router.pathname.includes('/blogs')) && (
99+
<Footer fixedBottom={false} />
100+
)}
99101
</AppStyleProvider>
100102
</UserCredentialsContext.Provider>
101103
</>

src/pages/blogs/[id].tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Flex } from '@chakra-ui/react';
2+
import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from 'next';
3+
4+
interface Post {
5+
content: {
6+
rendered: string;
7+
};
8+
title: {
9+
rendered: string;
10+
};
11+
}
12+
13+
export const getStaticPaths = (async () => {
14+
const res = await fetch('https://sneakword.online/wp-json/wp/v2/posts?_fields=id');
15+
const posts = await res.json();
16+
const paths = posts.map((post: any) => ({
17+
params: { id: post.id + '' }
18+
}));
19+
20+
return {
21+
paths,
22+
fallback: true
23+
};
24+
}) satisfies GetStaticPaths;
25+
26+
export const getStaticProps = (async (context: GetStaticPropsContext) => {
27+
const id = context.params!.id;
28+
const res = await fetch(`https://sneakword.online/wp-json/wp/v2/posts/${id}`);
29+
const post = (await res.json()) as Post;
30+
return {
31+
props: { post: post }
32+
};
33+
}) satisfies GetStaticProps<{
34+
post: Post;
35+
}>;
36+
37+
export default function BlogDetailPage({ post }: { post: Post }) {
38+
return (
39+
<Flex maxWidth={'1250px'} mx={'auto'} w={'full'} p={2}>
40+
<div
41+
className="mark-down"
42+
dangerouslySetInnerHTML={{
43+
__html: `
44+
<h1>${post.title.rendered}</h1>
45+
${post.content.rendered}`
46+
}}></div>
47+
</Flex>
48+
);
49+
}

src/pages/blogs/index.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Flex, List, ListItem, Stack, Text } from '@chakra-ui/react';
2+
import type { InferGetStaticPropsType, GetStaticProps } from 'next';
3+
import Link from 'next/link';
4+
5+
type Posts = {
6+
id: string;
7+
title: {
8+
rendered: string;
9+
};
10+
}[];
11+
12+
export const getStaticProps = (async (context) => {
13+
const res = await fetch('https://sneakword.online/wp-json/wp/v2/posts?_fields=title,id');
14+
const posts = (await res.json()) as Posts;
15+
return { props: { posts }, revalidate: 60 * 60 * 12 };
16+
}) satisfies GetStaticProps<{
17+
posts: Posts;
18+
}>;
19+
20+
export default function Page({ posts }: InferGetStaticPropsType<typeof getStaticProps>) {
21+
console.log(posts);
22+
return (
23+
<Flex maxWidth={'1200px'} mx={'auto'} w={'full'} p={2} justify={'center'} flexDir={'column'}>
24+
<Stack mt={6}>
25+
<Text as={'h1'} fontSize={'3xl'} fontWeight={'bold'}>
26+
Blogs
27+
</Text>
28+
</Stack>
29+
<List mt={'6'} w={'full'}>
30+
{posts.map((post, idx) => (
31+
<Link href={`/blogs/${post.id}`} key={idx}>
32+
<ListItem
33+
p={4}
34+
rounded={'md'}
35+
border={'1px solid var(--border-color)'}
36+
fontSize={'xl'}
37+
fontWeight={'medium'}
38+
_hover={{
39+
bg: 'var(--card-dark-color)',
40+
cursor: 'pointer'
41+
}}
42+
my={3}
43+
bg={'var(--card-color)'}>
44+
{post.title.rendered}
45+
</ListItem>
46+
</Link>
47+
))}
48+
</List>
49+
</Flex>
50+
);
51+
}

0 commit comments

Comments
 (0)