8000 feat/ SEO in Post. · lostcode-dev/lostcode-blog@f024410 · GitHub
[go: up one dir, main page]

Skip to content

Commit f024410

Browse files
committed
feat/ SEO in Post.
1 parent 7877ea3 commit f024410

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/helpers/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export const getFooter = (post) => {
3030
return RichText.asHtml(post.data.footer) ?? ''
3131
}
3232

33+
export const getKeywords = (post) => {
34+
return post.data.keywords ?? ''
35+
}
36+
3337
export const getContent = (post) => {
3438
const content = post.data.content;
3539
return content.map(el => {

src/pages/posts/[slug].tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GetServerSideProps } from "next";
22
import Head from "next/head";
3-
import { dateToPtbr, getContent, getFooter, getImgUrl, getIntroduction, getTitle } from "../../helpers/util";
3+
import { dateToPtbr, getContent, getFooter, getImgUrl, getIntroduction, getKeywords, getPreviewText, getTitle } from "../../helpers/util";
44
import { api_id, GET_PRISMIC_CLIENT } from "../../services/prismic";
55
import styles from './post.module.scss';
66

@@ -13,6 +13,8 @@ interface PostProps {
1313
image_banner: string;
1414
footer: string;
1515
updatedAt: string;
16+
keywords: string;
17+
previewText: string;
1618
}
1719
}
1820

@@ -21,6 +23,9 @@ export default function Post({ post }: PostProps) {
2123
<>
2224
<Head>
2325
<title>{post.title} | lostCode</title>
26+
<meta name='description' content={post.previewText}/>
27+
<meta name='keywords' content={post.keywords}/>
28+
2429
</Head>
2530

2631
<main className={styles.container}>
@@ -59,6 +64,8 @@ export const getServerSideProps: GetServerSideProps = async ({ req, params }) =>
5964
image_banner: getImgUrl(response),
6065
updatedAt: dateToPtbr(response.last_publication_date),
6166
footer: getFooter(response),
67+
keywords: getKeywords(response),
68+
previewText: getPreviewText(response),
6269
}
6370

6471
return {

0 commit comments

Comments
 (0)
0