chipzoller / hugo-clarity

A theme for Hugo based on VMware Clarity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

404 getting image from page bundle in post URL ending in .html

rasmusson opened this issue · comments

I have checked all the prerequisites below and I'm yet experiencing a problem

  • Read the README.md
  • Have the extended version of Hugo installed
  • Used the exampleSite's config.toml as a reference
  • I have included my repository link. Instead of pasting long snippets here.
    My source is currently not public

Describe the bug
Because of migration from a old blog I have have used the front matter parameter URL to set the URL of the post.
When I set the URL to be a path ending in ".html" the thumbnail and feature imaged can not be fetched.
The image src is pointing to "/11/verifying-signatures-with-opensaml.html/opensaml4-signing.jpg", while the image is actually directly under "/11" as a sibling to verifying-signatures-with-opensaml.html.
If I remove the .html ending the images resolves fine.

Avoid long-winded descriptions

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • Browser: Chrome 102

Hmm. Yes that makes sense what's going on, I'm not sure how to resolve it, though. What happens if you set the path to the image explicitly as /11/opensaml4-signing.jpg? The leading slash might tell Hugo to use that path directly rather than construct a relative URL.

It still looking for it relatively, path is now 2012/11/verifying-signatures-with-opensaml.html/2012/11/opensaml4-signing.jpg

OK, thanks for trying. Here's the issue and the fix if it's possible:

When using page bundles, Hugo Clarity constructs the URL for the image resources by taking the path for the page you're on and appending the image filename. So if the path is /blog/foo and the image is bar.jpg, the path to the image is /blog/foo/bar.jpg. As you've already discovered, this assumes the page's path is equivalent to a directory.

So in order to accommodate paths ending in .html, we'd have to evaluate the page's path, and if it contains a dot character (to make this work for things like migrating old .php paths, say) to instead use the parent dir of the page's path and append the image's filename to that. Theoretically that seems possible but I'm not sure what the template logic is to accomplish it.

Right. Maby use in to check for presens of . as a substring of the path?
{{ if in path "." }}

No, sorry there can be other dots in there. Perhaps a regex using findRE?

This also feels like something https://discourse.gohugo.io/t/how-to-determine-a-page-budle-branch-or-leaf/25089/3

There is also a page variable bundleType that might be of use.