Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0] Refactor and document APIs #1053

Merged
merged 23 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b46a59b
Add basic version of new documentation.js transformer
KyleAMathews May 28, 2017
ab7ba98
Change api 'addFieldToNode' to 'createNodeField'
KyleAMathews May 29, 2017
45f7a31
Fix up node creation and add some simple tests
KyleAMathews May 30, 2017
1067771
Get basic docs page for action creators up
KyleAMathews May 30, 2017
0e39282
change deletePageByPath to just deletePage also sort action creators …
KyleAMathews May 30, 2017
d27833d
Change 'upsertPage' to 'createPage' and document it
KyleAMathews May 30, 2017
8a7575d
Only hide parent object description if its a desctructured object + i…
KyleAMathews May 30, 2017
61b79ff
Update action type
KyleAMathews May 30, 2017
776f77d
Support third level of parameters
KyleAMathews May 30, 2017
8863d25
Document createNode
KyleAMathews May 30, 2017
3697716
change 'addNodeToParent' to 'createParentChildLink' and document
KyleAMathews May 30, 2017
9e1c25a
Change 'addPageDependency' to 'createPageDependency' and document
KyleAMathews May 30, 2017
a8108ab
rename internal APIs
KyleAMathews May 30, 2017
5b0528b
Add links from function names at top to reference
KyleAMathews May 30, 2017
cba9b46
Ignore yarn.lock
KyleAMathews May 30, 2017
3ad7e09
Don't change the changelog...
KyleAMathews May 30, 2017
3c77aa3
Document and slightly modify node APIs
KyleAMathews May 31, 2017
6acd904
Factor out a FunctionsList component for rendering function docs
KyleAMathews May 31, 2017
6d536b3
Add browser/ssr docs and make a few tweaks to APIs
KyleAMathews May 31, 2017
62461fe
Add API specification document
KyleAMathews May 31, 2017
b5d634c
Actually add docs for node/browser/ssr
KyleAMathews May 31, 2017
e6600ab
Tweaks
KyleAMathews May 31, 2017
385bc78
Add README for gatsby-transformer-documentationjs
KyleAMathews May 31, 2017
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add browser/ssr docs and make a few tweaks to APIs
  • Loading branch information
KyleAMathews committed May 31, 2017
commit 6d536b3c77c8e3a6b8a8e5042121a93fdbff0260
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-google-analytics/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react"

exports.modifyPostBodyComponents = (args, pluginOptions) => {
exports.createPostBodyComponents = (args, pluginOptions) => {
if (process.env.NODE_ENV === `production`) {
return [
<script
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-manifest/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react"

exports.modifyHeadComponents = (args, pluginOptions) => [
exports.createHeadComponents = (args, pluginOptions) => [
<link rel="manifest" href="/manifest.json" />,
<meta name="theme-color" content={pluginOptions.theme_color} />,
]
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-offline/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react"

exports.modifyPostBodyComponents = () => {
exports.createPostBodyComponents = () => {
if (process.env.NODE_ENV === `production`) {
return [
<script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const scrollToHash = offsetY => {
}, 10)
}

exports.clientEntry = (args, pluginOptions) => {
exports.onClientEntry = (args, pluginOptions) => {
let offsetY = 0
if (pluginOptions.offsetY) {
offsetY = pluginOptions.offsetY
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-remark-autolink-headers/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react"

exports.modifyHeadComponents = (args, pluginOptions) => {
exports.createHeadComponents = (args, pluginOptions) => {
let offsetY = 0
if (pluginOptions.offsetY) {
offsetY = pluginOptions.offsetY
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/cache-dir/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const apiRunner = require(`./api-runner-browser`)
// Let the site/plugins run code very early.
apiRunner(`clientEntry`)
apiRunner(`onClientEntry`)

import React from "react"
import ReactDOM from "react-dom"
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/cache-dir/production-app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import apiRunner from "./api-runner-browser"
// Let the site/plugins run code very early.
apiRunner(`clientEntry`)
apiRunner(`onClientEntry`)

import React from "react"
import ReactDOM from "react-dom"
Expand Down Expand Up @@ -114,7 +114,7 @@ window.___navigateTo = navigateTo

const history = createHistory()
history.listen((location, action) => {
apiRunner(`onRouteUpdate`, location, action)
apiRunner(`onRouteUpdate`, { location, action })
})

function shouldUpdateScroll(prevRouterProps, { location: { pathname } }) {
Expand Down
11 changes: 2 additions & 9 deletions packages/gatsby/src/cache-dir/static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,26 +139,19 @@ module.exports = (locals, callback) => {

// Call plugins to let them add to or modify components/props.
const pluginHeadComponents = apiRunner(
`modifyHeadComponents`,
`createHeadComponents`,
{ headComponents },
[]
)
headComponents = headComponents.concat(pluginHeadComponents)

const pluginPostBodyComponents = apiRunner(
`modifyPostBodyComponents`,
`createPostBodyComponents`,
{ postBodyComponents },
[]
)
postBodyComponents = postBodyComponents.concat(pluginPostBodyComponents)

const pluginBodyRenderProps = apiRunner(
`modifyBodyRenderProps`,
{ bodyRenderProps },
{}
)
bodyRenderProps = merge(bodyRenderProps, pluginBodyRenderProps)

const html = `<!DOCTYPE html>\n ${renderToStaticMarkup(<Html {...bodyRenderProps} headComponents={headComponents} postBodyComponents={postBodyComponents} body={body} path={locals.path} />)}`
callback(null, html)
}
4 changes: 2 additions & 2 deletions packages/gatsby/src/utils/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ async function startServer(program) {
const htmlElement = React.createElement(HTML, {
body: ``,
headComponents: _.flattenDeep(
apiRunner(`modifyHeadComponents`, { headComponents: [] }, [])
apiRunner(`createHeadComponents`, { headComponents: [] }, [])
),
postBodyComponents: _.flattenDeep(
apiRunner(
`modifyPostBodyComponents`,
`createPostBodyComponents`,
{ headComponents: [] },
[]
)
Expand Down
41 changes: 41 additions & 0 deletions www/src/pages/docs/browser-apis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react"

import Functions from "../../components/function-list"
import { rhythm, scale } from "../../utils/typography"

class BrowserAPIDocs extends React.Component {
render() {
return (
<div>
<h1>Gatsby Browser APIs</h1>
<h2 css={{ marginBottom: rhythm(1 / 2) }}>APIs</h2>
<ul css={{ ...scale(-1 / 5) }}>
{this.props.data.allDocumentationJs.edges.map(({ node }, i) => (
<li key={`function list ${node.name}`}>
<a href={`#${node.name}`}>{node.name}</a>
</li>
))}
</ul>
<br />
<hr />
<h2>Reference</h2>
<Functions functions={this.props.data.allDocumentationJs.edges} />
</div>
)
}
}

export default BrowserAPIDocs

export const pageQuery = graphql`
query BrowserAPIDocsQuery {
allDocumentationJs(id: {regex: "/src.*api-browser-docs.js/"}, sortBy: {fields: [name]}) {
edges {
node {
name
...FunctionList
}
}
}
}
`
5 changes: 4 additions & 1 deletion www/src/pages/docs/doc-links.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
- title: Reference
links:
Node Interface: /docs/node-interface/
Gatsby Node APIs: /docs/node-apis/
API Specificatoin: /docs/api-specification/
Bound Action Creators: /docs/bound-action-creators/
Gatsby Browser APIs: /docs/browser-apis/
Gatsby Node APIs: /docs/node-apis/
Gatsby SSR APIs: /docs/ssr-apis/
- title: Contributing
links:
How to Contribute: /docs/how-to-contribute/
Expand Down
15 changes: 5 additions & 10 deletions www/src/pages/docs/node-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@ import React from "react"
import Functions from "../../components/function-list"
import { rhythm, scale } from "../../utils/typography"

class ActionCreatorsDocs extends React.Component {
class NodeAPIDocs extends React.Component {
render() {
console.log(this.props)
return (
<div>
<h1>Gatsby Node APIs</h1>
<p>
Gatsby uses
{` `}
<a href="http://redux.js.org">Redux</a>
{` `}
internally to manage state. When you implement a Gatsby API, you're
passed a collection of "Bound Action Creators" (functions which create and dispatch Redux actions when called)
which you can use to manipulate state on your site.
Gatsby gives plugins and site builders many APIs
for controlling your site.
</p>
<h2 css={{ marginBottom: rhythm(1 / 2) }}>APIs</h2>
<ul css={{ ...scale(-1 / 5) }}>
Expand All @@ -26,6 +20,7 @@ class ActionCreatorsDocs extends React.Component {
</li>
))}
</ul>
<br />
<hr />
<h2>Reference</h2>
<Functions functions={this.props.data.allDocumentationJs.edges} />
Expand All @@ -34,7 +29,7 @@ class ActionCreatorsDocs extends React.Component {
}
}

export default ActionCreatorsDocs
export default NodeAPIDocs

export const pageQuery = graphql`
query APINodeDocsQuery {
Expand Down
41 changes: 41 additions & 0 deletions www/src/pages/docs/ssr-apis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react"

import Functions from "../../components/function-list"
import { rhythm, scale } from "../../utils/typography"

class SSRAPIs extends React.Component {
render() {
return (
<div>
<h1>Gatsby Server Rendering APIs</h1>
<h2 css={{ marginBottom: rhythm(1 / 2) }}>APIs</h2>
<ul css={{ ...scale(-1 / 5) }}>
{this.props.data.allDocumentationJs.edges.map(({ node }, i) => (
<li key={`function list ${node.name}`}>
<a href={`#${node.name}`}>{node.name}</a>
</li>
))}
</ul>
<br />
<hr />
<h2>Reference</h2>
<Functions functions={this.props.data.allDocumentationJs.edges} />
</div>
)
}
}

export default SSRAPIs

export const pageQuery = graphql`
query SSRAPIsQuery {
allDocumentationJs(id: {regex: "/src.*api-ssr-docs.js/"}, sortBy: {fields: [name]}) {
edges {
node {
name
...FunctionList
}
}
}
}
`