Skip to content

Commit 1f39aa1

Browse files
authored
Merge pull request linode#132 from alioso/hand-off-documentation
Hand off documentation
2 parents a573108 + 838e590 commit 1f39aa1

File tree

9 files changed

+97
-48
lines changed

9 files changed

+97
-48
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ The developers.linode.com website built with Gatsby and including the API Docs
44

55
## Setup
66

7+
DLC currently needs `node v10.16.0` to build properly. You may want to use NVM to manage your versions (https://github.com/nvm-sh/nvm/blob/master/README.md)
8+
79
`yarn`
810

911
`yarn develop`

gatsby-node.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ const { recursiveQuery } = require("./generateQuery.js");
1212

1313
exports.sourceNodes = async ({ actions }) => {
1414
const { createNode, createTypes } = actions;
15+
16+
// This parser allows compiling the JSON object into a valid
17+
// OpenAPI object (parsing $refs etc)
1518
const res = await parser.dereference(specs);
1619

1720
// CREATING NODES FROM API SPECS
21+
22+
// Type definitions for GraphQL
23+
// We force define these types to avoid build errors
1824
const typeDefs = `
1925
type MarkdownRemark implements Node {
2026
frontmatter: Frontmatter!
@@ -29,15 +35,15 @@ exports.sourceNodes = async ({ actions }) => {
2935
createTypes(typeDefs);
3036

3137
const allSpecs =
32-
// map into these results and create nodes
38+
// crate endpoint smap
3339
Object.keys(res.paths).map(async (path, i) => {
3440
// Create your node object
3541
const pathNode = {
3642
// Required fields
3743
id: `${i}`,
3844
parent: `__SOURCE__`,
3945
internal: {
40-
type: `Paths` // name of the graphQL query --> allRandomUser {}
46+
type: `Paths` // name of the graphQL query --> allPaths {}
4147
},
4248
children: [],
4349

@@ -69,10 +75,9 @@ exports.sourceNodes = async ({ actions }) => {
6975
createNode(pathNode);
7076
});
7177

72-
const baseUrl =
73-
"https://linode.com/wp-json/menus/v1/menus";
74-
7578
// CREATING MENU NODES FROM WP API
79+
// This will gather the WP API from linode.com to build the header menu items
80+
const baseUrl = "https://linode.com/wp-json/menus/v1/menus";
7681
const wpMenus = [
7782
{
7883
path: `${baseUrl}/header-utility`,
@@ -170,6 +175,7 @@ exports.sourceNodes = async ({ actions }) => {
170175
return Promise.all(allMenus, allSpecs);
171176
};
172177

178+
// GENERATE CHANGELOG ENTRIES
173179
exports.createPages = async ({ actions, graphql }) => {
174180
const { createPage } = actions;
175181
const changelogTemplate = path.resolve(
@@ -207,7 +213,7 @@ exports.createPages = async ({ actions, graphql }) => {
207213
// Eliminate duplicate tags
208214
tags = _.uniq(tags);
209215

210-
// Make tag pages
216+
// Make changelog pages
211217
tags.forEach(changelog => {
212218
createPage({
213219
path: `/changelog/${_.kebabCase(changelog)}/`,
@@ -253,6 +259,7 @@ exports.createPages = async ({ actions, graphql }) => {
253259
});
254260
});
255261

262+
// CREATE FRAGMENTS
256263
const fragmentQueries = [
257264
{
258265
path: "PathsGetResponses_200ContentApplication_jsonSchemaProperties",
@@ -286,6 +293,9 @@ exports.createPages = async ({ actions, graphql }) => {
286293

287294
const fragments = [];
288295

296+
// GraphQL introspection query
297+
// Not sure if there's a better way top generate a recursive pattern here,
298+
// but this code makes sure we good deep enough into the data
289299
await fragmentQueries.map(q => {
290300
let partialFragments = graphql(`
291301
{
@@ -688,6 +698,7 @@ exports.createPages = async ({ actions, graphql }) => {
688698
.toString()
689699
.replace(/\,/g, "");
690700

701+
// Write REACT files for each fragment
691702
return (
692703
fragments.push(partialFragments),
693704
file.write(`

postcss.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class TailwindExtractor {
99
}
1010
}
1111

12+
// The css setup uses TailwindCSS as a utility library (https://tailwindcss.com/#what-is-tailwind).
13+
// We imports tailwind, then purge CSS classes that are not used
14+
// See gatsby-config.js for details
15+
1216
module.exports = {
1317
plugins: [
1418
atImport,

src/components/2_molecules/ResponseItemElements.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import Nullable from "./Nullable";
88
import SubResponse from "./SubResponse";
99
import CharDisplay from "./charDisplay";
1010

11+
/*
12+
__TODO__ needs better scripting.
13+
Ideally we should generate this in a much more dynamic way
14+
We are missing data at times, and missing deeply nested data.
15+
*/
16+
1117
export const ResponseItemElements = props => {
1218
const { context } = props;
1319
return (
@@ -23,7 +29,6 @@ export const ResponseItemElements = props => {
2329
)
2430
.map((p, i) => {
2531
const l = context.content.application_json.schema.properties[p];
26-
// console.log(l);
2732
return (
2833
l && (
2934
<div key={i} className="response-wrapper">
@@ -71,7 +76,6 @@ export const ResponseItemElements = props => {
7176
Object.keys(l.items.properties).map(
7277
(value, index) => {
7378
const data = l.items.properties[value];
74-
// console.log(data);
7579
return (
7680
data && (
7781
<div key={index} className="response-wrapper">

src/components/2_molecules/ResponseSample.js

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import React from "react";
22
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
33
import { atomDark } from "react-syntax-highlighter/dist/esm/styles/prism";
44

5+
/*
6+
__TODO__ needs better scripting.
7+
Ideally we should generate this in a much more dynamic way
8+
We are missing data at times, and missing deeply nested data.
9+
*/
10+
511
export const ResponseItem = props => {
612
const { response, r } = props;
713
return (
@@ -62,42 +68,41 @@ export const ResponseItem = props => {
6268
</div>
6369
);
6470
})}
65-
{l.items &&
66-
(l.items.properties && (
67-
<div>
68-
{" {"}
69-
{Object.keys(l.items.properties).map((e, i) => {
70-
const data = l.items.properties[e];
71-
const rowLen3 = Object.keys(l.items).length;
72-
return (
73-
data && (
74-
<div key={i} className="ml-8">
75-
<div>
76-
"{e}":{" "}
77-
<span style={{ color: "#3BB878" }}>
78-
"{data.example}"
79-
{rowLen3 === i + 1 && ","}
80-
</span>
81-
</div>
71+
{l.items && l.items.properties && (
72+
<div>
73+
{" {"}
74+
{Object.keys(l.items.properties).map((e, i) => {
75+
const data = l.items.properties[e];
76+
const rowLen3 = Object.keys(l.items).length;
77+
return (
78+
data && (
79+
<div key={i} className="ml-8">
80+
<div>
81+
"{e}":{" "}
82+
<span style={{ color: "#3BB878" }}>
83+
"{data.example}"
84+
{rowLen3 === i + 1 && ","}
85+
</span>
8286
</div>
83-
)
84-
);
85-
})}
86-
{" }"}
87-
{l.type !== "array" && (
88-
<div>
89-
{"]"}
90-
{rowLen !== i + 1 && ","}
91-
</div>
92-
)}
93-
{p !== "errors" && (
94-
<div>
95-
{"]"}
96-
{rowLen !== i + 1 && ","}
97-
</div>
98-
)}
99-
</div>
100-
))}
87+
</div>
88+
)
89+
);
90+
})}
91+
{" }"}
92+
{l.type !== "array" && (
93+
<div>
94+
{"]"}
95+
{rowLen !== i + 1 && ","}
96+
</div>
97+
)}
98+
{p !== "errors" && (
99+
<div>
100+
{"]"}
101+
{rowLen !== i + 1 && ","}
102+
</div>
103+
)}
104+
</div>
105+
)}
101106
</div>
102107
)
103108
);

src/components/2_molecules/ResponseSampleBody.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ export const ResponseSampleBody = props => {
1212
context
1313
);
1414

15+
{
16+
/*
17+
__TODO__ Sample source need better scripting.
18+
Kinda hand coded for speed, not very scalable and missing info.
19+
Ideally we should generate this in a much more dynamic way
20+
We are missing data at times, and missing deeply nested data.
21+
Additionally, allOf & oneOf need better handling
22+
*/
23+
}
24+
1525
const sampleSource = `
1626
{
1727
${properties &&
1828
Object.keys(properties)
1929
.filter(v => properties[v] !== null)
2030
.map(p => {
2131
const l = properties[p];
22-
// console.log(l);
2332
return (
2433
l &&
2534
(l.type !== "array" && p !== "errors" && l.type !== "object"
@@ -120,9 +129,9 @@ export const ResponseSampleBody = props => {
120129
.map(e => {
121130
const data = l.items.properties[e];
122131
return data &&
123-
(data.type !== "array" &&
124-
data.type !== "object" &&
125-
!data.oneOf)
132+
data.type !== "array" &&
133+
data.type !== "object" &&
134+
!data.oneOf
126135
? `
127136
"${e}": ${JSON.stringify(
128137
data.example ? data.example : ""
@@ -138,7 +147,8 @@ export const ResponseSampleBody = props => {
138147
.map(oo => {
139148
const ro = o.properties[oo];
140149
return ro &&
141-
(ro.type === "object" && ro.properties)
150+
ro.type === "object" &&
151+
ro.properties
142152
? `"${oo}": {
143153
${Object.keys(ro.properties)
144154
.filter(
@@ -214,6 +224,9 @@ export const ResponseSampleBody = props => {
214224
console.log(e);
215225
}
216226

227+
// Switch constants for testing if data does not show up for instance
228+
// `sanitized` will output unformatted data to test it
229+
217230
const finalSource = JSON.stringify(parsed, null, 2);
218231
// const finalSource = sanitized;
219232

src/components/2_molecules/ResponseSamples.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const ResponseSamples = props => {
3232
return (
3333
response !== null && (
3434
<TabPanel key={i}>
35+
{/* __TODO__ This below needs work. Logic is not sound */}
3536
{(mode === "put" || mode === "post") && response["default"] ? (
3637
<ResponseSampleBody
3738
response={options[e]}

src/components/2_molecules/allOf.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
__TODO__ May need rework
3+
1. We worked out what allOfs and oneOfs are supposed to do, but did not get a chance to get to it
4+
This component has more complexion we need to address
5+
2. We need to handle more recursion here, deep nested data may not show
6+
*/
7+
18
const accumulator = (or, ov) => {
29
return Object.keys(or).reduce((acc, currentKey) => {
310
if (!!ov[currentKey]) {

tailwind.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// We import the tailwind settings from the base theme
12
const config = require("./linode-hugo-theme/tailwind");
23

4+
// We override (merge) or add specific settings to DLC
35
config.colors["ThemeCell"] = "#f4f4f4";
46
config.colors["ThemeBeige"] = "#eCeCeC";
57
config.colors["ThemeTagGrey"] = "#e1e8eC";

0 commit comments

Comments
 (0)