|
| 1 | +# gatsby-gitbook-starter |
| 2 | + |
| 3 | +Kick off your project with this starter to create a powerful/flexible docs/tutorial web apps. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Motivation |
| 8 | + |
| 9 | +We wanted to create a [GraphQL tutorial](https://learn.hasura.io) series. The content would be written by developers for various languages/frameworks and what better than writing it in Markdown! And since this is a tutorial series we also needed rich embeds, syntax highlighting and more customisations. |
| 10 | + |
| 11 | +We also wanted to serve these tutorials in sub paths of [learn.hasura.io](https://learn.hasura.io). To serve all these requirements, we decided to use Gatsby + MDX (Markdown + JSX) to extend markdown and used a neat consistent theme like the one at [GitBook](https://www.gitbook.com) and deployed as docker containers. |
| 12 | + |
| 13 | +## 🔥 Features |
| 14 | +- Write using Markdown / [MDX](https://github.com/mdx-js/mdx) |
| 15 | +- GitBook style theme |
| 16 | +- Syntax Highlighting using Prism [`Bonus`: Code diff highlighting] |
| 17 | +- Search Integration with Algolia |
| 18 | +- Progressive Web App, Works Offline |
| 19 | +- Google Analytics Integration |
| 20 | +- Automatically generated sidebar navigation, table of contents, previous/next |
| 21 | +- Dark Mode toggle |
| 22 | +- Edit on Github |
| 23 | +- Fully customisable |
| 24 | +- Rich embeds and live code editor using MDX |
| 25 | +- Easy deployment: Deploy on Netlify / Now.sh / Docker |
| 26 | + |
| 27 | +## 🔗 Live Demo |
| 28 | + |
| 29 | +Here's a [live demo](https://learn.hasura.io/graphql/react) |
| 30 | + |
| 31 | +## 🚀 Quickstart |
| 32 | + |
| 33 | +Get started by running the following commands: |
| 34 | + |
| 35 | +``` |
| 36 | +$ git clone [email protected]:hasura/gatsby-gitbook-starter.git |
| 37 | +$ cd gatsby-gitbook-starter |
| 38 | +$ npm install |
| 39 | +$ npm start |
| 40 | +``` |
| 41 | + |
| 42 | +Visit `http://localhost:8000/` to view the app. |
| 43 | + |
| 44 | +## 🔧 Configure |
| 45 | + |
| 46 | +Write markdown files in `content` folder. |
| 47 | + |
| 48 | +Open `config.js` for templating variables. Broadly configuration is available for `gatsby`, `header`, `sidebar` and `siteMetadata`. |
| 49 | + |
| 50 | +- `gatsby` config for global configuration like |
| 51 | + - `pathPrefix` - Gatsby Path Prefix |
| 52 | + - `siteUrl` - Gatsby Site URL |
| 53 | + - `gaTrackingId` - Google Analytics Tracking ID |
| 54 | + |
| 55 | +- `header` config for site header configuration like |
| 56 | + - `title` - The title that appears on the top left |
| 57 | + - `githubUrl` - The Github URL for the docs website |
| 58 | + - `helpUrl` - Help URL for pointing to resources |
| 59 | + - `tweetText` - Tweet text |
| 60 | + - `links` - Links on the top right |
| 61 | + - `search` - Enable search and [configure Algolia](https://www.gatsbyjs.org/docs/adding-search-with-algolia/) |
| 62 | + |
| 63 | +- `sidebar` config for navigation links configuration |
| 64 | + - `forcedNavOrder` for left sidebar navigation order. It should be in the format "/<filename>" |
| 65 | + - `frontLine` - whether to show a front line at the beginning of a nested menu.(Collapsing capability would be turned of if this option is set to true) |
| 66 | + - `links` - Links on the bottom left of the sidebar |
| 67 | + - `ignoreIndex` - Set this to true if the index.md file shouldn't appear on the left sidebar navigation. Typically this can be used for landing pages. |
| 68 | + |
| 69 | +- `siteMetadata` config for website related configuration |
| 70 | + - `title` - Title of the website |
| 71 | + - `description` - Description of the website |
| 72 | + - `ogImage` - Social Media share og:image tag |
| 73 | + - `docsLocation` - The Github URL for Edit on Github |
| 74 | + |
| 75 | +- For sub nesting in left sidebar, create a folder with the same name as the top level `.md` filename and the sub navigation is auto-generated. The sub navigation is alphabetically ordered. |
| 76 | + |
| 77 | +### Algolia Configuration |
| 78 | + |
| 79 | +To setup Algolia, go to `config.js` and update the `search` object to look like the one below: |
| 80 | + |
| 81 | +```..., |
| 82 | + "search": { |
| 83 | + "enabled": true, |
| 84 | + "indexName": "MY_INDEX_NAME", |
| 85 | + "algoliaAppId": process.env.GATSBY_ALGOLIA_APP_ID, |
| 86 | + "algoliaSearchKey": process.env.GATSBY_ALGOLIA_SEARCH_KEY, |
| 87 | + "algoliaAdminKey": process.env.ALGOLIA_ADMIN_KEY |
| 88 | + }, |
| 89 | +``` |
| 90 | + |
| 91 | +Values for Algolia App ID, Search Key, and Admin Key can be obtained from Algolia Dashboard with the right set of permissions. Replace `MY_INDEX_NAME` with the Algolia Index name of your choice. To build the Algolia index, you need to run `npm run build` which will do a gatsby build along with content indexing in Algolia. |
| 92 | + |
| 93 | +### Progressive Web App, Offline |
| 94 | + |
| 95 | +To enable PWA, go to `config.js` and update the `pwa` object to look like the one below: |
| 96 | + |
| 97 | +``` |
| 98 | + "pwa": { |
| 99 | + "enabled": false, // disabling this will also remove the existing service worker. |
| 100 | + "manifest": { |
| 101 | + "name": "Gatsby Gitbook Starter", |
| 102 | + "short_name": "GitbookStarter", |
| 103 | + "start_url": "/", |
| 104 | + "background_color": "#6b37bf", |
| 105 | + "theme_color": "#6b37bf", |
| 106 | + "display": "standalone", |
| 107 | + "crossOrigin": "use-credentials", |
| 108 | + icons: [ |
| 109 | + { |
| 110 | + src: "src/pwa-512.png", |
| 111 | + sizes: `512x512`, |
| 112 | + type: `image/png`, |
| 113 | + }, |
| 114 | + ], |
| 115 | + }, |
| 116 | + } |
| 117 | +``` |
| 118 | + |
| 119 | +## Live Code Editor |
| 120 | + |
| 121 | +To render react components for live editing, add the `react-live=true` to the code section. For example: |
| 122 | + |
| 123 | +```javascript react-live=true |
| 124 | +<button>Edit my text</button> |
| 125 | +``` |
| 126 | + |
| 127 | +In the above code, just add `javascript react-live=true` after the triple quote ``` to start rendering react components that can be edited by users. |
| 128 | + |
| 129 | +## 🤖 SEO friendly |
| 130 | + |
| 131 | +This is a static site and comes with all the SEO benefits. Configure meta tags like title and description for each markdown file using MDX Frontmatter |
| 132 | + |
| 133 | +```markdown |
| 134 | +--- |
| 135 | +title: "Title of the page" |
| 136 | +metaTitle: "Meta Title Tag for this page" |
| 137 | +metaDescription: "Meta Description Tag for this page" |
| 138 | +--- |
| 139 | +``` |
| 140 | + |
| 141 | +Canonical URLs are generated automatically. |
| 142 | + |
| 143 | +## ☁️ Deploy |
| 144 | + |
| 145 | +[](https://app.netlify.com/start/deploy?repository=https://github.com/hasura/gatsby-gitbook-starter) |
| 146 | + |
0 commit comments