Skip to content

Instantly share code, notes, and snippets.

@ZackBoe
Last active January 18, 2019 16:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ZackBoe/99da0eb2d04145b146c3727494ef8a4f to your computer and use it in GitHub Desktop.
Save ZackBoe/99da0eb2d04145b146c3727494ef8a4f to your computer and use it in GitHub Desktop.
Generate netlify _redirects from Hugo data file for editing in Forestry.io
  • config.toml: /config.toml
  • index.redir: /layouts/index.redir
  • redirects-json.yml: .forestry/front_matter/templates/redirects-json.yml
  • redirects.json: /data/redirects.json
[outputs]
home = ["HTML", "REDIR"]
[mediaTypes]
[mediaTypes."text/netlify"]
delimiter = ""
[outputFormats]
[outputFormats.REDIR]
mediatype = "text/netlify"
baseName = "_redirects"
isPlainText = true
notAlternative = true
# Netlify redirects. See https://www.netlify.com/docs/redirects/
# Edit redirects in /data/redirects.json
{{ range $r := .Site.Data.redirects }}
{{ $r.from }} {{ $r.to }} {{ if $r.status }}{{ $r.status }}{{ end }}
{{ end }}
---
label: redirects.json
hide_body: true
is_partial: false
fields:
- name: Redirects
label: Redirects
type: field_group_list
fields:
- name: from
label: From URL
type: text
hidden: false
default: ''
config:
required: true
description: URL to redirect from (/about.html)
- name: to
label: To URL
type: text
hidden: false
default: ''
config:
required: true
description: URL to redirect to (/about)
- name: status
label: Status
type: text
hidden: false
default: ''
description: 'Optional redirect status. Default: 301'
hidden: false
default: ''
description: 'Documentation: https://www.netlify.com/docs/redirects/'
pages:
- data/redirects.json
[
{
"from": "/contact.html",
"to": "/contact",
"status": ""
},
{
"from": "/home.html",
"to": "/",
"status": 302
},
{
"from": "/about.html",
"to": "/about"
}
]
@ZackBoe
Copy link
Author

ZackBoe commented Nov 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment