Skip to content

Commit 92b5c16

Browse files
dcramerPeloWriter
andauthored
feat: New platform layout and JavaScript conversion (#2026)
Co-authored-by: Fiona Artiaga <[email protected]>
1 parent 68d1656 commit 92b5c16

File tree

96 files changed

+1226
-525
lines changed

Some content is hidden

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

96 files changed

+1226
-525
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.vscode/settings.json

+4-18
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,8 @@
55

66
"editor.wordWrap": "on",
77

8-
"files.associations": {
9-
"*.js": "javascriptreact"
10-
},
11-
12-
"liquid.format": false,
13-
14-
"[ruby]": {
15-
"editor.detectIndentation": false,
16-
"editor.tabSize": 2,
17-
"editor.formatOnSave": true
18-
},
19-
20-
"[html]": {
21-
"editor.detectIndentation": false,
22-
"editor.tabSize": 2,
23-
"editor.formatOnSave": false
24-
},
25-
"search.usePCRE2": true
8+
"typescript.tsdk": "node_modules/typescript/lib",
9+
"editor.codeActionsOnSave": {
10+
"source.fixAll.eslint": true
11+
}
2612
}

README.md

+39-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,45 @@ foo bar
9898
</markdown>
9999
```
100100

101-
## Creating new SDK docs
101+
## Platform / SDK Docs
102+
103+
The current generation platform content lives in `src/platforms` and follows some specific rules to generate content. These rules are enforced via the directory structure:
104+
105+
```
106+
[platformName]/
107+
child.mdx
108+
childTwo/
109+
index.mdx
110+
common/
111+
aSharedPage.mdx
112+
guides/
113+
[guideName]/
114+
uniqueChild.mdx
115+
childTwo/
116+
index.mdx
117+
```
118+
119+
Platforms will generate a list of "guides", and inherit all content within common. Given the above example, we end up with a variety of semi-duplicated URLs:
120+
121+
```
122+
/platforms/platformName/
123+
/platforms/platformName/child/
124+
/platforms/platformName/childTwo/
125+
/platforms/platformName/aSharedPage/
126+
/platforms/platformName/guides/guideName/
127+
/platforms/platformName/guides/guideName/child/
128+
/platforms/platformName/guides/guideName/uniqueChild/
129+
/platforms/platformName/guides/guideName/childTwo/
130+
/platforms/platformName/guides/guideName/aSharedPage/
131+
```
132+
133+
This is generated by inheriting all content with the ``command/`` directory, then adding (or overriding with) content from the siblings (or children as we'd call them). In the above example, you'll see ``aSharedPage`` is loaded at two different URLs, and ``childTwo`` is overwritten by ``guideName``.
134+
135+
The sidebar on platform pages (handled by ``<PlatformSidebar>``) will generate with the Guide, or the Base Platform being the primary section, in addition to a list of other guides available in a section below it. This means that all content is focused on the current guide (usually a framework) they're in, ensuring ease of navigation.
136+
137+
### Creating new SDK docs
138+
139+
TODO: This needs updated!
102140

103141
If you want to create new docs for SDKs you should start by choosing an SDK to copy from and change the parts necessary. Start by calling
104142

gatsby-config.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// const path = require("path");
1+
require("ts-node").register({
2+
files: true, // to that TS node hooks have access to local typings too
3+
});
4+
25
const activeEnv =
36
process.env.GATSBY_ENV || process.env.NODE_ENV || "development";
47

@@ -96,7 +99,7 @@ const getPlugins = () => {
9699
resolve: `gatsby-transformer-json`,
97100
options: {
98101
typeName: ({ node, object, isArray }) => {
99-
if (node.sourceInstanceName === "api-docs") {
102+
if (node.sourceInstanceName === "api") {
100103
return "ApiDoc";
101104
}
102105
return null;
@@ -113,7 +116,14 @@ const getPlugins = () => {
113116
{
114117
resolve: `gatsby-source-filesystem`,
115118
options: {
116-
name: `api-docs`,
119+
name: `platforms`,
120+
path: `${__dirname}/src/platforms`,
121+
},
122+
},
123+
{
124+
resolve: `gatsby-source-filesystem`,
125+
options: {
126+
name: `api`,
117127
path: `${__dirname}/src/api`,
118128
},
119129
},

gatsby-node.js

+4-244
Original file line numberDiff line numberDiff line change
@@ -1,244 +1,4 @@
1-
const path = require("path");
2-
const { createFilePath } = require("gatsby-source-filesystem");
3-
4-
exports.onCreateWebpackConfig = ({ stage, actions }) => {
5-
actions.setWebpackConfig({
6-
resolve: {
7-
alias: {
8-
"~src": path.join(path.resolve(__dirname, "src")),
9-
},
10-
},
11-
});
12-
};
13-
14-
// TODO(dcramer): move frontmatter out of ApiDoc and into Frontmatter
15-
exports.createSchemaCustomization = ({ actions, schema }) => {
16-
const { createTypes } = actions;
17-
const typeDefs = [
18-
`
19-
type MarkdownRemark implements Node {
20-
frontmatter: Frontmatter
21-
fields: Fields
22-
}
23-
24-
type Mdx implements Node {
25-
frontmatter: Frontmatter
26-
fields: Fields
27-
}
28-
29-
type Fields {
30-
slug: String!
31-
legacy: Boolean
32-
}
33-
34-
type ApiParam {
35-
type: String!
36-
name: String!
37-
description: String
38-
}
39-
40-
type ApiDoc implements Node {
41-
sidebar_order: Int
42-
title: String!
43-
fields: Fields
44-
45-
api_path: String!
46-
authentication: String
47-
description: String
48-
example_request: String
49-
example_response: String
50-
method: String!
51-
parameters: [ApiParam]
52-
path_parameters: [ApiParam]
53-
query_parameters: [ApiParam]
54-
warning: String
55-
}
56-
`,
57-
schema.buildObjectType({
58-
name: "Frontmatter",
59-
fields: {
60-
title: {
61-
type: "String!",
62-
},
63-
keywords: {
64-
type: "[String!]",
65-
},
66-
draft: {
67-
type: "Boolean",
68-
},
69-
redirect_from: {
70-
type: "[String!]",
71-
},
72-
noindex: {
73-
type: "Boolean",
74-
},
75-
sidebar_order: {
76-
type: "Int",
77-
resolve(source, args, context, info) {
78-
// For a more generic solution, you could pick the field value from
79-
// `source[info.fieldName]`
80-
return source[info.fieldName] !== null
81-
? source[info.fieldName]
82-
: 10;
83-
},
84-
},
85-
86-
// wizard fields
87-
// TODO(dcramer): move to a diff schema/type
88-
support_level: {
89-
type: "String",
90-
},
91-
type: {
92-
type: "String",
93-
},
94-
doc_link: {
95-
type: "String",
96-
},
97-
name: {
98-
type: "String",
99-
},
100-
},
101-
}),
102-
];
103-
createTypes(typeDefs);
104-
};
105-
106-
exports.onCreateNode = ({
107-
node,
108-
actions,
109-
getNode,
110-
createContentDigest,
111-
createNodeId,
112-
}) => {
113-
const { createNodeField, createNode } = actions;
114-
if (node.internal.type === "Mdx" || node.internal.type === "MarkdownRemark") {
115-
const value = createFilePath({ node, getNode });
116-
createNodeField({
117-
name: "slug",
118-
node,
119-
value,
120-
});
121-
122-
createNodeField({
123-
name: "legacy",
124-
node,
125-
value: value.indexOf("/clients/") === 0,
126-
});
127-
} else if (node.internal.type === "ApiDoc") {
128-
const value = createFilePath({ node, getNode });
129-
createNodeField({
130-
name: "slug",
131-
node,
132-
value: `/api${value}`,
133-
});
134-
createNodeField({
135-
name: "legacy",
136-
node,
137-
value: false,
138-
});
139-
140-
const markdownNode = {
141-
id: createNodeId(`${node.id} >>> MarkdownRemark`),
142-
children: [],
143-
parent: node.id,
144-
internal: {
145-
content: node.description,
146-
contentDigest: createContentDigest(node.description),
147-
mediaType: `text/markdown`,
148-
type: `ApiDocMarkdown`,
149-
},
150-
};
151-
createNode(markdownNode);
152-
153-
createNodeField({
154-
node,
155-
name: "description___NODE",
156-
value: markdownNode.id,
157-
});
158-
}
159-
};
160-
161-
exports.createPages = async function({ actions, graphql, reporter }) {
162-
const createApi = async () => {
163-
const { data, errors } = await graphql(`
164-
query {
165-
allApiDoc {
166-
nodes {
167-
id
168-
title
169-
fields {
170-
slug
171-
}
172-
}
173-
}
174-
}
175-
`);
176-
177-
if (errors) {
178-
reporter.panicOnBuild('🚨 ERROR: Loading "createApi" query');
179-
}
180-
const component = require.resolve(`./src/components/pages/api.js`);
181-
await Promise.all(
182-
data.allApiDoc.nodes.map(async node => {
183-
actions.createPage({
184-
path: node.fields.slug,
185-
component,
186-
context: {
187-
id: node.id,
188-
title: node.title,
189-
},
190-
});
191-
})
192-
);
193-
};
194-
195-
const createDocs = async () => {
196-
const { data, errors } = await graphql(`
197-
query {
198-
allFile(filter: { sourceInstanceName: { eq: "docs" } }) {
199-
nodes {
200-
id
201-
childMarkdownRemark {
202-
frontmatter {
203-
title
204-
}
205-
fields {
206-
slug
207-
}
208-
}
209-
childMdx {
210-
frontmatter {
211-
title
212-
}
213-
fields {
214-
slug
215-
}
216-
}
217-
}
218-
}
219-
}
220-
`);
221-
222-
if (errors) {
223-
reporter.panicOnBuild('🚨 ERROR: Loading "createDocs" query');
224-
}
225-
const component = require.resolve(`./src/components/pages/doc.js`);
226-
await Promise.all(
227-
data.allFile.nodes.map(async node => {
228-
const child = node.childMarkdownRemark || node.childMdx;
229-
if (child && child.fields) {
230-
actions.createPage({
231-
path: child.fields.slug,
232-
component,
233-
context: {
234-
id: node.id,
235-
title: child.frontmatter.title,
236-
},
237-
});
238-
}
239-
})
240-
);
241-
};
242-
243-
await Promise.all([createApi(), createDocs()]);
244-
};
1+
exports.onCreateNode = require("./src/gatsby/onCreateNode").default;
2+
exports.onCreateWebpackConfig = require("./src/gatsby/onCreateWebpackConfig").default;
3+
exports.createPages = require("./src/gatsby/createPages").default;
4+
exports.createSchemaCustomization = require("./src/gatsby/createSchemaCustomization").default;

0 commit comments

Comments
 (0)