Skip to content

Commit a486d56

Browse files
make the PostLayout component
1 parent 6842fd1 commit a486d56

File tree

1 file changed

+80
-77
lines changed

1 file changed

+80
-77
lines changed

src/components/PostLayout.tsx

Lines changed: 80 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,100 @@
1-
import Head from "next/head";
21
import React from "react";
32
import styles from "../../public/styles/content.module.css";
4-
import Author from "../components/Author";
5-
import Copyright from "../components/Copyright";
6-
import Date from "../components/Date";
7-
import Layout from "../components/Layout";
8-
import BasicMeta from "../components/meta/BasicMeta";
9-
import JsonLdMeta from "../components/meta/JsonLdMeta";
10-
import OpenGraphMeta from "../components/meta/OpenGraphMeta";
11-
import TwitterCardMeta from "../components/meta/TwitterCardMeta";
12-
import { SocialList } from "../components/SocialList";
13-
import TagButton from "../components/TagButton";
3+
import Author from "./Author";
4+
import Copyright from "./Copyright";
5+
import Date from "./Date";
6+
import Layout from "./Layout";
7+
import BasicMeta from "./meta/BasicMeta";
8+
import JsonLdMeta from "./meta/JsonLdMeta";
9+
import OpenGraphMeta from "./meta/OpenGraphMeta";
10+
import TwitterCardMeta from "./meta/TwitterCardMeta";
11+
import { SocialList } from "./SocialList";
12+
import TagButton from "./TagButton";
1413
import { getAuthor } from "../lib/authors";
1514
import { getTag } from "../lib/tags";
16-
15+
import { MdxRemote } from "next-mdx-remote/types"
16+
import hydrate from "next-mdx-remote/hydrate"
1717

1818
type Props = {
1919
title: string;
20-
date: string;
20+
date: Date;
2121
slug: string;
2222
tags: string[];
2323
author: string;
24+
components: MdxRemote.Components;
25+
source: MdxRemote.Source;
2426
description?: string;
2527
};
26-
export default function Index({
28+
export default function PostLayout({
2729
title,
2830
date,
2931
slug,
3032
author,
3133
tags,
34+
source,
35+
components,
3236
description = "",
3337
}: Props) {
38+
const content = hydrate(source, { components });
3439
const keywords = tags.map((it) => getTag(it).name);
3540
const authorName = getAuthor(author).name;
36-
return ({ children: content }) => {
37-
return (
38-
<Layout>
39-
<BasicMeta
40-
url={`/posts/${slug}`}
41-
title={title}
42-
keywords={keywords}
43-
description={description}
44-
/>
45-
<TwitterCardMeta
46-
url={`/posts/${slug}`}
47-
title={title}
48-
description={description}
49-
/>
50-
<OpenGraphMeta
51-
url={`/posts/${slug}`}
52-
title={title}
53-
description={description}
54-
/>
55-
<JsonLdMeta
56-
url={`/posts/${slug}`}
57-
title={title}
58-
keywords={keywords}
59-
date={date}
60-
author={authorName}
61-
description={description}
62-
/>
63-
<div className={"container"}>
64-
<article>
65-
<header>
66-
<h1>{title}</h1>
67-
<div className={"metadata"}>
68-
<div>
69-
<Date date={date} />
70-
</div>
71-
<div>
72-
<Author author={getAuthor(author)} />
73-
</div>
41+
return (
42+
<Layout>
43+
<BasicMeta
44+
url={`/posts/${slug}`}
45+
title={title}
46+
keywords={keywords}
47+
description={description}
48+
/>
49+
<TwitterCardMeta
50+
url={`/posts/${slug}`}
51+
title={title}
52+
description={description}
53+
/>
54+
<OpenGraphMeta
55+
url={`/posts/${slug}`}
56+
title={title}
57+
description={description}
58+
/>
59+
<JsonLdMeta
60+
url={`/posts/${slug}`}
61+
title={title}
62+
keywords={keywords}
63+
date={date}
64+
author={authorName}
65+
description={description}
66+
/>
67+
<div className={"container"}>
68+
<article>
69+
<header>
70+
<h1>{title}</h1>
71+
<div className={"metadata"}>
72+
<div>
73+
<Date date={date} />
74+
</div>
75+
<div>
76+
<Author author={getAuthor(author)} />
7477
</div>
75-
</header>
76-
<div className={styles.content}>{content}</div>
77-
<ul className={"tag-list"}>
78-
{tags.map((it, i) => (
79-
<li key={i}>
80-
<TagButton tag={getTag(it)} />
81-
</li>
82-
))}
83-
</ul>
84-
</article>
85-
<footer>
86-
<div className={"social-list"}>
87-
<SocialList />
8878
</div>
89-
<Copyright />
90-
</footer>
91-
</div>
92-
<style jsx>
93-
{`
79+
</header>
80+
<div className={styles.content}>{content}</div>
81+
<ul className={"tag-list"}>
82+
{tags.map((it, i) => (
83+
<li key={i}>
84+
<TagButton tag={getTag(it)} />
85+
</li>
86+
))}
87+
</ul>
88+
</article>
89+
<footer>
90+
<div className={"social-list"}>
91+
<SocialList />
92+
</div>
93+
<Copyright />
94+
</footer>
95+
</div>
96+
<style jsx>
97+
{`
9498
.container {
9599
display: block;
96100
max-width: 36rem;
@@ -132,9 +136,9 @@ export default function Index({
132136
}
133137
}
134138
`}
135-
</style>
136-
<style global jsx>
137-
{`
139+
</style>
140+
<style global jsx>
141+
{`
138142
/* Syntax highlighting */
139143
.token.comment,
140144
.token.prolog,
@@ -232,8 +236,7 @@ export default function Index({
232236
color: #005cc5;
233237
}
234238
`}
235-
</style>
236-
</Layout>
237-
);
238-
};
239+
</style>
240+
</Layout>
241+
);
239242
}

0 commit comments

Comments
 (0)