hugolib: No links for bundled pages
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 22 Apr 2019 07:13:47 +0000 (09:13 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 22 Apr 2019 11:22:01 +0000 (13:22 +0200)
This fixes a bug introduced in Hugo 0.55.

Fixes #5882

hugolib/page__meta.go
hugolib/page__new.go
hugolib/page__paths.go
hugolib/pagebundler_handlers.go
hugolib/pagebundler_test.go

index 64c72b8958523d3f0b5731c3e0997011405017d5..d14b9d724f5469c9a6c9e9199ac53b2fc17af26e 100644 (file)
@@ -98,6 +98,9 @@ type pageMeta struct {
        // 3. But you can get it via .Site.GetPage
        headless bool
 
+       // Set if this page is bundled inside another.
+       bundled bool
+
        // A key that maps to translation(s) of this page. This value is fetched
        // from the page front matter.
        translationKey string
index c703867f170b9c48078f95d72d222565274215a9..64c84b0f8b01dcb5b0180bcaa70c207273bcf5c3 100644 (file)
@@ -166,14 +166,14 @@ func newPageStandalone(m *pageMeta, f output.Format) (*pageState, error) {
 
 }
 
-func newPageWithContent(f *fileInfo, s *Site, content resource.OpenReadSeekCloser) (*pageState, error) {
+func newPageWithContent(f *fileInfo, s *Site, bundled bool, content resource.OpenReadSeekCloser) (*pageState, error) {
        sections := s.sectionsFromFile(f)
        kind := s.kindFromFileInfoOrSections(f, sections)
        if kind == page.KindTaxonomy {
                s.PathSpec.MakePathsSanitized(sections)
        }
 
-       metaProvider := &pageMeta{kind: kind, sections: sections, s: s, f: f}
+       metaProvider := &pageMeta{kind: kind, sections: sections, bundled: bundled, s: s, f: f}
 
        ps, err := newPageBase(metaProvider)
        if err != nil {
index 8bc7a753556818206edecf80b2d2994c16d53ca9..adbdb4668c7c17c7bb4fbe7598159adb930deaec 100644 (file)
@@ -52,7 +52,9 @@ func newPagePaths(
 
                var relPermalink, permalink string
 
-               if !pm.headless {
+               // If a page is headless or bundled in another, it will not get published
+               // on its own and it will have no links.
+               if !pm.headless && !pm.bundled {
                        relPermalink = paths.RelPermalink(s.PathSpec)
                        permalink = paths.PermalinkForOutputFormat(s.PathSpec, f)
                }
index c217b5e094455dabc80a849617bc95f45e6ca9e6..e745a04f2ac14305d1e1a737172bed3202ba6328 100644 (file)
@@ -197,7 +197,7 @@ func (c *contentHandlers) parsePage(h contentHandler) contentHandler {
                        return f, nil
                }
 
-               ps, err := newPageWithContent(fi, c.s, content)
+               ps, err := newPageWithContent(fi, c.s, ctx.parentPage != nil, content)
                if err != nil {
                        return handlerResult{err: err}
                }
index 06bd641542f1a805c0e8106b7a54a4dde2e960ec..64c1529d8928e3ab19c086eea2cdfdfca3d01429 100644 (file)
@@ -237,10 +237,17 @@ func TestPageBundlerSiteRegular(t *testing.T) {
                                                                "Short Thumb Width: 56",
                                                                "1: Image Title: Sunset Galore 1",
                                                                "1: Image Params: map[myparam:My Sunny Param]",
+                                                               relPermalinker("1: Image RelPermalink: %s/2017/pageslug/sunset1.jpg"),
                                                                "2: Image Title: Sunset Galore 2",
                                                                "2: Image Params: map[myparam:My Sunny Param]",
                                                                "1: Image myParam: Lower: My Sunny Param Caps: My Sunny Param",
+                                                               "0: Page Title: Bundle Galore",
                                                        )
+
+                                                       // https://github.com/gohugoio/hugo/issues/5882
+                                                       th.assertFileContent(
+                                                               filepath.FromSlash("/work/public/2017/pageslug.html"), "0: Page RelPermalink: |")
+
                                                        th.assertFileContent(filepath.FromSlash("/work/public/cpath/2017/pageslug.html"), "TheContent")
 
                                                        // 은행
@@ -642,11 +649,16 @@ Thumb Name: {{ $thumb.Name }}
 Thumb Title: {{ $thumb.Title }}
 Thumb RelPermalink: {{ $thumb.RelPermalink }}
 {{ end }}
-{{ range $i, $e := .Resources.ByType "image" }}
-{{ $i }}: Image Title: {{ .Title }}
-{{ $i }}: Image Name: {{ .Name }}
-{{ $i }}: Image Params: {{ printf "%v" .Params }}
-{{ $i }}: Image myParam: Lower: {{ .Params.myparam }} Caps: {{ .Params.MYPARAM }}
+{{ $types := slice "image" "page" }}
+{{ range $types }}
+{{ $typeTitle := . | title }}
+{{ range $i, $e := $.Resources.ByType . }}
+{{ $i }}: {{ $typeTitle }} Title: {{ .Title }}
+{{ $i }}: {{ $typeTitle }} Name: {{ .Name }}
+{{ $i }}: {{ $typeTitle }} RelPermalink: {{ .RelPermalink }}|
+{{ $i }}: {{ $typeTitle }} Params: {{ printf "%v" .Params }}
+{{ $i }}: {{ $typeTitle }} myParam: Lower: {{ .Params.myparam }} Caps: {{ .Params.MYPARAM }}
+{{ end }}
 {{ end }}
 `