Overcoming HTML File Exclusion in Leaf Page Bundles

I have the below directory structure in my hugo content directory:

content/
├── 20240806115757
│   └── index.md
├── 20240807121149
│   └── index.md
└── 20240828152118
    ├── 20240828152118.html
    ├── 20240828152118.jpg
    └── index.md

I’m using leaf page bundles, and any attachments I include under the subfolders are processed published (I can see them in the public directory), but html files are ignored.

Is there a way to tell Hugo to treat any HTML file in the content directory just like any other attachment (image, pdf etc)?

Thanks in advance

Page resources of type page (.md, .adoc, .pdc, .html, .rst, .org) are not published. When you place these files in a leaf bundle, you can capture them with .Resources.Get to insert content. A typical use case is snippet inclusion.

If you want to blindly copy an HTML file when publishing the site, you can place it in the static directory using the desired path. For example:

content/
├── 20240806115757/
│   └── index.md
├── 20240807121149/
│   └── index.md
├── 20240828152118/
│   ├── 20240828152118.jpg
│   └── index.md
└── _index.md
static/
├── 20240828152118/
│   └── 20240828152118.html
└── favicon.ico

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

Files with resource type page include content written in Markdown, HTML, AsciiDoc, Pandoc, reStructuredText, and Emacs Org Mode. In a leaf bundle, excluding the index file, these files are only accessible as page resources. In a branch bundle, these files are only accessible as content pages.

Another approach is to capture and publish each resource of type page. For example, you could place something like this in a single page layout:

{{ range .Resources.ByType "page" }}
  {{ with resources.FromString (print $.RelPermalink .Name) .Content }}
    {{ .Publish }}
  {{ end }}
{{ end }}

The above won’t work with uglyURLs = true in your site configuration.

If you don’t want to publish these resources on every page, either trigger the above with a boolean front matter value, or create a shortcode using a similar construct.

2 Likes

Thanks for explaining so clearly @jmooring much appreciated!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.