Skip to content

Commit bc784a7

Browse files
authored
Override alias template to preserve anchor fragment (#24394)
This PR fixes an annoyance where docs aliases aren't preserving their anchor fragments. The refactor included aliases to keep old links from dying, but currently they redirect without their anchor, which was used _often_ to jump to sections. This overrides the alias template with an alternative that preserves the anchor fragment. To note, this is just a copy of the [embedded template](https://github.com/gohugoio/hugo/blob/5c7b79cf7f00aa2651dd5f0364ee575af6715a31/tpl/tplimpl/embedded/templates/alias.html), but defaults to a JS redirect that preserves the anchor, and uses the meta tag as a fallback for noscript users. --------- Signed-off-by: jolheiser <[email protected]>
1 parent 3843252 commit bc784a7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/layouts/alias.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html{{ with site.LanguageCode | default site.Language.Lang }} lang="{{ . }}"{{ end }}>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>{{ .Permalink }}</title>
6+
<link rel="canonical" href="{{ .Permalink }}">
7+
<meta name="robots" content="noindex">
8+
<noscript><meta http-equiv="refresh" content="0; url={{ .Permalink }}"></noscript>
9+
<script>
10+
window.location = "{{ .Permalink }}" + window.location.search + window.location.hash;
11+
</script>
12+
</head>
13+
</html>

0 commit comments

Comments
 (0)