Skip to content

Improve publishing path when the output format "path" is set #13829

@jmooring

Description

@jmooring

This isn't anything new. The behavior described below is present in v0.73.0 and later, and probably well before that. Anything we do here will be a breaking change, limited to those sites where path is specified in one or more of its output format definitions.

Important

Since this change is going to break some eggs, I strongly suggest we address #4428 and #7497 at the same time.


Our documentation describes the output format path setting as follows1:

The published file’s directory path, relative to the root of the publish directory. If not specified, the file will be published using its content path.

However, the actual behavior is very different.

Consider this site configuration:

uglyURLs = false

[outputFormats.print]
isPlainText = true
mediaType = 'text/plain'
path = 'print'

[outputs]
home = ['html','print']
page = ['html','print']
section = ['html','print']
taxonomy = ['html','print']
term = ['html','print']

[taxonomies]
tag = 'tags'

And this content structure:

content/
├── s1/
│   ├── _index.md
│   └── p1.md
├── tags/
│   ├── red/
│   │   └── _index.md
│   └── _index.md
└── _index.md

When you build the site, the URL pattern of the "print" output format depends on the page kind, which doesn't make sense:

page kind content path published path
page content/s1/p1.md public/print/s1/p1/index.txt
section content/s1/_index.md public/s1/print/index.txt
taxonomy content/tags/_index.md public/tags/print/index.txt
term content/tags/red/_index.md public/tags/red/print/index.txt
home content/_index.md public/print/index.txt

Or to look at the entire structure:

tree
public/
├── print/
│   ├── s1/
│   │   └── p1/
│   │       └── index.txt
│   └── index.txt
├── s1/
│   ├── p1/
│   │   └── index.html
│   ├── print/
│   │   └── index.txt
│   └── index.html
├── tags/
│   ├── print/
│   │   └── index.txt
│   ├── red/
│   │   ├── print/
│   │   │   └── index.txt
│   │   └── index.html
│   └── index.html
└── index.html

My expectation is that the URL pattern would be the same2 regardless of page kind.

Test site that matches the above:

git clone --single-branch -b hugo-github-issue-13829 https://github.com/jmooring/hugo-testing hugo-github-issue-13829
cd hugo-github-issue-13829
rm -rf public/ && hugo && tree public

We need test cases with and without uglyURLs enabled.

References:

Footnotes

  1. This could use some fine tuning, perhaps: "The initial directory segment for the published file. This path is relative to the root of your publication directory. If omitted, Hugo will use the file's original content path for publishing."

  2. It should match the existing documentation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions