tiroyo
March 29, 2024, 4:59pm
1
Hello, in Hugo partial header I want to have this code
<meta property="og:image" content="resized image 1200x630 url here...">
<meta property="twitter:image" content="resized image 1200x675 url here...">
Need to tell Hugo to check if the page param have cover:
image value if not then get the image from .Site.Params.coverImg.og
and resize images accordingly and add the url in the code above. How can I achieve this?
resources get is not working for me
image urls format used in the params:
# Site param
coverImg:
og: cafe-outside.jpg
# page param
cover: cafe-waterloo.jpg
tiroyo:
page param have cover:
In this case, where is the image located?
tiroyo:
.Site.Params.coverImg.og
In this case, where is the image located?
1 Like
tiroyo
March 29, 2024, 5:05pm
3
Hello, images are in the assets folder
/assets/images/cafe/cafe-outside.jpg
/assets/images/cafe/Waterloo/main/cafe-waterloo.jpg
Do you mean:
params:
coverImg:
og: cafe-outside.jpg
tiroyo
March 29, 2024, 5:10pm
5
I miss the point earlier, so the folder structure is like this
/config/_default/params.yaml/
# here are all the params and in here is
coverImg:
og: cafe/cafe-outside.jpg
assets/
āāā images/
āāā cafe/
āāā Waterloo/
ā āāā main/
ā āāā cafe-waterloo.jpg
āāā cafe-outside.jpg
params.yaml
coverImg:
og: images/cafe/Waterloo/main/cafe-waterloo.jpg
front matter
title: My Page
cover: images/cafe/cafe-outside.jpg
{{ with or (resources.Get .Params.cover) (resources.Get site.Params.coverImg.og) }}
{{ with .Fill "1200x630" }}
<meta property="og:image" content="{{ .RelPermalink }}">
{{ end }}
{{ with .Fill "1200x675" }}
<meta property="twitter:image" content="{{ .RelPermalink }}">
{{ end }}
{{ end }}
Also, I encourage you to use lowercase for all of your files and directories.
1 Like
system
Closed
March 31, 2024, 5:52pm
8
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.