Skip to content

Commit bf22dcb

Browse files
committed
SEO
1 parent e9ddaef commit bf22dcb

File tree

2 files changed

+55
-34
lines changed

2 files changed

+55
-34
lines changed

src/pages/blogs/[id].tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Flex } from '@chakra-ui/react';
22
import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from 'next';
3+
import Head from 'next/head';
34
import { useRouter } from 'next/router';
45
import { useEffect } from 'react';
56

@@ -47,14 +48,20 @@ export default function BlogDetailPage({ post }: { post: Post }) {
4748
if (!post) return <></>;
4849

4950
return (
50-
<Flex maxWidth={'1250px'} mx={'auto'} w={'full'} p={2}>
51-
<div
52-
className="mark-down"
53-
dangerouslySetInnerHTML={{
54-
__html: `
51+
<>
52+
<Head>
53+
<title>{post.title.rendered}</title>
54+
<meta name="description" content={`${post.content.rendered.slice(0, 100)}`} />
55+
</Head>
56+
<Flex maxWidth={'1250px'} mx={'auto'} w={'full'} p={2}>
57+
<div
58+
className="mark-down"
59+
dangerouslySetInnerHTML={{
60+
__html: `
5561
<h1>${post.title.rendered}</h1>
5662
${post.content.rendered}`
57-
}}></div>
58-
</Flex>
63+
}}></div>
64+
</Flex>
65+
</>
5966
);
6067
}

src/pages/blogs/index.tsx

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Flex, List, ListItem, Stack, Text } from '@chakra-ui/react';
22
import type { InferGetStaticPropsType, GetStaticProps } from 'next';
3+
import Head from 'next/head';
34
import Link from 'next/link';
45

56
type Posts = {
@@ -19,32 +20,45 @@ export const getStaticProps = (async (context) => {
1920

2021
export default function Page({ posts }: InferGetStaticPropsType<typeof getStaticProps>) {
2122
return (
22-
<Flex maxWidth={'1200px'} mx={'auto'} w={'full'} p={2} justify={'center'} flexDir={'column'}>
23-
<Stack mt={6}>
24-
<Text as={'h1'} fontSize={'3xl'} fontWeight={'bold'}>
25-
Blogs
26-
</Text>
27-
</Stack>
28-
<List mt={'6'} w={'full'}>
29-
{posts.map((post, idx) => (
30-
<Link href={`/blogs/${post.id}`} key={idx}>
31-
<ListItem
32-
p={4}
33-
rounded={'md'}
34-
border={'1px solid var(--border-color)'}
35-
fontSize={'xl'}
36-
fontWeight={'medium'}
37-
_hover={{
38-
bg: 'var(--card-dark-color)',
39-
cursor: 'pointer'
40-
}}
41-
my={3}
42-
bg={'var(--card-color)'}>
43-
{post.title.rendered}
44-
</ListItem>
45-
</Link>
46-
))}
47-
</List>
48-
</Flex>
23+
<>
24+
<Head>
25+
<title>Blogs</title>
26+
<meta
27+
name="description"
28+
content="Discover leading educational blogs that provide insights and knowledge on various topics."
29+
/>
30+
</Head>
31+
<Flex maxWidth={'1200px'} mx={'auto'} w={'full'} p={2} justify={'center'} flexDir={'column'}>
32+
<Stack mt={6}>
33+
<Text as="h1" fontSize="3xl" fontWeight="bold">
34+
Blogs
35+
</Text>
36+
<Text fontSize="lg" color="gray.600">
37+
Explore our collection of blogs that cover a wide range of educational topics, designed
38+
to inform and inspire you.
39+
</Text>
40+
</Stack>
41+
<List mt={'6'} w={'full'}>
42+
{posts.map((post, idx) => (
43+
<Link href={`/blogs/${post.id}`} key={idx}>
44+
<ListItem
45+
p={4}
46+
rounded={'md'}
47+
border={'1px solid var(--border-color)'}
48+
fontSize={'xl'}
49+
fontWeight={'medium'}
50+
_hover={{
51+
bg: 'var(--card-dark-color)',
52+
cursor: 'pointer'
53+
}}
54+
my={3}
55+
bg={'var(--card-color)'}>
56+
{post.title.rendered}
57+
</ListItem>
58+
</Link>
59+
))}
60+
</List>
61+
</Flex>
62+
</>
4963
);
5064
}

0 commit comments

Comments
 (0)