Hugo Pass Shortcode Variables From Pages Into sitemap.xml

Viewed 149

Currently Hugo's built-in sitemap generator only creates two field attributes for images -- image:loc and image:license. Unfortunately this does not tell Google Bots much about the images context for SEO. The fields, image:title & image:caption at minimum is needed with the other two for best practices; Otherwise it's basically dead XML code.

I am working on a site that is image-content driven and since a short code is given in each page labeled as "Featured-Image" and contains the needed variables where I would like to extract/pass into the sitemap.

Here is an example of the shortcode within a page.md:

{{< 
    featured-image 
    name          ="THE_IMAGE_NAME.jpg"
    featuredTitle ="THE_IMAGE_TITLE"
    location      ="THE_IMAGE_LOCATION"
    alt           ="THE_IMAGE_ALT/CAPTION"
>}}

Within the sitemap.xml is what I would like to do:

    {{ $license := .Site.Params.schema.license }}
    {{ range .Data.Pages }}
    ...
      {{ range $i := .Resources.ByType "image" }}

      // Below is the additional data I am wanting to get from the pages' 
      // shortcode named "featured-image" -- But How Do I Get It?.

      {{ $caption   := .Get "alt" }}
      {{ $location  := .Get "location"}}
      {{ $title     := .Get "featuredTitle"}}

      <image:image>
         <image:loc>{{ $i.Permalink }}</image:loc>
         <image:license>{{ $license }}</image:license>

          // Below are the additional attributes needed:

          <image:geo_location>{{ $location }}</image:geo_location>
          <image:title>{{ $title }}</image:title>
          <image:caption>{{ $caption }}</image:caption>
      </image:image>
    ...
0 Answers
Related