Skip to content

Commit

Permalink
website: link to same page (if possible) from version picker (#3390)
Browse files Browse the repository at this point in the history
This might not be the most efficient or idiomatic way to do it, but
I think it works.

Doesn't do in-page anchors, so selecting a different version when on
page /docs/v0.26.0/policy-performance/#benchmarking-queries will get
you to /docs/<other>/policy-performance/ only.

Fixes #3023 to some extend. A little less annoying now, I hope.

Signed-off-by: Stephan Renatus <[email protected]>
  • Loading branch information
srenatus authored Apr 16, 2021
1 parent dd35d6c commit 27d658c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ support backwards compatible URLs (from pre-netlify days) and to have the `lates
version of the docs URLs work
[openpolicyagent.org/docs/latest](https://openpolicyagent.org/docs/latest) the site
relies on Netlify URL [redirects and rewrites](https://www.netlify.com/docs/redirects/)
which are defined in [website/layouts/index.redirects](./webiste/layouts/index.redirects)
which are defined in [website/layouts/index.redirects](./website/layouts/index.redirects)
and are build into a `_redirects` file when the Hugo build happens via
`make production-build` or `make preview-build`.

Expand Down Expand Up @@ -127,7 +127,7 @@ docker run --rm -it --net=host linkchecker/linkchecker $URL
Note: You may need to adjust the `URL` (host and/or port) depending on the environment. For OSX
and Windows the host might need to be `host.docker.internal` instead of `localhost`.

> This link checker will work on best with Netlify previews! Just point it at the preview URL instead of the local server.
> This link checker will work best with Netlify previews! Just point it at the preview URL instead of the local server.
The "pretty url" feature seems to work best when deployed, running locally may result in erroneous links.

## Live Code Blocks
Expand Down
2 changes: 1 addition & 1 deletion docs/website/layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ $isDoc := eq .Section "docs" }}
{{ $isHome := .IsHome }}
{{ $isHome := .IsHome }}
{{ if $isHome }}
{{/* The homepage layouts/index.html template defines its own <head> content. */}}
{{ block "main" . }}
Expand Down
7 changes: 6 additions & 1 deletion docs/website/layouts/partials/docs/dashboard-panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{{ $releases := site.Data.releases }}
{{ $latest := index $releases 1 }}
{{ $version := index (split .File.Path "/") 1 }}
{{ $page := trim .RelPermalink "/" }}
{{ $isLatest := or (eq $version $latest) (eq $version "latest") }}
<div class="dashboard-panel left has-background-white-bis is-hidden-mobile">
<div class="dashboard-panel-header has-text-centered">
Expand Down Expand Up @@ -52,7 +53,11 @@
{{ if $isLatest }}
{{ $verRef = "latest" }}
{{ end }}
<a href="/docs/{{ $verRef }}" class="dropdown-item">
{{ $versionedLink := strings.Replace $page $version $verRef }}
{{ if (eq (site.GetPage $versionedLink).Content "") }}
{{ $versionedLink = printf "docs/%s" $verRef }}
{{ end }}
<a href="{{ printf "/%s" $versionedLink }}" class="dropdown-item">
{{ . }}
{{ if $isLatest }}
<span class="tag latest-tag is-success is-small has-text-weight-bold">
Expand Down

0 comments on commit 27d658c

Please sign in to comment.