Page resources with a ResourceType of "page" are not published

Hi there,

haven’t been able to find a solution to this issue in the forum.

I follow the Quick Start guide (Quick start | Hugo) to create an example of my issue.

hugo new site quickstart
cd quickstart
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
echo "theme = 'ananke'" >> hugo.toml
hugo server

Then added:
content/index.md:

---
{{% resref test.md %}}

content/test.md:

my test

layouts/shortcodes/resref.html:

{{ .Page }}
{{ $resource := .Page.Page.Resources.GetMatch ($.Get 0) }}

{{ with $resource }}
    ResourceType: {{ .ResourceType }}
    Params: {{ .Params }}
    Title: {{ .Title }}
    Content: {{ .Content }}
    Permalink: "{{ .Permalink }}"
    RelPermalink: "{{ .RelPermalink }}"
{{ end }}

Result is:

ResourceType: page
Params: map[draft:false iscjklanguage:false]
Title: 
Content: <p>my test</p>

Permalink: ""
RelPermalink: ""

Why are Permalink and RelPermalink empty?

Problem 1

mv content/index.md content/_index.md

https://gohugo.io/troubleshooting/faq/#what-is-the-difference-between-an-indexmd-file-and-an-_indexmd-file

Problem 2

Branch bundles (which includes the home page) cannot have page resources where the ResourceType is page.

https://gohugo.io/content-management/page-bundles/#comparison

Problem 3

.Page.Page.Resources

That’s not necessary. .Page.Resources is sufficient.

Question

What are you trying to do?

Ok, so my actual case is not in the root directory of content. So I have a leaf bundle and want to reference other pages.

I use leaf bundles because I want to discern between navigation levels (branch bundles for section navigation and leaf bundles for extra content).

Doing mv content/index.md content/_index.md transforms the leaf bundle into a branch bundle which I don’t really want.

Reducing the double .Page.Page to just .Page also does not work.

Do page resources just never have a Permalink?

The home page is, by definition, a branch bundle, and must be represented by an _index.md file. You cannot change the home page into a leaf bundle.

Please share your actual use case.

Thanks for the input.

I moved index.md and test.md into content/test/ directory. It doesn’t change much about the case however.

Now under http://localhost:1313/test/ the result is:

ResourceType: page
Params: map[draft:false iscjklanguage:false]
Title: 
Content: <p>my test</p>

Permalink: ""
RelPermalink: ""

Permalink is empty. And I don’t understand why.

To me this looks like a bug. If it’s not a bug, I’d expect an exception to be documented here: Permalink | Hugo

With the exception of the index file, all of the files in a leaf bundle are page resources. Each page resource has a ResourceType.

content/
├── leaf-bundle-1/
│   ├── a.jpg     <-- page resource with ResourceType = image
│   ├── b.md      <-- page resource with ResourceType = page
│   └── index.md
├── leaf-bundle-2/
│   ├── c.jpg     <-- page resource with ResourceType = image
│   └── index.md
└── _index.md

Hugo supports six content formats. Page resources with any of these media types have a ResourceType of page. Page resources with a ResourceType of page are not published, and their Permalink and RelPermalink methods return an empty string.

We can do a better job of documenting this behavior, and the terminology isn’t great either:
https://github.com/gohugoio/hugoDocs/issues/2428

The use case for page resources with a ResouceType of page is to augment content. For example, create Markdown snippets that you can insert with a shortcode:

layouts/shortcodes/include-page-resource.html
{{ with .Get 0 }}
  {{ with $.Page.Resources.Get . }}
    {{- .RenderShortcodes }}
  {{ else }}
    {{ errorf "The %q shortcode was unable to find %q. See %s" $.Name . $.Position }}
  {{ end }}
{{ else }}
  {{ errorf "The %q shortcode requires a positional parameter indicating the relative path of the page resource to include. See %s" .Name .Position }}
{{ end }}

Then call it from content/leaf-bundle-1/index.md using the {{% %}} notation:

{{% include-page-resource "b.md"}}

In the shortcode above, note that the third line begins with {{- . Without this whitespace removal the result is rendered as an indented code block.

1 Like

also telated to this one:

he relpermalink doc mentioned by the op seems to be faulty (outdated)

Once you have captured a resource, use any of the applicable Resource methods to return a value or perform an action.

Thanks, this helps a lot. Indeed, documenting this behaviour would be great.

In my case, I’ll opt for HTML anchors towards the specific page resource within the leaf bundle’s index.md. Thanks!

Unless I am missing something, this isn’t going to help you. Page resources with a ResourceType of page are not published. That means they are not copied to the public directory when you build your site.

1 Like