---
`)
- b.WithContent("mypage.md", `---
+ b.WithContent("mypage/index.md", `---
title: My Page
-images: ["pageimg1.jpg", "pageimg2.jpg"]
+images: ["pageimg1.jpg", "pageimg2.jpg", "https://example.local/logo.png", "sample.jpg"]
date: 2021-02-26T18:02:00+01:00
lastmod: 2021-05-22T19:25:00+01:00
---
`)
b.WithSunset("content/mybundle/featured-sunset.jpg")
+ b.WithSunset("content/mypage/sample.jpg")
b.Build(BuildCfg{})
b.AssertFileContent("public/mybundle/index.html", `
-<meta name="twitter:image" content="https://example.org/mybundle/featured-sunset.jpg"/>
+<meta name="twitter:image" content="https://example.org/mybundle/featured-sunset.jpg" />
<meta name="twitter:title" content="My Bundle"/>
<meta property="og:title" content="My Bundle" />
<meta property="og:url" content="https://example.org/mybundle/" />
-<meta property="og:image" content="https://example.org/mybundle/featured-sunset.jpg"/>
+<meta property="og:image" content="https://example.org/mybundle/featured-sunset.jpg" />
<meta property="article:published_time" content="2021-02-26T18:02:00-01:00" />
<meta property="article:modified_time" content="2021-05-22T19:25:00-01:00" />
<meta itemprop="name" content="My Bundle">
-<meta itemprop="image" content="https://example.org/mybundle/featured-sunset.jpg">
+<meta itemprop="image" content="https://example.org/mybundle/featured-sunset.jpg" />
<meta itemprop="datePublished" content="2021-02-26T18:02:00-01:00" />
<meta itemprop="dateModified" content="2021-05-22T19:25:00-01:00" />
`)
b.AssertFileContent("public/mypage/index.html", `
-<meta name="twitter:image" content="https://example.org/pageimg1.jpg"/>
+<meta name="twitter:image" content="https://example.org/pageimg1.jpg" />
<meta property="og:image" content="https://example.org/pageimg1.jpg" />
<meta property="og:image" content="https://example.org/pageimg2.jpg" />
+<meta property="og:image" content="https://example.local/logo.png" />
+<meta property="og:image" content="https://example.org/mypage/sample.jpg" />
<meta property="article:published_time" content="2021-02-26T18:02:00+01:00" />
<meta property="article:modified_time" content="2021-05-22T19:25:00+01:00" />
-<meta itemprop="image" content="https://example.org/pageimg1.jpg">
-<meta itemprop="image" content="https://example.org/pageimg2.jpg">
+<meta itemprop="image" content="https://example.org/pageimg1.jpg" />
+<meta itemprop="image" content="https://example.org/pageimg2.jpg" />
+<meta itemprop="image" content="https://example.local/logo.png" />
+<meta itemprop="image" content="https://example.org/mypage/sample.jpg" />
<meta itemprop="datePublished" content="2021-02-26T18:02:00+01:00" />
<meta itemprop="dateModified" content="2021-05-22T19:25:00+01:00" />
`)
b.AssertFileContent("public/mysite/index.html", `
-<meta name="twitter:image" content="https://example.org/siteimg1.jpg"/>
-<meta property="og:image" content="https://example.org/siteimg1.jpg"/>
-<meta itemprop="image" content="https://example.org/siteimg1.jpg"/>
+<meta name="twitter:image" content="https://example.org/siteimg1.jpg" />
+<meta property="og:image" content="https://example.org/siteimg1.jpg" />
+<meta itemprop="image" content="https://example.org/siteimg1.jpg" />
`)
}
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
<meta property="og:url" content="{{ .Permalink }}" />
-{{- with $.Params.images -}}
-{{- range first 6 . }}<meta property="og:image" content="{{ . | absURL }}" />{{ end -}}
-{{- else -}}
-{{- $images := $.Resources.ByType "image" -}}
-{{- $featured := $images.GetMatch "*feature*" -}}
-{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
-{{- with $featured -}}
-<meta property="og:image" content="{{ $featured.Permalink }}"/>
-{{- else -}}
-{{- with $.Site.Params.images }}<meta property="og:image" content="{{ index . 0 | absURL }}"/>{{ end -}}
-{{- end -}}
+{{- $images := partial "_funcs/get-page-images" . -}}
+{{- range first 6 $images -}}
+ <meta property="og:image" content="{{ .Permalink }}" />
{{- end -}}
{{- if .IsPage }}
--- /dev/null
+{{- $imgs := slice }}
+{{- $imgParams := .Params.images }}
+{{- $resources := .Resources.ByType "image" -}}
+{{/* Find featured image resources if the images parameter is empty. */}}
+{{- if not $imgParams }}
+ {{- $featured := $resources.GetMatch "*feature*" -}}
+ {{- if not $featured }}{{ $featured = $resources.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
+ {{- with $featured }}
+ {{- $imgs = $imgs | append (dict
+ "Image" .
+ "RelPermalink" .RelPermalink
+ "Permalink" .Permalink) }}
+ {{- end }}
+{{- end }}
+{{/* Use the first one of site images as the fallback. */}}
+{{- if and (not $imgParams) (not $imgs) }}
+ {{- with site.Params.images }}
+ {{- $imgParams = first 1 . }}
+ {{- end }}
+{{- end }}
+{{/* Parse page's images parameter. */}}
+{{- range $imgParams }}
+ {{- $img := . }}
+ {{- $url := urls.Parse $img }}
+ {{- if eq $url.Scheme "" }}
+ {{/* Internal image. */}}
+ {{- with $resources.GetMatch $img -}}
+ {{/* Image resource. */}}
+ {{- $imgs = $imgs | append (dict
+ "Image" .
+ "RelPermalink" .RelPermalink
+ "Permalink" .Permalink) }}
+ {{- else }}
+ {{- $imgs = $imgs | append (dict
+ "RelPermalink" (relURL $img)
+ "Permalink" (absURL $img)
+ ) }}
+ {{- end }}
+ {{- else }}
+ {{/* External image */}}
+ {{- $imgs = $imgs | append (dict
+ "RelPermalink" $img
+ "Permalink" $img
+ ) }}
+ {{- end }}
+{{- end }}
+{{- return $imgs }}
{{ with .Lastmod }}<meta itemprop="dateModified" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end}}
<meta itemprop="wordCount" content="{{ .WordCount }}">
-{{- with $.Params.images -}}
-{{- range first 6 . -}}<meta itemprop="image" content="{{ . | absURL }}">{{ end -}}
-{{- else -}}
-{{- $images := $.Resources.ByType "image" -}}
-{{- $featured := $images.GetMatch "*feature*" -}}
-{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
-{{- with $featured -}}
-<meta itemprop="image" content="{{ $featured.Permalink }}">
-{{- else -}}
-{{- with $.Site.Params.images -}}<meta itemprop="image" content="{{ index . 0 | absURL }}"/>{{ end -}}
-{{- end -}}
+{{- $images := partial "_funcs/get-page-images" . -}}
+{{- range first 6 $images -}}
+ <meta itemprop="image" content="{{ .Permalink }}" />
{{- end -}}
<!-- Output all taxonomies as schema.org keywords -->
-{{- with $.Params.images -}}
-<meta name="twitter:card" content="summary_large_image"/>
-<meta name="twitter:image" content="{{ index . 0 | absURL }}"/>
-{{ else -}}
-{{- $images := $.Resources.ByType "image" -}}
-{{- $featured := $images.GetMatch "*feature*" -}}
-{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
-{{- with $featured -}}
-<meta name="twitter:card" content="summary_large_image"/>
-<meta name="twitter:image" content="{{ $featured.Permalink }}"/>
+{{- $images := partial "_funcs/get-page-images" . -}}
+{{- with index $images 0 -}}
+<meta name="twitter:card" content="summary_large_image" />
+<meta name="twitter:image" content="{{ .Permalink }}" />
{{- else -}}
-{{- with $.Site.Params.images -}}
-<meta name="twitter:card" content="summary_large_image"/>
-<meta name="twitter:image" content="{{ index . 0 | absURL }}"/>
-{{ else -}}
<meta name="twitter:card" content="summary"/>
{{- end -}}
-{{- end -}}
-{{- end }}
<meta name="twitter:title" content="{{ .Title }}"/>
<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end -}}"/>
return c, err
}
-//go:embed embedded/templates/*
+//go:embed all:embedded/templates/*
//go:embed embedded/templates/_default/*
//go:embed embedded/templates/_server/*
var embeddedTemplatesFs embed.FS
// For the render hooks and the server templates it does not make sense to preserve the
// double _internal double book-keeping,
// just add it if its now provided by the user.
- if !strings.Contains(path, "_default/_markup") && !strings.HasPrefix(name, "_server/") {
+ if !strings.Contains(path, "_default/_markup") && !strings.HasPrefix(name, "_server/") && !strings.HasPrefix(name, "partials/_funcs/") {
templateName = internalPathPrefix + name
}