MkDocs is a fast, simple and downright gorgeous static site generator that's geared towards building project documentation. Follow the steps below to deploy your MkDocs site to Layer0

If you don't have an existing MkDocs site, you can create one by running:

# https://www.mkdocs.org/getting-started

$ pip install mkdocs
$ mkdocs new my-project
$ cd my-project

Create a package.json at the root of your project with the following:

{
  "name": "mkdocs",
  "version": "1.0.0",
  "scripts": {
    "build": "python3 -m mkdocs build",
    "server": "python3 -m mkdocs serve",
    "layer0:dev": "layer0 dev",
    "postinstall": "pip3 install mkdocs",
    "layer0:build": "npm run build && layer0 build",
    "layer0:deploy": "npm run build && layer0 deploy"
  },
  "dependencies": {},
  "devDependencies": {}
}
# First, globally install the Layer0 CLI:
$ npm i -g @layer0/cli

# Then, add Layer0 to your MkDocs site:
$ 0 init

Paste the following into routes.js:

import { Router } from '@layer0/core'

const ONE_MINUTE = 60
const FAR_FUTURE = 60 * 60 * 24 * 365 * 10

const dynamicPaths = ['css', 'fonts', 'img', 'js', 'search']

const router = new Router()

dynamicPaths.forEach((i) => {
  router.match(`/${i}/:path*`, ({ serveStatic, cache }) => {
    cache({
      browser: {
        maxAgeSeconds: FAR_FUTURE,
      },
      edge: {
        maxAgeSeconds: ONE_MINUTE,
        staleWhileRevalidateSeconds: FAR_FUTURE,
      },
    })
    serveStatic(`site/${i}/:path*`)
  })
})

router.match('/:path*', ({ serveStatic, cache }) => {
  cache({
    browser: false,
    edge: {
      maxAgeSeconds: FAR_FUTURE,
    },
  })
  serveStatic('site/:path*')
})

export default router

To deploy your site to Layer0, run:

# Create a production build of your mkdocs site
$ npm run build

# Deploy it to Layer0
$ 0 deploy
Edit this guide on GitHub