File tree 7 files changed +26
-12
lines changed
7 files changed +26
-12
lines changed Original file line number Diff line number Diff line change 12
12
"dependencies" : {
13
13
"@mapbox/rehype-prism" : " ^0.5.0" ,
14
14
"@svgr/webpack" : " ^5.4.0" ,
15
+ "@types/js-yaml" : " ^3.12.5" ,
15
16
"date-fns" : " ^2.11.1" ,
16
17
"gray-matter" : " ^4.0.2" ,
18
+ "js-yaml" : " ^3.14.0" ,
17
19
"next" : " 9.5.1" ,
18
20
"next-mdx-enhanced" : " ^3.1.0" ,
19
21
"normalize.css" : " ^8.0.1" ,
Original file line number Diff line number Diff line change 1
- import { parseISO , formatISO , format } from "date-fns" ;
1
+ import { format , formatISO } from "date-fns" ;
2
2
3
- export default function Date ( { dateString } : { dateString : string } ) {
4
- const date = parseISO ( dateString ) ;
3
+ type Props = {
4
+ date : Date ;
5
+ } ;
6
+ export default function Date ( { date } : Props ) {
5
7
return (
6
8
< time dateTime = { formatISO ( date ) } >
7
9
< span > { format ( date , "LLLL d, yyyy" ) } </ span >
Original file line number Diff line number Diff line change 1
1
import { PostContent } from "../lib/posts" ;
2
2
import Date from "./Date" ;
3
3
import Link from "next/link" ;
4
+ import { parseISO } from "date-fns" ;
4
5
5
6
type Props = {
6
7
post : PostContent ;
@@ -9,7 +10,7 @@ export default function PostItem({ post }: Props) {
9
10
return (
10
11
< Link href = { "/posts/" + post . slug } >
11
12
< a >
12
- < Date dateString = { post . date } />
13
+ < Date date = { parseISO ( post . date ) } />
13
14
< h2 > { post . title } </ h2 >
14
15
< style jsx >
15
16
{ `
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ type Props = {
7
7
url : string ;
8
8
title : string ;
9
9
keywords ?: string [ ] ;
10
- dateString : string ;
10
+ date : Date ;
11
11
author ?: string ;
12
12
image ?: string ;
13
13
description ?: string ;
@@ -16,12 +16,11 @@ export default function JsonLdMeta({
16
16
url,
17
17
title,
18
18
keywords,
19
- dateString ,
19
+ date ,
20
20
author,
21
21
image,
22
22
description,
23
23
} : Props ) {
24
- const date = parseISO ( dateString ) ;
25
24
return (
26
25
< script
27
26
{ ...jsonLdScriptProps < BlogPosting > ( {
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ import { getTag } from "../lib/tags";
16
16
17
17
type Props = {
18
18
title : string ;
19
- date : string ;
19
+ date : Date ;
20
20
slug : string ;
21
21
description : string ;
22
22
tags : string [ ] ;
@@ -56,7 +56,7 @@ export default function Index({
56
56
url = { `/posts/${ slug } ` }
57
57
title = { title }
58
58
keywords = { keywords }
59
- dateString = { date }
59
+ date = { date }
60
60
author = { authorName }
61
61
description = { description }
62
62
/>
@@ -67,7 +67,7 @@ export default function Index({
67
67
< h1 > { title } </ h1 >
68
68
< div className = { "metadata" } >
69
69
< div >
70
- < Date dateString = { date } />
70
+ < Date date = { date } />
71
71
</ div >
72
72
< div >
73
73
< Author author = { getAuthor ( author ) } />
Original file line number Diff line number Diff line change 1
1
import fs from "fs" ;
2
2
import matter from "gray-matter" ;
3
3
import path from "path" ;
4
+ import yaml from "js-yaml" ;
4
5
5
6
const postsDirectory = path . join ( process . cwd ( ) , "src/pages/posts" ) ;
6
7
@@ -27,7 +28,11 @@ function fetchPostContent(): PostContent[] {
27
28
const fileContents = fs . readFileSync ( fullPath , "utf8" ) ;
28
29
29
30
// Use gray-matter to parse the post metadata section
30
- const matterResult = matter ( fileContents ) ;
31
+ const matterResult = matter ( fileContents , {
32
+ engines : {
33
+ yaml : ( s ) => yaml . safeLoad ( s , { schema : yaml . JSON_SCHEMA } ) ,
34
+ } ,
35
+ } ) ;
31
36
const matterData = matterResult . data as {
32
37
date : string ;
33
38
title : string ;
Original file line number Diff line number Diff line change 1727
1727
jest-diff "^25.2.1"
1728
1728
pretty-format "^25.2.1"
1729
1729
1730
+ " @types/js-yaml@^3.12.5 " :
1731
+ version "3.12.5"
1732
+ resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.12.5.tgz#136d5e6a57a931e1cce6f9d8126aa98a9c92a6bb"
1733
+ integrity sha512-JCcp6J0GV66Y4ZMDAQCXot4xprYB+Zfd3meK9+INSJeVZwJmHAW30BBEEkPzXswMXuiyReUGOP3GxrADc9wPww==
1734
+
1730
1735
" @types/json-schema@^7.0.4 " :
1731
1736
version "7.0.5"
1732
1737
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.5.tgz#dcce4430e64b443ba8945f0290fb564ad5bac6dd"
@@ -5399,7 +5404,7 @@ jest@^26.3.0:
5399
5404
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
5400
5405
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
5401
5406
5402
- js-yaml@^3.11.0, js-yaml@^3.13.1 :
5407
+ js-yaml@^3.11.0, js-yaml@^3.13.1, js-yaml@^3.14.0 :
5403
5408
version "3.14.0"
5404
5409
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.0.tgz#a7a34170f26a21bb162424d8adacb4113a69e482"
5405
5410
integrity sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==
You can’t perform that action at this time.
0 commit comments