shithub: hugo

Download patch

ref: ead5799f7ea837fb2ca1879a6d37ba364e53827f
parent: d57be113243be4b76310d4476fbb7525d1452658
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Wed Oct 14 07:23:24 EDT 2020

Render aliases even if render=link

Fixes #7832

--- a/hugolib/content_map.go
+++ b/hugolib/content_map.go
@@ -830,6 +830,13 @@
 		}
 		return n.p.m.noRender()
 	}
+
+	contentTreeNoLinkFilter = func(s string, n *contentNode) bool {
+		if n.p == nil {
+			return true
+		}
+		return n.p.m.noLink()
+	}
 )
 
 func (c *contentTree) WalkQuery(query pageMapQuery, walkFn contentTreeNodeCallback) {
@@ -860,6 +867,13 @@
 
 func (c contentTrees) WalkRenderable(fn contentTreeNodeCallback) {
 	query := pageMapQuery{Filter: contentTreeNoRenderFilter}
+	for _, tree := range c {
+		tree.WalkQuery(query, fn)
+	}
+}
+
+func (c contentTrees) WalkLinkable(fn contentTreeNodeCallback) {
+	query := pageMapQuery{Filter: contentTreeNoLinkFilter}
 	for _, tree := range c {
 		tree.WalkQuery(query, fn)
 	}
--- a/hugolib/disableKinds_test.go
+++ b/hugolib/disableKinds_test.go
@@ -58,6 +58,7 @@
 			"sect/no-render-link.md", `
 ---
 title: No Render Link
+aliases: ["/link-alias"]
 _build:
   render: link
 ---
@@ -319,10 +320,14 @@
 		p := getPage(b, ref)
 		b.Assert(p, qt.Not(qt.IsNil))
 		b.Assert(p.RelPermalink(), qt.Equals, "/blog/sect/no-render-link/")
-		b.Assert(p.OutputFormats(), qt.HasLen, 0)
+		b.Assert(p.OutputFormats(), qt.HasLen, 1)
 		b.Assert(getPageInSitePages(b, ref), qt.Not(qt.IsNil))
 		sect := getPage(b, "/sect")
 		b.Assert(getPageInPagePages(sect, ref), qt.Not(qt.IsNil))
+
+		// https://github.com/gohugoio/hugo/issues/7832
+		// It should still render any aliases.
+		b.AssertFileContent("public/link-alias/index.html", "refresh")
 	})
 
 	c.Run("Build config, no publish resources", func(c *qt.C) {
--- a/hugolib/page__paths.go
+++ b/hugolib/page__paths.go
@@ -76,7 +76,7 @@
 	}
 
 	var out page.OutputFormats
-	if !pm.noRender() {
+	if !pm.noLink() {
 		out = pageOutputFormats
 	}
 
--- a/hugolib/site_render.go
+++ b/hugolib/site_render.go
@@ -323,19 +323,27 @@
 // renderAliases renders shell pages that simply have a redirect in the header.
 func (s *Site) renderAliases() error {
 	var err error
-	s.pageMap.pageTrees.WalkRenderable(func(ss string, n *contentNode) bool {
+	s.pageMap.pageTrees.WalkLinkable(func(ss string, n *contentNode) bool {
 		p := n.p
 		if len(p.Aliases()) == 0 {
 			return false
 		}
 
+		pathSeen := make(map[string]bool)
+
 		for _, of := range p.OutputFormats() {
 			if !of.Format.IsHTML {
-				return false
+				continue
 			}
 
-			plink := of.Permalink()
 			f := of.Format
+
+			if pathSeen[f.Path] {
+				continue
+			}
+			pathSeen[f.Path] = true
+
+			plink := of.Permalink()
 
 			for _, a := range p.Aliases() {
 				isRelative := !strings.HasPrefix(a, "/")