diff --git a/www/gatsby-node.js b/www/gatsby-node.js
index 15659d31bbf1e..76583db356405 100644
--- a/www/gatsby-node.js
+++ b/www/gatsby-node.js
@@ -6,6 +6,13 @@ const fs = require(`fs-extra`)
const slash = require(`slash`)
const slugify = require(`limax`)
+// convert a string like `/some/long/path/name-of-docs/` to `name-of-docs`
+const slugToAnchor = slug =>
+ slug
+ .split(`/`) // split on dir separators
+ .filter(item => item !== ``) // remove empty values
+ .pop() // take last item
+
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators
return new Promise((resolve, reject) => {
@@ -170,6 +177,7 @@ exports.onCreateNode = ({ node, boundActionCreators, getNode }) => {
createNodeField({ node, name: `package`, value: true })
}
if (slug) {
+ createNodeField({ node, name: `anchor`, value: slugToAnchor(slug) })
createNodeField({ node, name: `slug`, value: slug })
}
} else if (node.internal.type === `AuthorYaml`) {
diff --git a/www/src/pages/docs/bound-action-creators.js b/www/src/pages/docs/bound-action-creators.js
index ecf2df34d2aa4..b54ecda08661c 100644
--- a/www/src/pages/docs/bound-action-creators.js
+++ b/www/src/pages/docs/bound-action-creators.js
@@ -12,7 +12,9 @@ class ActionCreatorsDocs extends React.Component {
Gatsby uses
{` `}
diff --git a/www/src/pages/docs/browser-apis.js b/www/src/pages/docs/browser-apis.js
index 47d37c5bcea16..36471bc18b716 100644
--- a/www/src/pages/docs/browser-apis.js
+++ b/www/src/pages/docs/browser-apis.js
@@ -12,7 +12,9 @@ class BrowserAPIDocs extends React.Component {
Implement any of these APIs by exporting them from a file named{` `}
diff --git a/www/src/pages/docs/index.js b/www/src/pages/docs/index.js
index 3a982b807613a..e7b6fe2597289 100644
--- a/www/src/pages/docs/index.js
+++ b/www/src/pages/docs/index.js
@@ -14,13 +14,15 @@ class IndexRoute extends React.Component {
Gatsby is a blazing-fast static site generator for React.
npm install --global gatsby-cli
Running gatsby new
installs the default Gatsby starter.
There are{` `}
@@ -58,7 +60,7 @@ class IndexRoute extends React.Component {
{` `}
you can use to kickstart building your Gatsby site.
It walks you through building a Gatsby site from scratch to a finished
polished site.
diff --git a/www/src/pages/docs/node-apis.js b/www/src/pages/docs/node-apis.js
index 098b50c0e6ce1..63ff89032d70f 100644
--- a/www/src/pages/docs/node-apis.js
+++ b/www/src/pages/docs/node-apis.js
@@ -12,7 +12,9 @@ class NodeAPIDocs extends React.Component {
Gatsby gives plugins and site builders many APIs for controlling your
site.
diff --git a/www/src/pages/docs/ssr-apis.js b/www/src/pages/docs/ssr-apis.js
index 9e855e5050570..62df2e91f771a 100644
--- a/www/src/pages/docs/ssr-apis.js
+++ b/www/src/pages/docs/ssr-apis.js
@@ -12,7 +12,9 @@ class SSRAPIs extends React.Component {
Implement any of these APIs by exporting them from a file named{` `} diff --git a/www/src/templates/template-docs-markdown.js b/www/src/templates/template-docs-markdown.js index 755619c3cb8c4..8117b49bb194b 100644 --- a/www/src/templates/template-docs-markdown.js +++ b/www/src/templates/template-docs-markdown.js @@ -20,7 +20,9 @@ class DocsTemplate extends React.Component { -