Skip to content

Commit

Permalink
🎉 Add open graph template & assets [WIP] (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinwilson authored Sep 28, 2023
2 parents a9717ca + 2155694 commit 23e0af2
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 0 deletions.
Binary file added assets/images/logos/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/opengraph/card-base-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/opengraph/card-base-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/opengraph/poppins-bold.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions layouts/partials/docs/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<meta name="Version" content="v0.1.0" />
<!-- favicon -->
{{ block "favicon" . }}{{ partialCached (printf "%s/%s" ($.Scratch.Get "pathName") "head/favicon.html") . }}{{ end }}
{{- partial (printf "%s/%s" ($.Scratch.Get "pathName") "head/opengraph") . }}
<!-- Dark Mode -->
{{ if eq .Site.Params.docs.darkMode true -}}
{{ $darkModeInit := resources.Get (printf "/%s/%s" ($.Scratch.Get "pathName") "js/darkmode-init.js") | js.Build | minify -}}
Expand Down
68 changes: 68 additions & 0 deletions layouts/partials/docs/head/get-featured-image.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{ $images := $.Resources.ByType "image" }}
{{ $featured := $images.GetMatch "*feature*" }}
{{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end }}
{{ if not $featured }}
{{ $featured = resources.Get "/opengraph/card-base-2.png" }}
{{ $font := resources.Get "/opengraph/poppins-bold.ttf" }}
{{ $descPadding := 0 }}

{{ $title := $.LinkTitle }}
{{ $sizeTitle := 80 }}

{{ if gt (len $title) 20 }}
{{ $sizeTitle = 70 }}
{{ end }}

{{ $textTitle := $title }}
{{ $textTitleOptions := dict
"color" "#2e2e2e"
"size" $sizeTitle
"lineSpacing" 10
"x" 65 "y" 180
"font" $font
}}

{{ $filters := slice (images.Text $textTitle $textTitleOptions) }}

{{ $logo := resources.Get "images/logos/logo.png" }}
{{ with $logo }}
{{ $logo = $logo.Resize "x60" }}
{{ $logoFilter := (images.Overlay $logo 65 110) }}
{{ $filters = $filters | append $logoFilter }}
{{ end }}

{{ if gt ($title | strings.RuneCount) 23 }}
{{ $descPadding = 100 }}
{{ end }}

{{ $description := $.Description }}
{{ with $description }}
{{ $textDesc := $description }}
{{ $textDescOptions := dict
"color" "#8e8e8e"
"size" 50
"lineSpacing" 10
"x" 65 "y" (add 290 $descPadding)
"font" $font
}}
{{ $descFilter := (images.Text $textDesc $textDescOptions) }}
{{ $filters = $filters | append $descFilter }}
{{ end }}

{{ $textSiteTitle := $.Site.Title }}
{{ with $textSiteTitle }}
{{ $textSiteTitleOptions := dict
"color" "#5e5e5e"
"size" 35
"lineSpacing" 10
"x" 65 "y" 550
"font" $font
}}
{{ $siteTitleFilter := (images.Text $textSiteTitle $textSiteTitleOptions)}}
{{ $filters = $filters | append $siteTitleFilter }}
{{ end }}

{{ $featured = $featured | images.Filter $filters }}
{{ end }}

{{ return $featured }}
45 changes: 45 additions & 0 deletions layouts/partials/docs/head/opengraph.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<meta property="og:title" content="{{ .Title }}" />
<meta property="og:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}" />
<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 := partial (printf "%s/%s" ($.Scratch.Get "pathName") "head/get-featured-image.html") . }}
{{- with $featured -}}
<meta property="og:image" content="{{ $featured.Permalink }}"/>
{{- else -}}
{{- with $.Site.Params.images }}<meta property="og:image" content="{{ index . 0 | absURL }}"/>{{ end -}}
{{- end -}}
{{- end -}}

{{- if .IsPage }}
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
<meta property="article:section" content="{{ .Section }}" />
{{ with .PublishDate }}<meta property="article:published_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }}
{{ with .Lastmod }}<meta property="article:modified_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }}
{{- end -}}

{{- with .Params.audio }}<meta property="og:audio" content="{{ . }}" />{{ end }}
{{- with .Params.locale }}<meta property="og:locale" content="{{ . }}" />{{ end }}
{{- with .Site.Params.title }}<meta property="og:site_name" content="{{ . }}" />{{ end }}
{{- with .Params.videos }}{{- range . }}
<meta property="og:video" content="{{ . | absURL }}" />
{{ end }}{{ end }}

{{- /* If it is part of a series, link to related articles */}}
{{- $permalink := .Permalink }}
{{- $siteSeries := .Site.Taxonomies.series }}
{{- if $siteSeries }}
{{ with .Params.series }}{{- range $name := . }}
{{- $series := index $siteSeries ($name | urlize) }}
{{- range $page := first 6 $series.Pages }}
{{- if ne $page.Permalink $permalink }}<meta property="og:see_also" content="{{ $page.Permalink }}" />{{ end }}
{{- end }}
{{ end }}{{ end }}
{{- end }}

{{- /* Facebook Page Admin ID for Domain Insights */}}
{{- with .Site.Social.facebook_admin }}<meta property="fb:admins" content="{{ . }}" />{{ end }}

0 comments on commit 23e0af2

Please sign in to comment.