目前 Hugo 的内置站点地图生成器只为图像创建两个字段属性 -image:loc
和image:license
. 不幸的是,这并没有告诉 Google Bots 多少关于 SEO 的图像上下文。字段,image:title
至少image:caption
需要其他两个字段以获得最佳实践;否则它基本上是死的 XML 代码。
我正在一个图像内容驱动的网站上工作,因为在每个标记为“特色图像”的页面中都给出了一个短代码,并且包含我想要提取/传递到站点地图的所需变量。
这是 a 中的简码示例page.md
:
{{<
featured-image
name ="THE_IMAGE_NAME.jpg"
featuredTitle ="THE_IMAGE_TITLE"
location ="THE_IMAGE_LOCATION"
alt ="THE_IMAGE_ALT/CAPTION"
>}}
在里面sitemap.xml
是我想做的事情:
{{ $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>
...