Skip to content

Commit 875f521

Browse files
committed
Gatsby Migration
1 parent 1a399ab commit 875f521

File tree

274 files changed

+16068
-7213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

274 files changed

+16068
-7213
lines changed

.gitignore

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,70 @@
1-
*.swp
2-
*~
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
old
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
*.pid.lock
14+
15+
# Directory for instrumented libs generated by jscoverage/JSCover
16+
lib-cov
17+
18+
# Coverage directory used by tools like istanbul
19+
coverage
20+
21+
# nyc test coverage
22+
.nyc_output
23+
24+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
25+
.grunt
26+
27+
# Bower dependency directory (https://bower.io/)
28+
bower_components
29+
30+
# node-waf configuration
31+
.lock-wscript
32+
33+
# Compiled binary addons (http://nodejs.org/api/addons.html)
34+
build/Release
35+
36+
# Dependency directories
37+
node_modules/
38+
jspm_packages/
39+
40+
# Typescript v1 declaration files
41+
typings/
42+
43+
# Optional npm cache directory
44+
.npm
45+
46+
# Optional eslint cache
47+
.eslintcache
48+
49+
# Optional REPL history
50+
.node_repl_history
51+
52+
# Output of 'npm pack'
53+
*.tgz
54+
55+
# dotenv environment variable files
56+
.env*
57+
58+
# gatsby files
59+
.cache/
60+
public
61+
62+
# Mac files
363
.DS_Store
4-
.nvmrc
5-
node_modules
6-
npm-debug.log
764

8-
/build/
9-
.tmp.*
10-
package-lock.json
65+
# Yarn
66+
yarn-error.log
67+
.pnp/
68+
.pnp.js
69+
# Yarn Integrity file
70+
.yarn-integrity

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.cache
2+
package.json
3+
package-lock.json
4+
public

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"arrowParens": "avoid",
3+
"semi": false
4+
}

.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

LICENSE

Lines changed: 0 additions & 26 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

gatsby-browser.js

Whitespace-only changes.

gatsby-config.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module.exports = {
2+
siteMetadata: {
3+
title: "A query language for your API",
4+
description:
5+
"GraphQL provides a complete description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.",
6+
siteUrl: "http://graphql.org/",
7+
},
8+
9+
plugins: [
10+
{
11+
resolve: "gatsby-source-filesystem",
12+
options: {
13+
name: "content",
14+
path: `${__dirname}/src/content`,
15+
include: ["**/*.md"], // ignore files starting with a dot
16+
},
17+
},
18+
{
19+
resolve: "gatsby-source-filesystem",
20+
options: {
21+
name: "pagecontent",
22+
path: `${__dirname}/src/pagecontent`,
23+
include: ["**/*.md"], // ignore files starting with a dot
24+
},
25+
},
26+
`gatsby-transformer-remark`,
27+
{
28+
resolve: `gatsby-plugin-webfonts`,
29+
options: {
30+
fonts: {
31+
google: [
32+
{
33+
family: `Rubik`,
34+
variants: [`300`],
35+
},
36+
{
37+
family: `Roboto Mono`,
38+
variants: [`400`, `400i`, `600`],
39+
},
40+
{
41+
family: `Roboto`,
42+
variants: [`300`],
43+
},
44+
],
45+
},
46+
},
47+
},
48+
`gatsby-plugin-less`,
49+
`gatsby-plugin-react-helmet`,
50+
{
51+
resolve: `gatsby-plugin-google-analytics`,
52+
options: {
53+
trackingId: "UA-44373548-16",
54+
},
55+
},
56+
],
57+
}

gatsby-node.js

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
const path = require("path")
2+
3+
exports.onCreatePage = async ({ page, actions }) => {
4+
const { createPage, deletePage } = actions
5+
deletePage(page)
6+
createPage({
7+
...page,
8+
context: {
9+
...page.context,
10+
sourcePath: path.relative(__dirname, page.componentPath),
11+
},
12+
})
13+
}
14+
15+
exports.createPages = async ({ graphql, actions }) => {
16+
const { createPage } = actions
17+
18+
const result = await graphql(/* GraphQL */ `
19+
query {
20+
allMarkdownRemark {
21+
edges {
22+
node {
23+
fileAbsolutePath
24+
parent {
25+
... on File {
26+
relativeDirectory
27+
sourceInstanceName
28+
}
29+
}
30+
frontmatter {
31+
title
32+
permalink
33+
next
34+
category
35+
sublinks
36+
sidebarTitle
37+
}
38+
id
39+
}
40+
}
41+
}
42+
}
43+
`)
44+
45+
const docTemplate = path.resolve("./src/templates/doc.tsx")
46+
47+
if (result.errors) {
48+
// eslint-disable-next-line no-console
49+
console.error(result.errors)
50+
throw result.errors
51+
}
52+
53+
const { edges } = result.data.allMarkdownRemark
54+
55+
let sideBardata = {}
56+
let pagesGroupedByFolder = {}
57+
const allPages = []
58+
59+
await Promise.all(edges.map(async ({ node }) => {
60+
const {
61+
frontmatter: { permalink, next, sidebarTitle },
62+
parent: { relativeDirectory, sourceInstanceName },
63+
} = node
64+
65+
if (sourceInstanceName !== "content") {
66+
return
67+
}
68+
69+
if (!pagesGroupedByFolder[relativeDirectory]) {
70+
pagesGroupedByFolder = {
71+
...pagesGroupedByFolder,
72+
[relativeDirectory]: [node],
73+
}
74+
} else {
75+
pagesGroupedByFolder = {
76+
...pagesGroupedByFolder,
77+
[relativeDirectory]: [...pagesGroupedByFolder[relativeDirectory], node],
78+
}
79+
}
80+
allPages.push({
81+
permalink,
82+
relativeDirectory,
83+
sidebarTitle,
84+
nextPermalink: next,
85+
sourcePath: path.relative(__dirname, node.fileAbsolutePath),
86+
})
87+
}));
88+
89+
await Promise.all(Object.entries(pagesGroupedByFolder).map(async ([folder, pages]) => {
90+
let pagesByUrl = {}
91+
let previousPagesMap = {}
92+
93+
await Promise.all(pages.map(async (page) => {
94+
const {
95+
frontmatter: { permalink, next },
96+
} = page
97+
if (next) {
98+
previousPagesMap[next] = permalink
99+
}
100+
pagesByUrl[permalink] = page
101+
}))
102+
103+
let firstPage = null
104+
105+
await Promise.all(pages.map(async (page) => {
106+
const {
107+
frontmatter: { permalink },
108+
} = page
109+
110+
if (!previousPagesMap[permalink]) {
111+
firstPage = page
112+
return
113+
}
114+
}))
115+
116+
if (!firstPage) {
117+
throw new Error(`First page not found in ${folder}`)
118+
}
119+
120+
let categories = []
121+
let currentCategory = null
122+
123+
let page = firstPage
124+
let i = 0
125+
while (page && i++ < 1000) {
126+
const {
127+
frontmatter: { category, next },
128+
} = page
129+
if (!currentCategory || category !== currentCategory.name) {
130+
currentCategory && categories.push(currentCategory)
131+
currentCategory = {
132+
name: category,
133+
links: [],
134+
}
135+
}
136+
currentCategory.links.push(page)
137+
page = pagesByUrl[next]
138+
}
139+
140+
categories.push(currentCategory)
141+
142+
sideBardata[folder] = categories
143+
}))
144+
145+
await Promise.all(allPages.map(async page => {
146+
createPage({
147+
path: `${page.permalink}`,
148+
component: docTemplate,
149+
context: {
150+
permalink: page.permalink,
151+
nextPermalink: page.nextPermalink,
152+
sideBarData: sideBardata[page.relativeDirectory],
153+
sourcePath: page.sourcePath,
154+
},
155+
})
156+
}))
157+
}

0 commit comments

Comments
 (0)