Skip to content

Commit

Permalink
refactor: Make title.html partial more readable, fix title for taxono…
Browse files Browse the repository at this point in the history
…my pages (#187)

* refactor: Make title.html partial more readable, fix title for taxonomy pages

* fix: Search index does not respect Markdown in page titles

BREAKING CHANGE: Markdown in page titles will be processed now
  • Loading branch information
palant committed Jun 7, 2020
1 parent 1322fdd commit ea09a86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
7 changes: 4 additions & 3 deletions layouts/index.searchindex.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
{{- if gt $index 0 -}}
,
{{- end -}}
{{- $entry := dict "uri" $page.RelPermalink "title" $page.Title "content" ($page.Plain | htmlUnescape) -}}
{{- $rawTitle := (partial "utils/title.html" (dict "$" $ "title" $page.Title)).rawTitle -}}
{{- $entry := dict "uri" $page.RelPermalink "title" $rawTitle "content" ($page.Plain | htmlUnescape) -}}
{{- if $page.Params.subtitle -}}
{{- $subtitle := partial "utils/markdownify.html" (dict "$" $page "raw" $page.Params.subtitle "isContent" false) -}}
{{- $entry = merge $entry (dict "subtitle" ($subtitle | plainify)) -}}
{{- $entry = merge $entry (dict "subtitle" ($subtitle | plainify | htmlUnescape)) -}}
{{- end -}}
{{- if .Site.Params.displayPostDescription -}}
{{- $description := partial "utils/markdownify.html" (dict "$" $page "raw" $page.Description "isContent" false) -}}
{{- $entry = merge $entry (dict "description" ($description | plainify)) -}}
{{- $entry = merge $entry (dict "description" ($description | plainify | htmlUnescape)) -}}
{{- end -}}
{{- if .Site.Params.displayCategory -}}
{{- if eq .Site.Params.categoryBy "sections" -}}
Expand Down
23 changes: 11 additions & 12 deletions layouts/partials/utils/title.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
{{- $ := index . "$" -}}
{{- $rawTitle := .title -}}
{{- $htmlTitle := .title -}}
<!-- Home -->
{{- if eq $.Kind "home" -}}
{{- $rawTitle = $rawTitle | default $.Site.Title -}}
{{- $htmlTitle = $htmlTitle | default $.Site.Title -}}
<!-- Taxonomy -->
{{- else if eq $.Kind "taxonomyTerm" -}}
{{- $rawTitle = $rawTitle | default ($.Type | title) -}}
{{- $htmlTitle = $htmlTitle | default ($.Type | title) -}}
<!-- Taxonomy Term -->
{{- else if eq $.Kind "taxonomy" -}}
{{- $taxonomyTermTitle := $rawTitle | default $.Data.Term | default (delimit (last 1 (split (strings.TrimSuffix "/_index.md" $.Path) "/")) " ") -}}
{{- $taxonomyTermTitle := $htmlTitle | default $.Data.Term | default (delimit (last 1 (split (strings.TrimSuffix "/_index.md" $.Path) "/")) " ") -}}
{{- with $.Site.GetPage (printf "/%s" $.Data.Plural) -}}
{{- $rawTitle = printf "%s: %s" ($.Title | default ($.Type | title)) $taxonomyTermTitle -}}
{{- $htmlTitle = printf "%s: %s" (.Title | default (.Type | title)) $taxonomyTermTitle -}}
{{- end -}}
<!-- Section -->
{{- else if eq $.Kind "section" -}}
{{- $rawTitle = $rawTitle | default (delimit (last 1 (split (strings.TrimSuffix "/_index.md" $.Path) "/")) " ") -}}
<!-- Page -->
{{- else -}}
{{- $rawTitle = $rawTitle -}}
{{- $htmlTitle = $htmlTitle | default (delimit (last 1 (split (strings.TrimSuffix "/_index.md" $.Path) "/")) " ") -}}
{{- end -}}

{{- $htmlTitle := partial "utils/markdownify.html" (dict "$" $ "raw" $rawTitle "isContent" false) -}}
{{- $htmlTitle = partial "utils/markdownify.html" (dict "$" $ "raw" $htmlTitle "isContent" false) -}}

{{- $title := $htmlTitle -}}
{{- $rawTitle := $htmlTitle | plainify | htmlUnescape -}}

{{- $title := $rawTitle -}}
{{- if ne $.Kind "home" -}}
{{- $title = printf "%s | %s" $title $.Site.Title -}}
{{- end -}}

{{- return dict "rawTitle" ($htmlTitle | plainify | htmlUnescape) "title" ($title | plainify | htmlUnescape) "htmlTitle" $htmlTitle -}}
{{- return dict "rawTitle" $rawTitle "title" $title "htmlTitle" $htmlTitle -}}

0 comments on commit ea09a86

Please sign in to comment.