Skip to content

Commit

Permalink
fix: move body-class to partial
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-pwd committed Sep 16, 2021
1 parent b0dc0a7 commit 785380a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
25 changes: 1 addition & 24 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
<!doctype html>
<html lang="{{ .Site.LanguageCode | default "en" }}">
{{ partial "head/head.html" . }}

{{ $template := "" }}
{{ if or (eq .Kind "404") (eq .Kind "page") (eq .Kind "home")}}
{{ $template = "single" }}
{{ else if or (eq .Kind "section") (eq .Kind "taxonomy") (eq .Kind "term") -}}
{{ $template = "list" }}
{{ end -}}

{{ $name := "" }}
{{ if eq .Kind "taxonomy" }}
{{ $name = printf "taxonomy %s" .Data.Plural }}
{{ else if eq .Kind "term" }}
{{ $name = printf "term %s" .Section}}
{{ else if .Section }}
{{ $name = printf "section %s" .Section }}
{{ else if eq .Kind "page" }}
{{ $name = .File.ContentBaseName }}
{{ else if eq .Kind "home" }}
{{ $name = "home" }}
{{ else if eq .Kind "404" }}
{{ $name = "error404" }}
{{ end }}

{{ .Scratch.Set "class" (slice $template $name) -}}
{{- partial "head/body-class.html" -}}
<body class="{{ delimit (.Scratch.Get "class") " " }}">
{{ if and .IsHome .Site.Params.alert }}
{{ partial "header/alert.html" . }}
Expand Down
21 changes: 21 additions & 0 deletions layouts/partials/head/body-class.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- $template := "" -}}
{{- if or (eq .Kind "404") (eq .Kind "page") (eq .Kind "home") -}}
{{ $template = "single" -}}
{{- else if or (eq .Kind "section") (eq .Kind "taxonomy") (eq .Kind "term") -}}
{{ $template = "list" -}}
{{- end -}}
{{- $name := "" -}}
{{- if eq .Kind "taxonomy" -}}
{{- $name = printf "taxonomy %s" .Data.Plural -}}
{{- else if eq .Kind "term" -}}-
{{- $name = printf "term %s" .Section -}}
{{- else if .Section -}}
{{- $name = printf "section %s" .Section -}}
{{- else if eq .Kind "page" -}}
{{- $name = .File.ContentBaseName -}}
{{- else if eq .Kind "home" -}}
{{- $name = "home" -}}
{{- else if eq .Kind "404" -}}
{{- $name = "error404" -}}
{{- end -}}
{{- .Scratch.Set "class" (slice $template $name) -}}

0 comments on commit 785380a

Please sign in to comment.