Skip to content

Commit 79a022a

Browse files
committed
Render aliases even if render=link
Fixes #7832
1 parent 50dfe40 commit 79a022a

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

hugolib/content_map.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,13 @@ var (
830830
}
831831
return n.p.m.noRender()
832832
}
833+
834+
contentTreeNoLinkFilter = func(s string, n *contentNode) bool {
835+
if n.p == nil {
836+
return true
837+
}
838+
return n.p.m.noLink()
839+
}
833840
)
834841

835842
func (c *contentTree) WalkQuery(query pageMapQuery, walkFn contentTreeNodeCallback) {
@@ -865,6 +872,13 @@ func (c contentTrees) WalkRenderable(fn contentTreeNodeCallback) {
865872
}
866873
}
867874

875+
func (c contentTrees) WalkLinkable(fn contentTreeNodeCallback) {
876+
query := pageMapQuery{Filter: contentTreeNoLinkFilter}
877+
for _, tree := range c {
878+
tree.WalkQuery(query, fn)
879+
}
880+
}
881+
868882
func (c contentTrees) Walk(fn contentTreeNodeCallback) {
869883
for _, tree := range c {
870884
tree.Walk(func(s string, v interface{}) bool {

hugolib/disableKinds_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ _build:
5858
"sect/no-render-link.md", `
5959
---
6060
title: No Render Link
61+
aliases: ["/link-alias"]
6162
_build:
6263
render: link
6364
---
@@ -319,10 +320,14 @@ title: Headless Local Lists Sub
319320
p := getPage(b, ref)
320321
b.Assert(p, qt.Not(qt.IsNil))
321322
b.Assert(p.RelPermalink(), qt.Equals, "/blog/sect/no-render-link/")
322-
b.Assert(p.OutputFormats(), qt.HasLen, 0)
323+
b.Assert(p.OutputFormats(), qt.HasLen, 1)
323324
b.Assert(getPageInSitePages(b, ref), qt.Not(qt.IsNil))
324325
sect := getPage(b, "/sect")
325326
b.Assert(getPageInPagePages(sect, ref), qt.Not(qt.IsNil))
327+
328+
// https://github.com/gohugoio/hugo/issues/7832
329+
// It should still render any aliases.
330+
b.AssertFileContent("public/link-alias/index.html", "refresh")
326331
})
327332

328333
c.Run("Build config, no publish resources", func(c *qt.C) {

hugolib/page__paths.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func newPagePaths(
7676
}
7777

7878
var out page.OutputFormats
79-
if !pm.noRender() {
79+
if !pm.noLink() {
8080
out = pageOutputFormats
8181
}
8282

hugolib/site_render.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,20 +323,28 @@ func (s *Site) renderRobotsTXT() error {
323323
// renderAliases renders shell pages that simply have a redirect in the header.
324324
func (s *Site) renderAliases() error {
325325
var err error
326-
s.pageMap.pageTrees.WalkRenderable(func(ss string, n *contentNode) bool {
326+
s.pageMap.pageTrees.WalkLinkable(func(ss string, n *contentNode) bool {
327327
p := n.p
328328
if len(p.Aliases()) == 0 {
329329
return false
330330
}
331331

332+
pathSeen := make(map[string]bool)
333+
332334
for _, of := range p.OutputFormats() {
333335
if !of.Format.IsHTML {
334-
return false
336+
continue
335337
}
336338

337-
plink := of.Permalink()
338339
f := of.Format
339340

341+
if pathSeen[f.Path] {
342+
continue
343+
}
344+
pathSeen[f.Path] = true
345+
346+
plink := of.Permalink()
347+
340348
for _, a := range p.Aliases() {
341349
isRelative := !strings.HasPrefix(a, "/")
342350

0 commit comments

Comments
 (0)