From 7cb28fccfea5be7f5a22ddd9f895cd04cda68dc1 Mon Sep 17 00:00:00 2001 From: Spencer Smith Date: Fri, 5 Aug 2022 17:08:42 -0400 Subject: [PATCH] docs: handle latest version banner and canonical urls This PR is a copy of two PRs from talos: https://github.com/siderolabs/talos/pull/5389/files https://github.com/siderolabs/talos/pull/5391/files It ensures that the banner is shown if the user isn't viewing the latest sidero docs. This actually already was working but the banner html was in an incorrect spot, so moved that to match what's seen in Talos repo. Also adds the canonical links for search engines to update their indexes. Signed-off-by: Spencer Smith --- netlify.toml | 2 +- website/assets/scss/_styles_project.scss | 5 +++++ .../layouts/partials/doc_latest_version.html | 10 ++++++++++ website/layouts/partials/hooks/head-end.html | 12 ++++++++++++ .../layouts/partials/version-banner.html | 19 ++++++++++--------- 5 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 website/assets/scss/_styles_project.scss create mode 100644 website/layouts/partials/doc_latest_version.html rename website/{themes/docsy => }/layouts/partials/version-banner.html (62%) diff --git a/netlify.toml b/netlify.toml index 2b7cd616..05f9b877 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,5 +1,5 @@ [build] -command = "cd website && hugo --gc --minify" +command = "cd website && hugo --gc --minify --baseURL $DEPLOY_PRIME_URL" publish = "website/public" [build.environment] diff --git a/website/assets/scss/_styles_project.scss b/website/assets/scss/_styles_project.scss new file mode 100644 index 00000000..4af74d9f --- /dev/null +++ b/website/assets/scss/_styles_project.scss @@ -0,0 +1,5 @@ +.version-banner { + position: sticky; + top: 5rem; + z-index: 1; +} \ No newline at end of file diff --git a/website/layouts/partials/doc_latest_version.html b/website/layouts/partials/doc_latest_version.html new file mode 100644 index 00000000..3f9aaf80 --- /dev/null +++ b/website/layouts/partials/doc_latest_version.html @@ -0,0 +1,10 @@ +{{ $page := .Site.Params.url_latest_version }} +{{ $doc_latest_version := replaceRE (.Section | printf "^/%s") .Site.Params.url_latest_version .Page.RelPermalink | path.Clean }} +{{ range $p := (where .Site.Pages "Section" (.Site.Params.url_latest_version | strings.TrimPrefix "/")) }} +{{ $page = cond (eq $doc_latest_version ($p.RelPermalink | path.Clean)) $p.RelPermalink $page }} +{{ range .Aliases }} +{{ $alias := cond (hasPrefix . "/") . (path.Join $p.RelPermalink ".." .) }} +{{ $page = cond (eq $alias $doc_latest_version) $p.RelPermalink $page}} +{{ end }} +{{ end }} +{{ return $page }} \ No newline at end of file diff --git a/website/layouts/partials/hooks/head-end.html b/website/layouts/partials/hooks/head-end.html index 357c44a2..cd455b5a 100644 --- a/website/layouts/partials/hooks/head-end.html +++ b/website/layouts/partials/hooks/head-end.html @@ -4,4 +4,16 @@ {{ if (findRE " +{{ end }} + + +{{ if .Section }} + {{ $latest_version := .Site.Params.url_latest_version }} + {{ $current_version := .Section | printf "/%s" }} + {{ if ne $latest_version $current_version }} + {{ $latest_doc := partial "doc_latest_version.html" . }} + {{ if ne $latest_doc $latest_version }} + + {{ end }} + {{ end }} {{ end }} \ No newline at end of file diff --git a/website/themes/docsy/layouts/partials/version-banner.html b/website/layouts/partials/version-banner.html similarity index 62% rename from website/themes/docsy/layouts/partials/version-banner.html rename to website/layouts/partials/version-banner.html index ff87881e..6940585d 100644 --- a/website/themes/docsy/layouts/partials/version-banner.html +++ b/website/layouts/partials/version-banner.html @@ -2,26 +2,27 @@ If yes, display a banner. --> {{ $latest_version := .Site.Params.url_latest_version }} {{ $current_version := .Section | printf "/%s" }} +{{ $latest_doc := partial "doc_latest_version.html" . }} {{ if .FirstSection.Params.prerelease }} - {{ $color := "primary" }} -
+ {{ $color := "info" }} +
{{ with $current_version }}

Version {{ trim . "/" | markdownify }} of the - documentation is for the Sidero version being developed. - {{ with $latest_version }}For the latest stable version of Sidero, see the - latest version.

+ documentation is for the Sidero Metal version being developed. + {{ with $latest_version }}For the latest stable version of Sidero Metal, see the + latest version.

{{ end }} {{ end }}
{{ else if ne $latest_version $current_version }} - {{ $color := "primary" }} -
+ {{ $color := "warning" }} +
{{ with $current_version }}

Version {{ trim . "/" | markdownify }} of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. {{ with $latest_version }}For up-to-date documentation, see the - latest version.

+ latest version.

{{ end }} {{ end }}
-{{ end }} +{{ end }} \ No newline at end of file