@primer/gatsby-theme-doctocat 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/gatsby-node.js +37 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @primer/gatsby-theme-doctocat
|
|
2
2
|
|
|
3
|
+
## 3.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`3767651`](https://github.com/primer/doctocat/commit/37676515f1d7485ca7b5e932e115d96e3ef0285b) [#318](https://github.com/primer/doctocat/pull/318) Thanks [@colebemis](https://github.com/colebemis)! - Add a step to build process that will output a static `components.json` file with component status info if the site that its building has markdown files containing `componentId` frontmatter.
|
|
8
|
+
|
|
3
9
|
## 3.0.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/gatsby-node.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
|
+
const fs = require('fs')
|
|
2
3
|
const readPkgUp = require('read-pkg-up')
|
|
3
4
|
const getPkgRepo = require('get-pkg-repo')
|
|
4
5
|
const axios = require('axios')
|
|
@@ -12,7 +13,7 @@ exports.createPages = async ({graphql, actions}, themeOptions) => {
|
|
|
12
13
|
const repo = getPkgRepo(readPkgUp.sync().package)
|
|
13
14
|
|
|
14
15
|
const {data} = await graphql(`
|
|
15
|
-
{
|
|
16
|
+
query {
|
|
16
17
|
allMdx {
|
|
17
18
|
nodes {
|
|
18
19
|
fileAbsolutePath
|
|
@@ -34,7 +35,7 @@ exports.createPages = async ({graphql, actions}, themeOptions) => {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
// Turn every MDX file into a page.
|
|
37
|
-
|
|
38
|
+
await Promise.all(
|
|
38
39
|
data.allMdx.nodes.map(async node => {
|
|
39
40
|
const pagePath = path
|
|
40
41
|
.join(node.parent.relativeDirectory, node.parent.name === 'index' ? '/' : node.parent.name)
|
|
@@ -74,6 +75,40 @@ exports.createPages = async ({graphql, actions}, themeOptions) => {
|
|
|
74
75
|
)
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
exports.onPostBuild = async ({graphql}) => {
|
|
79
|
+
try {
|
|
80
|
+
const {data} = await graphql(`
|
|
81
|
+
query {
|
|
82
|
+
allSitePage(filter: {context: {frontmatter: {componentId: {ne: null}}}}) {
|
|
83
|
+
nodes {
|
|
84
|
+
path
|
|
85
|
+
context {
|
|
86
|
+
frontmatter {
|
|
87
|
+
componentId
|
|
88
|
+
status
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
`)
|
|
95
|
+
|
|
96
|
+
const components = data.allSitePage.nodes.map(node => {
|
|
97
|
+
return {
|
|
98
|
+
id: node.context.frontmatter.componentId,
|
|
99
|
+
path: node.path,
|
|
100
|
+
status: node.context.frontmatter.status.toLowerCase()
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
fs.writeFileSync(path.resolve(process.cwd(), 'public/components.json'), JSON.stringify(components))
|
|
105
|
+
} catch (error) {
|
|
106
|
+
// This is not necessarily an error, so we just log a warning instead of failing the build.
|
|
107
|
+
// Some sites won't have any markdown files with `componentId` frontmatter and that's okay.
|
|
108
|
+
console.warn('Unable to build components.json')
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
77
112
|
function getEditUrl(repo, filePath, defaultBranch) {
|
|
78
113
|
return `https://github.com/${repo.user}/${repo.project}/edit/${defaultBranch}/${filePath}`
|
|
79
114
|
}
|