Skip to content

Commit 0e89819

Browse files
authored
Merge pull request #52591 from Caesarsage/add-latest-api-ref
feat: add dynamic latest API redirects via Hugo templating
2 parents ad8d4b5 + 9c3463f commit 0e89819

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ nohup.out
3838
# Generated files when building with make container-build
3939
.config/
4040
.npm/
41+
42+
# Local Netlify folder
43+
.netlify

hugo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ blog = "/:section/:year/:month/:day/:slug/"
8181

8282
# Be explicit about the output formats. We (currently) only want an RSS feed for the home page.
8383
[outputs]
84-
home = [ "HTML", "RSS", "HEADERS" ]
84+
home = [ "HTML", "RSS", "HEADERS", "REDIRECTS"]
8585
page = [ "HTML"]
8686
section = [ "HTML", "print" ]
8787

@@ -101,6 +101,13 @@ baseName = "_headers"
101101
isPlainText = true
102102
notAlternative = true
103103

104+
# _redirects file output (uses the template at layouts/index.redirects)
105+
[outputFormats.REDIRECTS]
106+
mediatype = "text/netlify"
107+
baseName = "_redirects"
108+
isPlainText = true
109+
notAlternative = true
110+
104111
# Image processing configuration.
105112
[imaging]
106113
resampleFilter = "CatmullRom" # cSpell:disable-line

layouts/index.redirects

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- $latest := or .Site.Params.latest (errorf "missing .Site.Params.latest") -}}
2+
3+
###############################################
4+
# set server-side redirects in this file #
5+
# see https://www.netlify.com/docs/redirects/ #
6+
# test at https://play.netlify.com/redirects #
7+
###############################################
8+
9+
# Dynamic latest API redirect - automatically points to current latest version
10+
/docs/reference/generated/kubernetes-api/latest/ /docs/reference/generated/kubernetes-api/{{ $latest }}/ 307
11+
/docs/reference/generated/kubernetes-api/latest/* /docs/reference/generated/kubernetes-api/{{ $latest }}/:splat 307
12+
13+
# Include all existing static redirects
14+
{{- $staticRedirects := readFile "static/_redirects.base" -}}
15+
{{ $staticRedirects }}

static/_redirects renamed to static/_redirects.base

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
# test at https://play.netlify.com/redirects #
55
###############################################
66

7+
# NOTE: This is the SOURCE FILE for static redirects.
8+
#
9+
# How to add redirects:
10+
# - For STATIC redirects (fixed paths): Add them to THIS FILE
11+
# - For DYNAMIC redirects (using Hugo variables/logic): Edit layouts/index.redirects
12+
#
13+
# The actual _redirects file is auto-generated by Hugo from layouts/index.redirects,
14+
# which combines dynamic redirects with the static redirects from this file.
15+
16+
717
/concepts/containers/container-lifecycle-hooks/ /docs/concepts/containers/container-lifecycle-hooks/ 301
818
/docs/ /docs/home/ 301!
919
/bn/docs/ /bn/docs/home/ 301!

0 commit comments

Comments
 (0)