Skip to content

Commit

Permalink
Generate page meta-description like Hugo
Browse files Browse the repository at this point in the history
  • Loading branch information
chalin committed Jul 9, 2022
1 parent 712e36e commit 02b2746
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
{{ .Site.Title -}}
{{ end -}}
</title>
{{ $desc := .Page.Description | default (.Page.Content | safeHTML | truncate 150) -}}
<meta name="description" content="{{ $desc }}">
<meta name="description" content="{{ template "partials/page-description.html" . }}">
{{ template "_internal/opengraph.html" . -}}
{{ template "_internal/schema.html" . -}}
{{ template "_internal/twitter_cards.html" . -}}
Expand Down
11 changes: 11 additions & 0 deletions layouts/partials/page-description.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ with .Description | plainify -}}
{{ . -}}
{{ else -}}
{{ if .IsPage -}}
{{ .Summary | plainify | chomp -}}
{{ else -}}
{{ with .Site.Params.description | plainify -}}
{{ . -}}
{{ end -}}
{{ end -}}
{{ end -}}

0 comments on commit 02b2746

Please sign in to comment.