wjh18 / hugo-liftoff

Minimal blog/portfolio theme with a focus on content creation and SEO best practices. An ideal choice for technical users jump-starting a personal brand.
https://hugo-liftoff.netlify.app
MIT License
93 stars 27 forks source link

Bug - Feature image not working #30

Closed gellenburg closed 1 year ago

gellenburg commented 1 year ago

Describe the bug

Featured Images for a post aren't being rendered/ working.

To Reproduce Steps to reproduce the behavior:

  1. Add a feature image to the site:

image

    1. Add a feature_image = to a post:

image

  1. Render site. (I just launched hugo server.)
  2. View the source code:

image

Expected behavior I expected a featured image to be rendered into the page.

Screenshots See above.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context hugo server

wjh18 commented 1 year ago

It should show up automatically with that naming even without frontmatter parameters as it glob matches *feature*. But the frontmatter you have should work too. Are you not seeing it in your post at all or just not in SEO metadata like OG and Twitter cards? Have you tried clearing cache?

gellenburg commented 1 year ago

Sorry just saw your reply.

Are you not seeing it in your post at all or just not in SEO metadata like OG and Twitter cards?

Not seeing it at all.

Have you tried clearing cache?

Yes. Different browsers even. ;-)

This is the command string I'm using to render the site:

hugo server --buildDrafts --buildExpired --buildFuture --cleanDestinationDir --disableFastRender --disableLiveReload --forceSyncStatic --gc --ignoreCache --noHTTPCache --renderStaticToDisk --renderToDisk

And there is physically no featured image rendered out in the HTML that hugo generates.

wjh18 commented 1 year ago

No problem @gellenburg. After further investigation, I realized the issue is related to page bundles. Page bundle resources are only available in a directory with an index.md or _index.md file. Generally when using page bundles, especially in nested sections, the name of the post should be index.md instead of the title of the post.

To fix this, you could create a page bundle by adding an additional directory under 2023/08/ (e.g. 2023/08/name-of-post/ and use an index.md file for your post (instead of 01 - Signed the papers...) alongside the images in that directory. Alternatively, if you only expect to have a single post within 2023/08/ you could create the index.md there and it would be considered a leaf bundle. There are archetypes for creating these automatically within sections (see docs).

With an _index.md, that would make it a branch bundle which is more appropriate for sections. But generally a leaf bundle is what you want for individual posts, and a branch bundle is only necessary if you want to create a section page for that directory. I hope that makes sense. I don't have much insight into how you want to structure your posts so if more clarification is needed for your specific use case I'd be happy to provide it.

Not sure why I didn't see this previously, so apologies for that. I could've sworn I added support for featured images to fall back to global resources as well but I did not. If that were the case, you would be able to place the images in /assets/ instead of creating a page bundle for them. Perhaps that's something to consider supporting in the future.

gellenburg commented 1 year ago

To fix this, you could create a page bundle by adding an additional directory under 2023/08/ (e.g. 2023/08/name-of-post/ and use an index.md file for your post (instead of 01 - Signed the papers...) alongside the images in that directory.

That fixed it! Many thanks! I was just about ready to give up. :-) Appreciate your time and help.

wjh18 commented 1 year ago

Awesome, glad that helped.