Commit fad0cee
committed
redirect_to/aliases: keep the anchor, if any was specified
When redirecting from a URL specifying an anchor (e.g. links like
https://git-scm.com/docs/git#_git_commands), the regular redirection
mechanism would lose the `#<anchor>` part, which is unfortunate.
This is important because some translated manual pages point to
non-existing translated pages with an anchor. For example, the German
version of the `git` manual page points to
`docs/user-manual/de#git-concepts`, i.e. to the `git-concepts` anchor of
the German version of the `user-manual` (that does not exist yet).
Redirecting to such a large page without that specific anchor would be
quite unhelpful for the reader. So let's make sure that redirections
respect the specified anchor (this requires Javascript code to be
executed, in case Javascript is disabled this will fall back to the
traditional "redirect-without-anchor" functionality).
We do this in the layout that handles our custom `redirect_to:` front
matter directive as well as in the newly-introduced `layouts/alias.html`
which overrides Hugo's default handling of the `aliases:` directive.
One easy to miss part of this patch is that `layouts/alias.html` must be
careful to URI-encode any question mark in the URL to redirect to: These
are not URI-encoded in Hugo's `.Permalink` (at least not when the page
itself specifies a `url` in its front matter that contains a bare
question mark, something we need to do in the book sections because
otherwise the code implementing the navigation faces problems).
Signed-off-by: Johannes Schindelin <[email protected]>1 parent 6e69b7f commit fad0cee
2 files changed
+17
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
0 commit comments