Edgio
Edgio

MkDocs

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 Edgio.

Create your MkDocs site

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

Bash
1# https://www.mkdocs.org/getting-started
2
3pip install mkdocs
4mkdocs new my-project
5cd my-project

Add Edgio

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

JSON
1{
2 "name": "mkdocs",
3 "version": "1.0.0",
4 "scripts": {
5 "build": "python3 -m mkdocs build",
6 "server": "python3 -m mkdocs serve",
7 "layer0:dev": "layer0 dev",
8 "postinstall": "pip3 install mkdocs",
9 "layer0:build": "npm run build && layer0 build",
10 "layer0:deploy": "npm run build && layer0 deploy"
11 },
12 "dependencies": {},
13 "devDependencies": {}
14}
Bash
1# First, globally install the Edgio CLI:
2npm i -g @layer0/cli # yarn global add @layer0/cli
3
4# Then, add Edgio to your MkDocs site:
50 init

Update your Edgio Router

Paste the following into routes.js:

JavaScript
1import { Router } from '@layer0/core'
2
3const ONE_MINUTE = 60
4const FAR_FUTURE = 60 * 60 * 24 * 365 * 10
5
6const dynamicPaths = ['css', 'fonts', 'img', 'js', 'search']
7
8const router = new Router()
9
10dynamicPaths.forEach((i) => {
11 router.match(`/${i}/:path*`, ({ serveStatic, cache }) => {
12 cache({
13 browser: {
14 maxAgeSeconds: FAR_FUTURE,
15 },
16 edge: {
17 maxAgeSeconds: ONE_MINUTE,
18 staleWhileRevalidateSeconds: FAR_FUTURE,
19 },
20 })
21 serveStatic(`site/${i}/:path*`)
22 })
23})
24
25// Prevent search engine bot(s) from indexing
26// Read more on: https://docs.layer0.co/guides/cookbook#blocking-search-engine-crawlers
27router.noIndexPermalink()
28
29router.match('/:path*', ({ serveStatic, cache }) => {
30 cache({
31 browser: false,
32 edge: {
33 maxAgeSeconds: FAR_FUTURE,
34 },
35 })
36 serveStatic('site/:path*')
37})
38
39export default router

Deploying

Deploy your app to the App Platform by running the following commands in your project’s root directory:

Bash
1# Create a production build of your mkdocs site
2npm run build
3
4# Deploy it to the App Platform
50 deploy