|
1 | | -import Head from "next/head"; |
2 | 1 | import React from "react"; |
3 | 2 | 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"; |
14 | 13 | import { getAuthor } from "../lib/authors"; |
15 | 14 | import { getTag } from "../lib/tags"; |
16 | | - |
| 15 | +import { MdxRemote } from "next-mdx-remote/types" |
| 16 | +import hydrate from "next-mdx-remote/hydrate" |
17 | 17 |
|
18 | 18 | type Props = { |
19 | 19 | title: string; |
20 | | - date: string; |
| 20 | + date: Date; |
21 | 21 | slug: string; |
22 | 22 | tags: string[]; |
23 | 23 | author: string; |
| 24 | + components: MdxRemote.Components; |
| 25 | + source: MdxRemote.Source; |
24 | 26 | description?: string; |
25 | 27 | }; |
26 | | -export default function Index({ |
| 28 | +export default function PostLayout({ |
27 | 29 | title, |
28 | 30 | date, |
29 | 31 | slug, |
30 | 32 | author, |
31 | 33 | tags, |
| 34 | + source, |
| 35 | + components, |
32 | 36 | description = "", |
33 | 37 | }: Props) { |
| 38 | + const content = hydrate(source, { components }); |
34 | 39 | const keywords = tags.map((it) => getTag(it).name); |
35 | 40 | 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)} /> |
74 | 77 | </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 /> |
88 | 78 | </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 | + {` |
94 | 98 | .container { |
95 | 99 | display: block; |
96 | 100 | max-width: 36rem; |
@@ -132,9 +136,9 @@ export default function Index({ |
132 | 136 | } |
133 | 137 | } |
134 | 138 | `} |
135 | | - </style> |
136 | | - <style global jsx> |
137 | | - {` |
| 139 | + </style> |
| 140 | + <style global jsx> |
| 141 | + {` |
138 | 142 | /* Syntax highlighting */ |
139 | 143 | .token.comment, |
140 | 144 | .token.prolog, |
@@ -232,8 +236,7 @@ export default function Index({ |
232 | 236 | color: #005cc5; |
233 | 237 | } |
234 | 238 | `} |
235 | | - </style> |
236 | | - </Layout> |
237 | | - ); |
238 | | - }; |
| 239 | + </style> |
| 240 | + </Layout> |
| 241 | + ); |
239 | 242 | } |
0 commit comments