Awesome
<h1 align="center"> Gatsby + Staticman + Heroku </h1>Handle comments on your Gatsby site with Staticman. How? By running your own instance of Staticman by Eduardo Boucas, and giving it access to your Github repo.
Requirements
- Node.js 8.11.3+
- npm
- A personal access token for the GitHub and/or GitLab account you want to run Staticman with
- An RSA key in PEM format
Initial setup
1. Create a Github bot account.
This will act as a robot for handling comments. This is just an ordinary account but we will use it to create a personal access token
.
2. Generate a personal access token for the bot.
Go to Settings > Developer settings > Personal access tokens and Generate new token
. Give it a name and set the scope access to: repo
and user
.
Generate the token and then write it down somwhere, we will use this later on.
Hosting your own Staticman API
- Clone an instance of Staticman
- In the Staticman folder, create a
Procfile
with the single line:web: npm start
- Create a private RSA key for use with the API:
$ openssl genrsa -out key.pem
- Host your instance on Heroku and configure it:
$ cd ~/staticman heroku create <app_name>
$ git init
: Create a new Git repository.
$ heroku apps
: List your apps.
$ heroku git:remote -a <app_name>
: Add a remote to your local repo.
$ heroku config:set NODE_ENV="production"
$ heroku config:set RSA_PRIVATE_KEY="$(cat key.pem)"
$ heroku config:set GITHUB_TOKEN="Your_Token"
: Replace Your_Token with thepersonal access token
we created earlier. - Create a production branch:
git checkout -b production master
- Commit the changes, and deploy the API:
$ git push heroku production:master
- Confirm everything works by visiting your API instance at: https://<app_name>.herokuapp.com and you should be greeted with Hello from Staticman version 3.0.0!
Setup site
- Clone this repo to your computer.
- In
comments.js
file inside src > components update the form url:
https://<app_name>.herokuapp.com/v2/entry/<github_username>/<github_repo>/master/comments
: Your personal Github username (not the bot) and site repo (not API) - Configure the existing
staticman.yml
to your needs. Have a look at Staticman sample config file for all available options. - Push and commit changes to Github, and voila!