From e17a095ce26917954b7667614a4d158e82d7508f Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Thu, 1 Mar 2018 12:32:58 -0500 Subject: [PATCH] Add opengraph meta-data to doc site pages --- doc/ox-hugo-manual.org | 7 +- .../layouts/partials/head.html | 4 + .../layouts/partials/opengraph.html | 92 +++++++++++++++++++ .../layouts/partials/summary_minus_toc.html | 20 ++++ .../layouts/partials/twitter_cards.html | 40 ++++++++ 5 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 doc/themes/hugo-alabaster-theme/layouts/partials/opengraph.html create mode 100644 doc/themes/hugo-alabaster-theme/layouts/partials/summary_minus_toc.html create mode 100644 doc/themes/hugo-alabaster-theme/layouts/partials/twitter_cards.html diff --git a/doc/ox-hugo-manual.org b/doc/ox-hugo-manual.org index e1687e2..2f1af08 100644 --- a/doc/ox-hugo-manual.org +++ b/doc/ox-hugo-manual.org @@ -1811,9 +1811,10 @@ for writing your posts in Org, there are examples for both in the :PROPERTIES: :EXPORT_FILE_NAME: replace-front-matter-keys :END: -This is a =ox-hugo=-unique feature that allows you to -replace/substitute any front-matter key name to accommodate for your -favorite Hugo theme. +This is a =ox-hugo=-unique feature that allows you to replace any +front-matter key name to accommodate for your favorite Hugo theme. + +#+hugo: more The syntax is: diff --git a/doc/themes/hugo-alabaster-theme/layouts/partials/head.html b/doc/themes/hugo-alabaster-theme/layouts/partials/head.html index 8806ade..b428b4f 100644 --- a/doc/themes/hugo-alabaster-theme/layouts/partials/head.html +++ b/doc/themes/hugo-alabaster-theme/layouts/partials/head.html @@ -38,4 +38,8 @@ {{ with .Params.mathjax }} {{ partial "mathjax.html" }} {{ end }} + + + {{ partial "opengraph.html" . }} + {{ partial "twitter_cards.html" . }} diff --git a/doc/themes/hugo-alabaster-theme/layouts/partials/opengraph.html b/doc/themes/hugo-alabaster-theme/layouts/partials/opengraph.html new file mode 100644 index 0000000..881c386 --- /dev/null +++ b/doc/themes/hugo-alabaster-theme/layouts/partials/opengraph.html @@ -0,0 +1,92 @@ +{{ $permalink := .Permalink }} + + + + +{{ with .Params.images }} + {{ range first 6 . }} + {{ $image := . }} + {{ $image_link_absolute := (findRE "^/" $image) }} + {{ if $image_link_absolute }} + + {{ else }} + + {{ end }} + {{ end }} +{{ end }} +{{ if .IsPage }} + {{ if not .PublishDate.IsZero }} + + {{ else if not .Date.IsZero }} + + {{ end }} + {{ if not .Lastmod.IsZero }} + + {{ end }} +{{ else }} + {{ if not .Date.IsZero }} + + {{ end }} +{{ end }} +{{ with .Params.audio }} + {{ $audio := . }} + {{ $audio_link_absolute := (findRE "^/" $audio) }} + {{ if $audio_link_absolute }} + + {{ else }} + + {{ end }} +{{ end }} +{{ with .Params.locale }} + +{{ end }} +{{ with .Site.Params.title }} + +{{ end }} +{{ with .Params.videos }} + {{ range . }} + {{ $video := . }} + {{ $video_link_absolute := (findRE "^/" $video) }} + {{ if $video_link_absolute }} + + {{ else }} + + {{ end }} + {{ end }} +{{ end }} + +{{ $siteSeries := .Site.Taxonomies.series }} +{{ if $siteSeries }} + {{ with .Params.series }} + {{ range $name := . }} + {{ $series := index $siteSeries $name }} + {{ range $page := first 6 $series.Pages }} + {{ if ne $page.Permalink $permalink }} + + {{ end }} + {{ end }} + {{ end }} + {{ end }} +{{ end }} + +{{ if .IsPage }} + {{ range .Site.Authors }} + {{ with .Social.facebook }} + + {{ end }} + {{ with .Site.Social.facebook }} + + {{ end }} + + {{ with .Params.tags }} + {{ range first 6 . }} + + {{ end }} + {{ end }} + {{ end }} +{{ end }} + +{{ with .Site.Social.facebook_admin }} + +{{ end }} diff --git a/doc/themes/hugo-alabaster-theme/layouts/partials/summary_minus_toc.html b/doc/themes/hugo-alabaster-theme/layouts/partials/summary_minus_toc.html new file mode 100644 index 0000000..6ec6447 --- /dev/null +++ b/doc/themes/hugo-alabaster-theme/layouts/partials/summary_minus_toc.html @@ -0,0 +1,20 @@ +{{- $summary_has_org_toc := substr .Content 0 30 | findRE "[\".]ox-hugo-toc" -}} +{{- if $summary_has_org_toc -}} + {{- $content_splits := split .RawContent "" -}} + + {{- $summary_raw := index $content_splits 1 -}} + {{- $summary_splits := split $summary_raw "" -}} + {{- if eq (len $summary_splits) 2 -}} + {{- index $summary_splits 0 | markdownify -}} + {{- else -}} + {{- $summary_raw | markdownify | truncate 300 -}} + {{- end -}} + +{{- else -}} + {{- with .Description -}} + {{- . | markdownify | printf "

%s

" | safeHTML -}} + {{- else -}} + {{- .Summary | printf "

%s

" | safeHTML -}} + {{- end -}} +{{- end -}} diff --git a/doc/themes/hugo-alabaster-theme/layouts/partials/twitter_cards.html b/doc/themes/hugo-alabaster-theme/layouts/partials/twitter_cards.html new file mode 100644 index 0000000..ca3127e --- /dev/null +++ b/doc/themes/hugo-alabaster-theme/layouts/partials/twitter_cards.html @@ -0,0 +1,40 @@ +{{ $permalink := .Permalink }} +{{- with $.Params.images -}} + + + {{- $image := (index . 0) -}} + {{- $image_link_absolute := (findRE "^/" $image) -}} + {{- if $image_link_absolute -}} + + {{- else -}} + + {{- end -}} +{{ else -}} + {{- $images := $.Resources.ByType "image" -}} + {{- $featured := $images.GetMatch "*feature*" -}} + {{- $featured := cond (ne $featured nil) $featured ($images.GetMatch "{*cover*,*thumbnail*}") -}} + {{- with $featured -}} + + + {{- else -}} + {{- with $.Site.Params.images -}} + + {{- $image := (index . 0) -}} + {{- $image_link_absolute := (findRE "^/" $image) -}} + {{- if $image_link_absolute -}} + + {{- else -}} + + {{- end -}} + {{ else -}} + + {{- end -}} + {{- end -}} +{{- end }} + + +{{ with .Site.Social.twitter -}} + + +{{ end -}}