I’m trying to configure the metadata for my website in the front matter of my posts, but it seems to not be being implemented, and I can’t really figure out what to do.
A similar question has been asked previously, I followed the solution for that and was able to get a single OpenGraph implemented site-wide (so Hugo’s drawing from my config file). I then followed the instructions to add OpenGraph info into my front matter, but this isn’t being utilised. Similarly, I’ve noticed that pages outside of my website’s homepage aren’t being titled in my browser’s tabs: so for instance, if I navigate to a blog post then instead we see the full URL rather than the page title. It seems like Hugo’s having a difficult time extracting the relevant bits of data from my front matter and then using that to build my site, but I’m really not sure what the problem is - I’ve played around with various solutions given here for similar problems but to no avail.
So your code {{ with .Resources.ByType "image" }}{{ range . | first 1 }}{{ .Name | replaceRE ".jpg" "" | humanize | title }}{{ end }}{{ end }}{{ end }} from partial head.html returns a blank string.for this post.
You have to be sure it returns “something”.
For the pages outside of my website’s aren’t being titled in my browser’s tabs this makes no sense to me if it is outside your web site.
Oops, sorry, typo, I meant pages outside of my website’s homepage. So the home page has a title in my tab whereas the page for a post or anywhere else on the website simply has the raw URL as the browser’s tab title.
<title>{{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ with .Resources.ByType "image" }}{{ range . | first 1 }}{{ .Name | replaceRE ".jpg" "" | humanize | title }}{{ end }}{{ end }}{{ end }}</title>
That’s excellent, thank you. I’ve managed to fix the problem with tab titles! Although, my issues with metadata remain - there being a sitewide OpenGraph preview rather than specific previews for individual posts.
I think I see my issue, I need to mimic what’s done with the page titles i.e.: extend the code to use any descriptions for the page if they are present, {{else}} just use the “generic” website OpenGraph in my head.html file.