Netlify

Deploy to Netlify with sensible defaults. Easily use Netlify Functions, Netlify Redirects, and Netlify Headers.

On this page

  1. .
  2. ├── assets/
  3. └── lambda/
  4. ├── layouts/
  5. ├── index.headers
  6. └── index.redirects
  7. └── netlify.toml

See also the Hugo Docs: Host on Netlify.

Functions

Functions in ./assets/lambda/ are compiled on build to ./functions/.

See also the Netlify docs: Functions overview

Redirects

./layouts/index.redirects is converted on build to ./public/_redirects.

  1. {{ range $pages := .Site.Pages -}}
  2. {{ range .Aliases -}}
  3. {{ . }} {{ $pages.RelPermalink -}}
  4. {{ end -}}
  5. {{ end -}}

See also the Netlify docs: Redirects and rewrites

Headers

./layouts/index.headers is converted on build to ./public/_headers.

  1. /*
  2. Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
  3. X-Content-Type-Options: nosniff
  4. X-XSS-Protection: 1; mode=block
  5. Content-Security-Policy: default-src 'none'; manifest-src 'self'; connect-src 'self'; font-src 'self'; img-src 'self'; script-src 'self'; style-src 'self'
  6. X-Frame-Options: SAMEORIGIN
  7. Referrer-Policy: strict-origin
  8. Feature-Policy: geolocation 'self'
  9. Cache-Control: public, max-age=31536000

See also the Netlify docs: Custom headers

Build and deploy

./netlify.toml:

  1. [build]
  2. publish = "public"
  3. functions = "functions"
  4. [build.environment]
  5. NODE_VERSION = "15.5.1"
  6. NPM_VERSION = "7.3.0"
  7. [context.production]
  8. command = "npx hugo --gc --minify && npx netlify-lambda build assets/lambda"
  9. [context.deploy-preview]
  10. command = "npx hugo --gc --minify -b $DEPLOY_PRIME_URL"
  11. [context.branch-deploy]
  12. command = "npx hugo --gc --minify -b $DEPLOY_PRIME_URL"
  13. [context.next]
  14. command = "npx hugo --gc --minify && npx netlify-lambda build assets/lambda"
  15. [context.next.environment]
  16. HUGO_ENV = "next"
  17. [[plugins]]
  18. package = "netlify-plugin-submit-sitemap"
  19. [plugins.inputs]
  20. baseUrl = "https://getdoks.org"
  21. sitemapPath = "/sitemap.xml"
  22. providers = [
  23. "google",
  24. "bing",
  25. "yandex"
  26. ]
  27. [dev]
  28. framework = "#custom"
  29. command = "npx rimraf public resources functions && npx hugo server --bind=0.0.0.0 --disableFastRender"
  30. targetPort = 1313
  31. port = 8888
  32. publish = "public"
  33. autoLaunch = false

See also the Netlify docs: File-based configuration