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-started23pip install mkdocs4mkdocs new my-project5cd 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/cli34# 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'23const ONE_MINUTE = 604const FAR_FUTURE = 60 * 60 * 24 * 365 * 1056const dynamicPaths = ['css', 'fonts', 'img', 'js', 'search']78const router = new Router()910dynamicPaths.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})2425// Prevent search engine bot(s) from indexing26// Read more on: https://docs.layer0.co/applications/cookbook#blocking-search-engine-crawlers27router.noIndexPermalink()2829router.match('/:path*', ({ serveStatic, cache }) => {30 cache({31 browser: false,32 edge: {33 maxAgeSeconds: FAR_FUTURE,34 },35 })36 serveStatic('site/:path*')37})3839export default router
Deploying
Deploy your app to the Sites by running the following commands in your project’s root directory:
Bash
1# Create a production build of your mkdocs site2npm run build34# Deploy it to the Sites50 deploy