Skip to content
Simple wrapper around Staticman that allows it to be hosted as a netlify function.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
functions/staticman
.gitignore
README.md

README.md

staticman-netlify-function

staticman breaks free from servers

Introduction

Simple wrapper around Staticman that allows it to be hosted as a netlify function. I wrote this to overcome the frequent outages the public instance of staticman was facing due to its increased usage by the static site community.

Setup

  • Create/edit a netlify.toml file at the root of your project with the following content. The important thing to note here is the functions field which tells netlify where your functions are kept in the project
[build]
  command = "yarn build"
  functions = "functions"
  publish = "build"
  • Clone / download this repository and copy the functions folder to your project

  • Add a postinstall script to your project's package.json like so

// package.json
{
    "scripts": {
        //  existing scripts
        "postinstall": "cd functions/staticman && yarn"
    }
}
  • Commit and push the changes

Netlify should now automatically detect and deploy the function. Now to configure staticman.

Staticman needs a Github token with repo permissions and a RSA private key (On Mac this can be generated with ssh-keygen -t rsa -m pem) As documented here, this should be set under GITHUB_TOKEN and RSA_PRIVATE_KEY in Settings > Build & deploy > Environment > Environment variables (Environment variables in netlify)

Now you can continue past Step 2 in the guide and instead of calling https://api.staticman.net/v2/entry/{GITHUB USERNAME}/{GITHUB REPOSITORY}/{BRANCH}/{PROPERTY} in the examples, call https://{YOUR SITE}/.netlify/functions/staticman/{GITHUB USERNAME}/{GITHUB REPOSITORY}/{BRANCH}/{PROPERTY}

You can’t perform that action at this time.