Skip to content

Commit

Permalink
[CI/infra] Generate redirects for aliases (#88)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrice Chalin <[email protected]>
  • Loading branch information
chalin authored Dec 16, 2024
1 parent f073e46 commit d8d2dd8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
3 changes: 3 additions & 0 deletions content/en/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
title: in-toto
outputs:
- HTML
- REDIRECTS # Include this `content/en` ONLY
description: A framework to secure the integrity of software supply chains
---

Expand Down
1 change: 1 addition & 0 deletions content/en/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: About in-toto
linkTitle: About
menu: { main: { weight: 10 } }
aliases: [/in-toto]
---

{{% blocks/cover title="About in-toto" height="auto" %}}
Expand Down
1 change: 1 addition & 0 deletions content/en/docs/faq.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Frequently asked questions
linkTitle: FAQ
aliases: [/faq]
weight: 900
---

Expand Down
1 change: 1 addition & 0 deletions content/en/docs/specs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Specifications
linkTitle: Specs
aliases: [/specs]
weight: 70
---

Expand Down
13 changes: 10 additions & 3 deletions hugo.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
baseURL: https://in-toto.io
title: in-toto

# cSpell:ignore Catmull Libera noopener
# cSpell:ignore AFRL Catmull DARPA docsy Libera noopener

disableKinds: [taxonomy]
theme: [docsy]
Expand All @@ -13,9 +13,16 @@ enableGitInfo: true

disableAliases: true # We do redirects via Netlify's _redirects file

mediaTypes:
text/netlify: {}

outputFormats:
REDIRECTS:
mediaType: text/netlify
baseName: _redirects
notAlternative: true

outputs:
home: [HTML]
page: [HTML]
section: [HTML]

imaging:
Expand Down
36 changes: 32 additions & 4 deletions static/_redirects → layouts/index.redirects
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Netlify redirects. See https://www.netlify.com/docs/redirects/
{{/* cSpell:ignore cond wordmark */ -}}

# No versions mentioned in the spec so assume v0.1
Envelope/v0.1 https://github.com/in-toto/attestation/tree/v0.1.0/spec#envelope
Predicate/v0.1 https://github.com/in-toto/attestation/tree/v0.1.0/spec#predicate
Envelope/v0.1 https://github.com/in-toto/attestation/tree/v0.1.0/spec#envelope
Predicate/v0.1 https://github.com/in-toto/attestation/tree/v0.1.0/spec#predicate

# Below version numbers are in the spec at the v0.1.0 tag.
Statement/v0.1 https://github.com/in-toto/attestation/tree/v0.1.0/spec#statement
Expand All @@ -9,8 +12,8 @@ Provenance/v0.1.0 https://github.com/in-toto/attestation/tree/v0.1.0/spec/predic
SPDX/v1.0.0 https://github.com/in-toto/attestation/blob/v0.1.0/spec/predicates/spdx.md

# Bonus: v0.1.0 <-> v0.1
Envelope/v0.1.0 https://github.com/in-toto/attestation/tree/v0.1.0/spec#envelope
Predicate/v0.1.0 https://github.com/in-toto/attestation/tree/v0.1.0/spec#predicate
Envelope/v0.1.0 https://github.com/in-toto/attestation/tree/v0.1.0/spec#envelope
Predicate/v0.1.0 https://github.com/in-toto/attestation/tree/v0.1.0/spec#predicate
Provenance/v0.1 https://github.com/in-toto/attestation/tree/v0.1.0/spec/predicates/provenance.md
Statement/v0.1.0 https://github.com/in-toto/attestation/tree/v0.1.0/spec#statement

Expand All @@ -37,3 +40,28 @@ attestation/test-result/v* https://github.com/in-toto/attestation/tree/main/spec

attestation/vulns https://github.com/in-toto/attestation/tree/main/spec/predicates/vuln.md
attestation/vulns/v* https://github.com/in-toto/attestation/tree/main/spec/predicates/vuln.md

{{ range $p := .Site.Pages -}}

{{ range $p.Aliases -}}
{{ $alias := cond (strings.HasPrefix . "/")
.
(partial "relative-redirects-alias" (dict "alias" . "p" $p.Parent)) -}}
{{ $alias | printf "%-35s" }} {{ $p.RelPermalink }}
{{ end -}}

{{ end }}{{/* range $p */ -}}

{{- define "partials/relative-redirects-alias" -}}
{{ $result := "" }}
{{ if strings.HasPrefix .alias "../" }}
{{ $result = (partial "relative-redirects-alias"
(dict
"alias" (strings.TrimPrefix "../" .alias)
"p" .p.Parent ))
}}
{{ else }}
{{ $result = path.Join .p.RelPermalink .alias }}
{{ end }}
{{ return $result }}
{{ end }}

0 comments on commit d8d2dd8

Please sign in to comment.