{{- /* Open Graph image for link previews. The theme's head/meta.html writes og:image only for the "image" param; without it, this uses the first image in the page's Markdown, scaled down to at most 1200 pixels wide, with its alt text as og:image:alt. */ -}} {{- if not ($.Param "image") -}} {{- with findRESubmatch `!\[([^\]]*)\]\(\s*]+)` .RawContent 1 -}} {{- $alt := index . 0 1 -}} {{- $dest := index . 0 2 -}} {{- $url := "" -}} {{- $width := 0 -}} {{- $height := 0 -}} {{- $resource := false -}} {{- if findRE `^https?://` $dest -}} {{- $url = $dest -}} {{- else -}} {{- $resource = or ($.Resources.Get (strings.TrimPrefix "./" $dest)) (resources.Get $dest) -}} {{- end -}} {{- with $resource -}} {{- $image := . -}} {{- if and (eq .ResourceType "image") (ne .MediaType.SubType "svg") -}} {{- if gt .Width 1200 }}{{ $image = .Resize "1200x" }}{{ end -}} {{- $width = $image.Width -}} {{- $height = $image.Height -}} {{- end -}} {{- $url = $image.Permalink -}} {{- end -}} {{- with $url }} {{- with $width }} {{- end }} {{- with $alt }} {{- end }} {{- end -}} {{- end -}} {{- end -}}