Skip to content

Commit 3b83160

Browse files
committed
resolve markdown content by link
1 parent 1599a0f commit 3b83160

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

gatsby-node.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ exports.createSchemaCustomization = ({ actions, schema }) => {
1111

1212
createTypes(gql`
1313
type BlogPost implements Node
14-
@dontInfer
15-
@childOf(types: ["File", "MarkdownRemark"])
14+
@childOf(types: ["MarkdownRemark"])
1615
{
1716
postId: String!
1817
title: String!
19-
excerpt: String!
20-
rawContent: String! # raw markdown content, better if it would be fully parsed & rendered at the build time
2118
tags: [String!]!
2219
date: Date! @dateformat(formatString: "YYYY-MM-DD")
2320
authors: [String!]!
2421
guestBio: String
22+
remark: MarkdownRemark! @link # backlink to the parent
2523
}
2624
`);
2725
};
@@ -52,8 +50,6 @@ exports.onCreateNode = async ({
5250
id: nodeId,
5351
postId: permalink.replace('/blog/', '').replace(/\/$/, ''),
5452
title: node.frontmatter.title,
55-
excerpt: node.excerpt,
56-
rawContent: node.rawMarkdownBody,
5753
tags: node.frontmatter.tags ?? [],
5854
date: node.frontmatter.date,
5955
authors: (node.frontmatter.byline ?? '')
@@ -65,6 +61,7 @@ exports.onCreateNode = async ({
6561

6662
createNode({
6763
...blogPostContent,
64+
remark: node.id,
6865
parent: node.id,
6966
children: [],
7067
internal: {

src/components/BlogPost/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import Marked from "../Marked"
55
export const fragments = graphql`
66
fragment BlogPost_post on BlogPost {
77
title
8-
rawContent
98
date
109
authors
1110
tags
1211
guestBio
12+
remark {
13+
rawMarkdownBody
14+
}
1315
}
1416
`;
1517

@@ -41,7 +43,7 @@ const BlogPost: React.FC<Props> = ({
4143
<p className="guestBio">{`This guest article contributed by ${byline}, ${post.guestBio}.`}</p>
4244
)}
4345

44-
<Marked>{post.rawContent}</Marked>
46+
<Marked>{post.remark.rawMarkdownBody}</Marked>
4547
</div>
4648
)
4749
}

src/components/BlogPostPreview/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { graphql, Link } from "gatsby"
44
export const fragments = graphql`
55
fragment BlogPostPreview_post on BlogPost {
66
title
7-
excerpt
87
date
98
authors
109
tags
1110
postPath: gatsbyPath(filePath: "/blog/{BlogPost.postId}")
11+
remark {
12+
excerpt
13+
}
1214
}
1315
`;
1416

@@ -36,7 +38,7 @@ const BlogPostPreview: React.FC<Props> = ({
3638
))}
3739
</div>
3840

39-
<p>{post.excerpt}</p>
41+
<p>{post.remark.excerpt}</p>
4042
</div>
4143
)
4244

0 commit comments

Comments
 (0)