Welcome! These instructions walk you through deploying your own instance of Staticman and connecting it to your static site.
Step 1. Git provider authentication
Staticman currently supports the following git providers:
- GitHub
- GitLab
- OneDev
In order to use Staticman, the repository for your static site must be hosted on one of these providers. The Staticman service needs to authenticate with the git provider to commit files and handle pull requests. This step will walk you through obtaining the necessary credentials.
If using GitLab to host the static site repo:
Create a personal access token with the following scopes
read_repository
: Necessary to read the Staticman site configapi
: Necessary to merge pull requests
If using GitHub to host the static site repo:
Option 1. Authenticate as a GitHub application
This is the recommended way to authenticate with GitHub. This method will give the most control over what Staticman can and can’t access.
- Create a new GitHub application. Ensure you use the following:
- Homepage:
"https://staticman.net/"
- Webhook URL:
"{STATICMAN_BASE_URL}/v1/webhook"
- e.x."https://mystaticmaninstance.herokuapp.com/v1/webhook"
- Contents:
Read & Write
- Necessary to read the Staticman site config - Pull Requests:
Read & Write
- Necessary to merge pull requests - Subscribe to
Pull request
events
- Homepage:
- Generate a private key for the app and note it down along with your app ID.
- Install the app on your GitHub account. You can limit its access to only the repo from which you host your static site
Option 2. Authenticate to GitHub using a personal access token on a bot
- Register a new GitHub account to run your Staticman bot and create a personal access token for this new account.
- From your main GitHub account, send your bot a collaboration invite.
- Return to this step once your Staticman instance is running and send a GET request to
{STATICMAN_BASE_URL}/v3/connect/{GIT_PROVIDER_USERNAME}/{REPO}
For example:
https://staticmaninstance.herokuapp.com/v3/connect/eduardoboucas/staticman.net
- You should get an
OK!
response and the bot should have accepted the collaboration invitation.
Option 3. Authenticate to GitHub using a personal access token on your main account
This option is not recommended as it gives Staticman direct and complete access to your primary GitHub account. Simply, create a personal access token on your primary account.
If using OneDev to host the static site repo:
Get your access token from the user setting: https://code.onedev.io/my/access-token
You need to configure the following config items for OneDev:
onedevBaseUrl
: API-Url, for examplehttps://code.onedev.io/api
onedevUsername
: your usernameonedevPassword
: your password or access token
Alternatively you can use the environment variables ONEDEV_BASE_URL
, ONEDEV_USERNAME
and ONEDEV_PASSWORD
.
Step 2. Deploy Staticman
Read through the Staticman API config values and note the config values you wish to use. At a minimum, you must include a way for Staticman to auth with a git provider, as well as an RSA private key. To generate the RSA private key you can use
If you need the newline literals (for example when using JSON configs since multiline strings are not permitted) you can use
Option 1. Deploy to Heroku
- Follow this link to deploy the latest stable Staticman code to Heroku.
- You can enter your Staticman API config values as Heroku config variables.
- (Optional) Create a fork of Staticman and set up a Heroku pipeline to deploy from the fork. This will help you to keep your instance up to date with the latest Staticman improvements and bug fixes.
Option 2. Deploy to your own infrastructure
If you prefer to use Docker, check out the Docker instructions. Otherwise continue below
- Clone the Staticman repo and ensure
node
andnpm
are installed. - Install the dependencies
npm install
- Create a new config from the sample
cp config.sample.json config.production.json
- Edit the new production config with any values you want, and then start the Staticman server
npm start
Step 3. Create a site configuration file
Staticman will look for a staticman.yml
file in the root of the repository, where various configuration parameters will be defined. These configuration values are specific to the site. This means one Staticman instance can be used with many websites and users.
You can use the sample site config file as a starting point and check the available site configuration parameters for more information.
Step 4. Hook up your forms
Forms on your static site should POST
to:
{STATICMAN_BASE_URL}/v3/entry/{GIT_PROVIDER}/{GIT_PROVIDER_USERNAME}/{REPO}/{BRANCH}/{property (optional)}
e.x. https://staticmaninstance.herokuapp.com/v3/entry/github/eduardoboucas/staticman/gh-pages/comments
You can view full API docs at {STATICMAN_BASE_URL}/api-docs
including example values.
All fields should be nested under a fields
array. Optionally, a options
array can be used to pass along additional information, such as the title of a post.
You can specify a redirect URL in a options[redirect]
field. When the form is submitted, users will be redirected to this URL automatically.
The following markup shows how the form for a simple commenting system would look like:
Step 5. Approve entries (optional)
If you enable content moderation (by setting moderation: true
in the site config), Staticman will send a pull request whenever a new entry is submitted. Merge the pull request to approve it, or close to discard.
Please note that this step will be skipped if you disable moderation, as entries will be pushed to the main branch immediately.
Congratulations! You should now have working Staticman setup. Once you’ve verified this is working, you can start to experiment with more advanced configurations.