Skip to content

Commit 4bd70f4

Browse files
authored
Merge pull request #177 from primer/fix-frontmatter
Fix frontmatter GraphQL error
2 parents f8ca462 + a05d7ce commit 4bd70f4

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

theme/gatsby-node.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const readPkgUp = require('read-pkg-up')
33
const getPkgRepo = require('get-pkg-repo')
44
const axios = require('axios')
55
const uniqBy = require('lodash.uniqby')
6+
const extractExports = require(`gatsby-plugin-mdx/utils/extract-exports`)
7+
const mdx = require(`gatsby-plugin-mdx/utils/mdx`)
68

79
const CONTRIBUTOR_CACHE = new Map()
810

@@ -14,12 +16,7 @@ exports.createPages = async ({graphql, actions}, themeOptions) => {
1416
allMdx {
1517
nodes {
1618
fileAbsolutePath
17-
frontmatter {
18-
title
19-
status
20-
source
21-
additionalContributors
22-
}
19+
rawBody
2320
tableOfContents(maxDepth: 3)
2421
parent {
2522
... on File {
@@ -63,6 +60,11 @@ exports.createPages = async ({graphql, actions}, themeOptions) => {
6360
contributors = await fetchContributors(repo, fileRelativePath, process.env.GITHUB_TOKEN)
6461
}
6562

63+
// Copied from gatsby-plugin-mdx (https://git.io/JUs3H)
64+
// as a workaround for https://github.com/gatsbyjs/gatsby/issues/21837
65+
const code = await mdx(node.rawBody)
66+
const {frontmatter} = extractExports(code)
67+
6668
actions.createPage({
6769
path: pagePath,
6870
component: node.fileAbsolutePath,
@@ -74,7 +76,7 @@ exports.createPages = async ({graphql, actions}, themeOptions) => {
7476
// for us here, and does on the first build,
7577
// but when HMR kicks in the frontmatter is lost.
7678
// The solution is to include it here explicitly.
77-
frontmatter: node.frontmatter,
79+
frontmatter,
7880
},
7981
})
8082
}),

theme/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@primer/gatsby-theme-doctocat",
3-
"version": "0.24.0",
3+
"version": "0.24.1",
44
"main": "index.js",
55
"license": "MIT",
66
"scripts": {

0 commit comments

Comments
 (0)