Skip to content

Commit

Permalink
Merge pull request #165 from powerfulweb-fork/body-class
Browse files Browse the repository at this point in the history
fix: change body classes
  • Loading branch information
h-enk committed Sep 17, 2021
2 parents 3c8ba21 + e59422e commit 219b2b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
14 changes: 2 additions & 12 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
<!doctype html>
<html lang="{{ .Site.LanguageCode | default "en" }}">
{{ partial "head/head.html" . }}
{{ if eq .Kind "home" -}}
{{ .Scratch.Set "class" "home" -}}
{{ else if eq .Kind "404" -}}
{{ .Scratch.Set "class" "error404" -}}
{{ else if eq .Kind "page" -}}
{{ .Scratch.Set "class" .Type -}}
{{ .Scratch.Add "class" " single" -}}
{{ else -}}
{{ .Scratch.Set "class" .Type -}}
{{ .Scratch.Add "class" " list" -}}
{{ end -}}
<body class="{{ .Scratch.Get "class" }}">
{{- partial "head/body-class.html" . -}}
<body class="{{ delimit (.Scratch.Get "class") " " }}">
{{ if and .IsHome .Site.Params.alert }}
{{ partial "header/alert.html" . }}
{{ end }}
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 219b2b1

Please sign in to comment.