Skip to content

Commit

Permalink
tpl/tplimpl: Improve embedded templates
Browse files Browse the repository at this point in the history
- Do not escape HTML entities
- Use consistent formatting for title and description with opengraph,
  schema, and twitter_cards
- Improve readability of twitter_cards

Closes #12418
  • Loading branch information
jmooring committed Apr 24, 2024
1 parent 2d75f53 commit 71b7282
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
6 changes: 3 additions & 3 deletions tpl/tplimpl/embedded/templates/opengraph.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<meta property="og:url" content="{{ .Permalink }}">

{{- with or site.Title site.Params.title | plainify }}
{{- with or site.Title site.Params.title | .RenderString | plainify | htmlUnescape }}
<meta property="og:site_name" content="{{ . }}">
{{- end }}

{{- with or .Title site.Title site.Params.title | plainify}}
{{- with or .Title site.Title site.Params.title | .RenderString | plainify | htmlUnescape }}
<meta property="og:title" content="{{ . }}">
{{- end }}

{{- with or .Description .Summary site.Params.description | plainify }}
{{- with or .Description .Summary site.Params.description | .RenderString | plainify | htmlUnescape }}
<meta property="og:description" content="{{ . }}">
{{- end }}

Expand Down
4 changes: 2 additions & 2 deletions tpl/tplimpl/embedded/templates/schema.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{- with or .Title site.Title }}
{{- with or .Title site.Title site.Params.title | .RenderString | plainify | htmlUnescape }}
<meta itemprop="name" content="{{ . }}">
{{- end }}

{{- with or .Description .Summary site.Params.Description }}
{{- with or .Description .Summary site.Params.description | .RenderString | plainify | htmlUnescape }}
<meta itemprop="description" content="{{ . }}">
{{- end }}

Expand Down
25 changes: 16 additions & 9 deletions tpl/tplimpl/embedded/templates/twitter_cards.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{{- $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 -}}
<meta name="twitter:card" content="summary">
{{- 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 -}}">
{{- $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 }}
<meta name="twitter:card" content="summary">
{{- end }}

{{- with or .Title site.Title site.Params.title | .RenderString | plainify | htmlUnescape }}
<meta name="twitter:title" content="{{ . }}">
{{- end }}

{{- with or .Description .Summary site.Params.description | .RenderString | plainify | htmlUnescape }}
<meta name="twitter:description" content="{{ . }}">
{{- end }}

{{- $twitterSite := "" }}
{{- with site.Params.social }}
Expand Down

0 comments on commit 71b7282

Please sign in to comment.