This project is set up using TypeScript as a programming language in a Gatsby framework with Sanity as a content management system.
- Clone the repo to your local system.
First fork the repo to your own github account, then hit clone or download and copy the HTTPS url. Then go to your terminal and clone the repository.
$ git clone https://github.com/<your-github-account>/beneisenberg.git
- Setup Sanity
Sanity.io is a platform for structured content that comes with an open source editor that you can customize with React.js. It's a fully customizable, headless CMS that uses GraphQL as aquery language for your API.
You'll have to install Sanity globally and create an account or log in.
In the terminal run
$ npm install -g @sanity/cli && sanity login
Get your token
to connect your Gatsby app to the Sanity backend
In the terminal run
$ sanity bedug --secrets
Copy the Authentication Auth token
, api projectId
and dataset
and add them to your .env
file in the root directory of this project.
SANITY_PROJECT_ID=<api-projectid>
SANITY_DATASET=<api-dataset>
SANITY_TOKEN=<auth-token>
Navigate into the sanity directory and start it up.
$ cd beneisenberg/sanity/
$ sanity start
Now you'll find and create content using the GUI at http://localhost:3333/desk
- Setup Gatsby
Gatsby is a free and open source framework based on React that helps developers build blazing fast websites and apps
Navigate into your new site’s directory and download node_modules
.
$ cd beneisenberg/
$ yarn
Once node modules are installed, start up the app.
$ gatsby develop
Open the source code and start editing!
Your site is now running at http://localhost:8000
!
Note: You'll also see a second link: http://localhost:8000/___graphql
. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the Gatsby tutorial.
Open the beneisenberg
directory in your code editor of choice and edit src/pages/index.js
. Save your changes and the browser will update in real time!
A quick look at the top-level files and directories you'll see in a Gatsby project.
.
├── node_modules/
├── sanity/
├── src/
├── .env
├── .eslintrc.json
├── .gitignore
├── .prettierignore
├── .prettierrc
├── gatsby-browser.js
├── gatsby-config.js
├── gatsby-node.js
├── gatsby-ssr.js
├── LICENSE
├── package.json
├── README.md
├── tsconfig.json
└── yarn.lock
-
/node_modules
: This directory contains all of the modules of code that your project depends on (npm packages) are automatically installed. -
/sanity
: This directory contains all the configuration for your sanity project. -
/src
: This directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser) such as your site header or a page template.src
is a convention for “source code”. -
.env
: This file contains environment variables. This file does not get pushed to github, so you have to create it if it doesn't exist. -
.eslintc.json
: This file containseslint
configuration. -
.gitignore
: This file tells git which files it should not track / not maintain a version history for. -
.prettierignore
: This is a file for Prettier. (see below prettierrc) Tells prettier which files to ignore. -
.prettierrc
: This is a configuration file for Prettier. Prettier is a tool to help keep the formatting of your code consistent. -
gatsby-browser.js
: This file is where Gatsby expects to find any usage of the Gatsby browser APIs (if any). These allow customization/extension of default Gatsby settings affecting the browser. -
gatsby-config.js
: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins you’d like to include, etc. (Check out the config docs for more detail). -
gatsby-node.js
: This file is where Gatsby expects to find any usage of the Gatsby Node APIs (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process. -
gatsby-ssr.js
: This file is where Gatsby expects to find any usage of the Gatsby server-side rendering APIs (if any). These allow customization of default Gatsby settings affecting server-side rendering. -
LICENSE
: Gatsby is licensed under the MIT license. -
package.json
: A manifest file for Node.js projects, which includes things like metadata (the project’s name, author, etc). This manifest is how yarn knows which packages to install for your project. -
README.md
: A text file containing documentation and information about the project. -
tsconfig.json
: This is a configuration file for TypeScript. -
yarn.lock
This is an automatically generated file based on the exact versions of your yarn dependencies that were installed for your project. (You won’t change this file directly).
Run sanity graphql deploy
to use new config for graphQL.
$ cd beneisenberg/sanity/
$ sanity graphql deploy
Gatsby’s build command should be run when you’ve added the finishing touches to your site and everything looks great. gatsby build creates a version of your site with production-ready optimizations like packaging up your site’s config, data, and code, and creating all the static HTML pages that eventually get rehydrated into a React application.
In the terminal run gatsby build
.
$ cd beneisenberg/sanity/
$ sanity graphql deploy
- Gatsby quick start (https://www.gatsbyjs.org/docs/quick-start)
- Linking Gatsby to Sanity (https://www.sanity.io/help/graphql-beta)