I’ve started using the new “Page Resources” feature to organise my content (which is excellent!), but having some issues with uglyURLs.
Unfortunately I need to use ugly URLs and have the following in my config.toml
uglyURLs = true
canonifyURLs = true
My content is structured like this:
content
└── posts
├── article-title-1
│ ├── index.md
│ └── images
│ ├── article-image-01.jpg
│ └── article-image-02.jpg
└── article-title-2
├── index.md
└── images
├── article-image-03.jpg
└── article-image-04.jpg
When I use the {{ .Permalink }} variable on a single or list page template it does not display the correct full ugly URL.
I would expect the {{ .Permalink }} to output my post urls as:
/posts/article-title-1/index.html
/posts/article-title-2/index.html
But it’s outputting {{ .Permalink }} as:
/posts/article-title-1/
/posts/article-title-2/
This works fine in the hugo server preview but not when we deploy the site (where we need the full ugly urls for the links to work).
Any ideas what I might be doing wrong?
bep
January 16, 2018, 4:49pm
2
The “index.html” Permalink
has never (or, never say never) been ugly in Hugo. Maybe they should, that would be a breaking change and it is not on my “list of things to fix”.
1 Like
bep
January 16, 2018, 5:21pm
3
That said, thinking about it, I think they should be. This is probably needed for people serving their sites from disk. But you need to create an GitHub issue.
Thanks for the response @beb .
So I should just append the index.html to my Permalink
variable in my template like so
{{ .Permalink }}index.html
Have you any ideas how to handle a mix of content with single markdown posts and new “page resource” posts like so:
content
└── posts
├── article-title-1.md
├── article-title-2.md
├── article-title-3
│ ├── index.md
│ └── images
│ ├── article-image-01.jpg
│ └── article-image-02.jpg
└── article-title-4
├── index.md
└── images
├── article-image-03.jpg
└── article-image-04.jpg
Is there a way I could check in the template and append the index.html only when it’s required (for “page resources” type posts)?
bep
January 16, 2018, 6:21pm
5
You can do something like this (totally untested):
{{ $permalink := cond (strings.HasSuffix .Permalink "html") .Permalink (printf "%sindex.html" .Permalink)
But please also create a GitHub issue so we can have a look at a more permanent fix.
1 Like
Thanks for the temporary fix.
I’ve just created an issue on Github