This is our documentation site generator, built with GatsbyJS and a heavily modified fork of gatsby-starter-docs.
Check out the repository and from the root of the project:
npm install
- Edit
repos.json
to list markdown sources - Edit
gulp/copy.js
to copy the desired folders from your remote repo to the/content/public
folder npm run setup
npm run dev
- Node v10.1.0
- NPM v6.0.1
- Ngrok (for deployment steps)
There is a known issue with Node 10 and gulp gulpjs/gulp#2162
Resolution:
rm -rf node_modules/
rm -rf package-lock.json
sudo npm install --unsafe-perm=true
Run this command if you need to reset your workspace or have just cloned the repository for the first time.
Running this command will do the following:
- Installs custom plugins contained in the
/plugins
folder. - Cleans the
/repos
folder. - Fetches markdown from remotes configured in
repos.json
. - Cleans the
/public
folder. - Copies cloned content from
/repos
to/content/public
Periodically it will be necessary to apply updates to the documentation markdown contained within the /repos
folder. When a local development instance of the site is running, this changes can be applied by running this command to copy the files from /repos
to /content/public
.
This command watches the /repos
folder for updates. Any time an update happens it will run copy:markdown
. This enables live updates of markdown in development mode when compbined with npm run dev
.
To pull in documentation updates from the remote repositories, run this command. It does the following:
- Fetches markdown from remotes configured in
repos.json
. - Copies cloned content from
/repos
to/content/public
Run this command to build and run a local instance of the developer docs at http://localhost:8000
. GraphQL queries can be inspected at http://localhost:8000/___graphql
. npm run update:docs:local
and update:docs:remote
can both be run while the site is running locally to apply apply updates from local or remote markdown sources.
There are a few main points of configuration.
- Site
/data/SiteConfig.js
- Styling
/src/layouts/theme.js
- Content
/repos.json
- GatsbyJS configuration
gatsby-config.js
The SiteConfig.js
file contains properties that are used by the site generator at compile time. It contains configuration options like setting a path-prefix, the site name, logo images, etc.
At a minimum the siteUrl
and pathPrefix
should be set.
Example SiteConfig and each properties explanation:
module.exports = {
siteTitle: "Simple and secure login for your Ethereum app", // Site title.
siteTitleAlt: "Uport ID makes blockchain easy on desktop and mobile", // Alternative site title for SEO.
siteLogo: "/logos/[email protected]", // Logo used for SEO and manifest.
siteUrl: "https://rekt.uport.space", // Domain of your website without pathPrefix.
pathPrefix: "/", // Prefixes all links. For cases when deployed to example.github.io/gatsby-advanced-starter/.
siteDescription: "Uport ID makes blockchain easy on desktop and mobile", // Website description used for RSS feeds/meta description tag.
siteRss: "/rss.xml", // Path to the RSS file.
googleAnalyticsID: "UA-8xxxxx", // GA tracking ID.
userName: "uPort", // Username to display in the author segment.
userTwitter: "uport_me", // Optionally renders "Follow Me" in the UserInfo segment.
userLocation: "Universe", // User location to display in the author segment.
userAvatar: "https://pbs.twimg.com/profile_images/932688008314109952/3_QkvZeQ_400x400.jpg", // User avatar to display in the author segment.
userDescription: "Your ID. For you.", // User description to display in the author segment.
segmentProdKey: "", //Segment key for prod
segmentDevKey: "", //Segment key for dev
copyright: "Copyright © 2018", // Copyright string for the footer of the website and RSS feed.
themeColor: "#5c50ca", // Used for setting manifest and progress theme colors.
backgroundColor: "#e0e0e0", // Used for setting manifest background color.
};
The theme.js
file contains a couple attributes that are used to toggle CSS properties. For convenience the theme styles are included, but others can be added as needed.
const theme = {
// named colors:
brand: '#5c50ca',
accent: '#ADD2EB',
accentDark: "#35495E",
lightGrey: '#F6F6F6',
darkGrey: '#91a2a3',
ink: 'black',
errorRed: '#FF6666',
codeEditBlue: '#2973b7',
codeEditGreen: '#42b983',
themedWhite: '#f5f2f0',
// content width:
contentWidthLaptop: '850px',
sitePadding: "25px",
}
export default theme;
Note:
- Code highlighting is done with PrismJS. Prism Themes have been installed, and is utilized in
/src/layouts/index.jsx
- Our CSS is imported from weblow.
- The only CSS file that should be modified directly is
src/layours/css/index.css
. Use this to make changes to the defaults that are imported.
Our content is stored in remote repositories which are configured in a file called repos.json
. In this file any repository that is configured will be cloned into the /repos
folder. For convenience this folder has been added to .gitingore
.
Each repository listed can optionally pull from a specific branch. Use this property to test out the documentation changes before they are merged to develop/master.
Example repos.json:
{
"docs" : {
"githubURL": "https://github.com/uport-project/docs.git",
"branch": "move-docs-to-reference"
},
"specs" : {
"githubURL": "https://github.com/uport-project/specs.git",
"projectTitle": "uPort Specs",
"branch": "update-specs-for-docs-site"
}
}
The gatsby-config.js
file bootstraps all the plugins that are utilized by GatsbyJS to build the site. Most of the options here are configured through SiteConfig.js
and utilized within `gatsby-config.js`` at runtime.
There is a /plugins
folder that contains custom code. At this time the following custom plugins are:
gatsby-remark-copy-linked-files
gatsby-remark-catch-relative-markdown-links
This is a plugin provided by GatsbyJS. It's purpose is to iterate over all markdown documents and copy any files/images that are linked to the /public
folder. It then re-writes the links within the markdown to point to the new file location. We have extended it to ignore relative links to markdown files otherwise the relative links would be broken.
It is configured within gatsby-config.js
and now accepts a new option ignoreRelativeMarkdownLinks
{
resolve: "gatsby-remark-copy-linked-files",
options: {
ignoreRelativeMarkdownLinks: true
}
},
This is a custom plugin that is used to re-write the relative links to markdown documents. It detects if a link is a relative link and is a markdown document then updates the link to point to the new location within the /public
folder.
There are a few things to take note of, or would be good to know while working with this repository.
This is the brain of the site. It contains two functions, createPages
and onCreateNode
.
The former uses the output of onCreateNode
to physically create the pages.
The later is used to apply updates to the page frontmatter that are used by GraphQL queries to build the site. In this instance it sets the slug for each page. Slugs are eventually used to create the static content at the location that the slug specifies during createPages
.
This contains configuration for several plugins used by gatsby. Without this configuration gatsby-node.js
will be unable to find the files and operate on them.
We deploy the github pages from the master
branch. That meands we work off the develop
branch and tag releases.
ngrok is required
- Because we are using GitHub pages Ngrok Should be used to serve a production version of the site for feedback.
- Deployment is made easy with the provided command
npm run build:gh
. This will read configuration details about path prefix, and site urls to statically compile links for production. - For our purposes it is also necessary to update the DNS name within the repositories settings after each publish to the
gh-pages
branch: https://github.com/uport-project/docs-site/settings.
Always run the build:gh
from a release tag. Never from the develop branch
- Check out the latest release tag.
- Clean the project and pull content:
npm run setup
- Build a production version of the site:
npm run build
- Serve the production built site on a public DNS (ngrok) for feedback
npm run serve
- After validating the build with ngrok, build and deploy:
npm run build:gh
- Go to https://github.com/uport-project/docs-site/settings and update the custom domain to reflect our documentation home (developer.uport.me).
Manual deployment can be done. Simply build the site and copy the output to its destination.
- To build the site execute
npm run build
. - Copy or push the contents of the
/public
folder to its intended destination or gh-pages branch
Depending on the deployment destination (S3, Netflify, **), this command can be modified.