hugolib: Allow page-relative aliases

Fixes #5757
This commit is contained in:
Bjørn Erik Pedersen
2019-03-30 17:08:25 +01:00
parent a55640de8e
commit 92baa14fd3
7 changed files with 46 additions and 29 deletions

View File

@@ -303,7 +303,20 @@ func (s *Site) renderAliases() error {
f := of.Format
for _, a := range p.Aliases() {
if f.Path != "" {
isRelative := !strings.HasPrefix(a, "/")
if isRelative {
// Make alias relative, where "." will be on the
// same directory level as the current page.
// TODO(bep) ugly URLs doesn't seem to be supported in
// aliases, I'm not sure why not.
basePath := of.RelPermalink()
if strings.HasSuffix(basePath, "/") {
basePath = path.Join(basePath, "..")
}
a = path.Join(basePath, a)
} else if f.Path != "" {
// Make sure AMP and similar doesn't clash with regular aliases.
a = path.Join(f.Path, a)
}