feat: add dynamic latest API redirects via Hugo templatin

pull/52591/head
caesarsage 2025-09-30 03:08:19 +01:00
parent dbfb690ee9
commit f6b6444f0b
4 changed files with 26 additions and 1 deletions

3
.gitignore vendored
View File

@ -38,3 +38,6 @@ nohup.out
# Generated files when building with make container-build
.config/
.npm/
# Local Netlify folder
.netlify

View File

@ -81,7 +81,7 @@ blog = "/:section/:year/:month/:day/:slug/"
# Be explicit about the output formats. We (currently) only want an RSS feed for the home page.
[outputs]
home = [ "HTML", "RSS", "HEADERS" ]
home = [ "HTML", "RSS", "HEADERS", "REDIRECTS"]
page = [ "HTML"]
section = [ "HTML", "print" ]
@ -101,6 +101,13 @@ baseName = "_headers"
isPlainText = true
notAlternative = true
# _redirects file output (uses the template at layouts/index.redirects)
[outputFormats.REDIRECTS]
mediatype = "text/netlify"
baseName = "_redirects"
isPlainText = true
notAlternative = true
# Image processing configuration.
[imaging]
resampleFilter = "CatmullRom" # cSpell:disable-line

15
layouts/index.redirects Normal file
View File

@ -0,0 +1,15 @@
{{- $latest := or .Site.Params.latest (errorf "missing .Site.Params.latest") -}}
###############################################
# set server-side redirects in this file #
# see https://www.netlify.com/docs/redirects/ #
# test at https://play.netlify.com/redirects #
###############################################
# Dynamic latest API redirect - automatically points to current latest version
/docs/reference/generated/kubernetes-api/latest/ /docs/reference/generated/kubernetes-api/{{ $latest }}/ 301
/docs/reference/generated/kubernetes-api/latest/* /docs/reference/generated/kubernetes-api/{{ $latest }}/:splat 301
# Include all existing static redirects
{{- $staticRedirects := readFile "static/_redirects.base" -}}
{{ $staticRedirects }}