Why i am not getting the absURL in head schema?

Hi there,

Added schema today to a website but cannot figure out what i am doing wrong. is this setup correct for expected value:

# Domain: example.com
# Post: Blog post 1
# Cover image: image1.png

├── content
│   └──── blog
│       └──── blog-post-1
│           ├── images
│           |   ├── image1.png
│           |   ├── image2.png
│           └──── index.md
|
├── layouts
│   └──── partials
│          └──── head.html

baseurl

baseURL: https://example.com/

frontmatter of blog-post-1

ogimage: image/image1.png

use of front matter value in partial head

"image": "{{ .Params.ogimage | absURL }}",

expected url

example.com/blog/images/image1.png

returned url:

example.com/image1.png

what i am doing wrong here?

thanks for taking the time to help

Both absURL and relURL consider the configured value of baseURL in your site’s config file. Given a baseURL set to https://example.com/hugo/ :

{{ “mystyle.css” | absURL }} → “https://example.com/hugo/mystyle.css
{{ “mystyle.css” | relURL }} → “/hugo/mystyle.css”

Suffice to say, your absURL is what you set as a base in your config.toml

hi @brilliantzen

since i am getting the valude from frontmatter i am expecting it to add the apropriate path after the base url. it supose to work like this i remember doing this way in past not sure what i am currently doing wrong. do you see everything good with this example?

With other words (already said above): absURL is a function that prepends the configured baseURL to the provided path as it is. It has no deeper “magic” that calculates any paths from your content structure in the background. Therefore your “returned url” is the “expected url”.

As far as I understand you use a Leaf Bundle. Therefore I would try something with resources,Get but ?.

I would be willing to test this if you would provide a repo or other running test environment.

structure

content
├── blog/
│   └── blog-post-1/
│       ├── images/
│       │   ├── image1.png
│       │   └── image2.png
│       └── index.md
└── _index.md

content/blog/blog-post-1/index.md

+++
title = 'Blog Post 1'
date = 2022-05-06T09:33:00-07:00
draft = false
ogimage = 'images/image1.png'  # You neglected to include the subdirectory
+++

template

{{ with .Resources.Get .Params.ogimage }}
  "image": "{{ .Permalink }}"
{{ end }}

result

"image": "https://example.org/blog/blog-post-1/images/image1.png"
1 Like

Thanks @jmooring

The above solution did the job. My confusion arises when a method works for a site.params doesn’t work for the page.params

# This works
<meta property="og:image" content="{{ .Site.Params.ogimage | absURL }}" />

# Doesn't works
<meta property="og:image" content="{{ .Page.Params.ogimage | absURL }}" />

# Doesn't works
<meta property="og:image" content="{{ .Params.ogimage | absURL }}" />

# Doesn't works
{{ with .Params.ogimage }} 
  <meta property="og:image" content="{{ . | absURL }}" />
{{ end }}

Thank you for taking the time to assist me in my efforts to solve this mystery.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.