From ed91cb76293411884cbe88793d8a3394ac72e95f Mon Sep 17 00:00:00 2001 From: Jimmy Cai Date: Sat, 12 Sep 2020 10:33:53 +0200 Subject: [PATCH] refactor(layouts): move layout HTML to baseof.html For better maintainability --- assets/scss/partials/layout/article.scss | 4 +- layouts/404.html | 16 ++---- layouts/_default/baseof.html | 10 +++- layouts/_default/list.html | 29 ++++------ layouts/_default/single.html | 41 ++++++-------- layouts/_default/term.html | 72 +++++++++++------------- layouts/index.html | 34 +++++------ layouts/page/archive.html | 62 +++++++++----------- layouts/page/single.html | 22 +++----- 9 files changed, 122 insertions(+), 168 deletions(-) diff --git a/assets/scss/partials/layout/article.scss b/assets/scss/partials/layout/article.scss index 23b8763..76e0fad 100644 --- a/assets/scss/partials/layout/article.scss +++ b/assets/scss/partials/layout/article.scss @@ -1,6 +1,6 @@ @import "variables.scss"; -.article-and-sidebar { +.keep-sidebar { @media (min-width: $on-phone) and (max-width: $on-tablet) { --main-top-padding: 50px; } @@ -13,7 +13,7 @@ } } - .left-sidebar { + &:not(.keep-sidebar) .left-sidebar { @media (max-width: $on-tablet) { display: none; } diff --git a/layouts/404.html b/layouts/404.html index d882c30..dd5e49d 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -1,13 +1,7 @@ -{{ define "body_class" }}2-column{{ end }} {{ define "main" }} -
- {{ partial "sidebar/left.html" . }} - -
-
-

{{ T "notFoundTitle" }}

-

{{ T "notFoundSubtitle" }}

-
-
-
+
+

{{ T "notFoundTitle" }}

+

{{ T "notFoundSubtitle" }}

+
+ {{ partialCached "footer/footer" . }} {{ end }} \ No newline at end of file diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 52e5df2..bf3d511 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,9 +1,13 @@ {{- partial "head/head.html" . -}} - -
- {{- block "main" . }}{{- end }} + +
+ {{ partial "sidebar/left.html" . }} +
+ {{- block "main" . }}{{- end }} +
+ {{- block "right-sidebar" . -}}{{ end }}
{{ partial "footer/script.html" . }} {{ partial "footer/style.html" . }} diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 54206c4..8bd33d0 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,24 +1,19 @@ -{{ define "body_class" }}3-column{{ end }} {{ define "main" }} -
- {{ partialCached "sidebar/left.html" . }} +
+

{{ .Title }}

+
-
-
-

{{ .Title }}

-
+
+ {{ range .Paginator.Pages }} + {{ partial "article-list/compact" . }} + {{ end }} +
-
- {{ range .Paginator.Pages }} - {{ partial "article-list/compact" . }} - {{ end }} -
+ {{- partial "pagination.html" . -}} - {{- partial "pagination.html" . -}} - - {{ partialCached "footer/footer" . }} -
+ {{ partialCached "footer/footer" . }} +{{ end }} +{{ define "right-sidebar" }} {{ partialCached "sidebar/right.html" . }} -
{{ end }} \ No newline at end of file diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 82013b3..aabeee7 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,30 +1,21 @@ -{{ define "body_class" }}2-column{{ end }} +{{ define "container-class" }}article-page with-toolbar{{ end }} {{ define "main" }} -
- {{ partial "sidebar/left.html" . }} - -
-
-
- - {{ (resources.Get "icons/back.svg").Content | safeHTML }} - Back - -
- - {{ partial "article/article.html" . }} - - {{ partial "article/components/related-contents" . }} - - {{ if or (not (isset .Params "comments")) (eq .Params.comments "true")}} - {{ partial "comments/include" . }} - {{ end }} - - {{ partialCached "footer/footer" . }} -
+
+ + {{ (resources.Get "icons/back.svg").Content | safeHTML }} + Back +
-
-{{- partial "article/components/photoswipe.html" . -}} + {{ partial "article/article.html" . }} + {{ partial "article/components/related-contents" . }} + + {{ if or (not (isset .Params "comments")) (eq .Params.comments "true")}} + {{ partial "comments/include" . }} + {{ end }} + + {{ partialCached "footer/footer" . }} + + {{- partial "article/components/photoswipe.html" . -}} {{ end }} \ No newline at end of file diff --git a/layouts/_default/term.html b/layouts/_default/term.html index 9bf62fe..0d0a35f 100644 --- a/layouts/_default/term.html +++ b/layouts/_default/term.html @@ -1,45 +1,37 @@ -{{ define "body_class" }}2-column{{ end }} {{ define "main" }} -
- {{ partial "sidebar/left.html" . }} - -
- -

{{ .Type | singularize | humanize }}

-
-
-

{{ len .Pages }} post{{ if gt (len .Pages) 1 }}s{{ end }}

-

{{ .Title }}

- {{ with .Params.description }} -

{{ . }}

- {{ end }} -
- - {{ $image := partial "helper/image" (dict "Context" . "Type" "taxonomy") }} - {{ if $image.exists }} -
- {{ if $image.resource }} - {{- $thumbnail := $image.resource.Fill "120x120" -}} - - {{ else }} - - {{ end }} -
+

{{ .Type | singularize | humanize }}

+
+
+

{{ len .Pages }} post{{ if gt (len .Pages) 1 }}s{{ end }}

+

{{ .Title }}

+ {{ with .Params.description }} +

{{ . }}

{{ end }}
- -
- {{ $v2 := where .Pages "Params.hidden" "!=" true }} - {{ $pag := .Paginate (.Pages) }} - {{ range $pag.Pages }} - {{ partial "article-list/compact" . }} - {{ end }} -
- - {{- partial "pagination.html" . -}} - {{ partialCached "footer/footer" . }} -
-
+ {{ $image := partial "helper/image" (dict "Context" . "Type" "taxonomy") }} + {{ if $image.exists }} +
+ {{ if $image.resource }} + {{- $thumbnail := $image.resource.Fill "120x120" -}} + + {{ else }} + + {{ end }} +
+ {{ end }} +
+ +
+ {{ $v2 := where .Pages "Params.hidden" "!=" true }} + {{ $pag := .Paginate (.Pages) }} + {{ range $pag.Pages }} + {{ partial "article-list/compact" . }} + {{ end }} +
+ + {{- partial "pagination.html" . -}} + + {{ partialCached "footer/footer" . }} {{ end }} \ No newline at end of file diff --git a/layouts/index.html b/layouts/index.html index f3559b3..1811bd2 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -1,25 +1,19 @@ -{{ define "body_class" }}3-column{{ end }} {{ define "main" }} -
- {{ partialCached "sidebar/left.html" . }} + {{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }} + {{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }} + {{ $filtered := ($pages | intersect $notHidden) }} + {{ $pag := .Paginate ($filtered) }} -
- {{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }} - {{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }} - {{ $filtered := ($pages | intersect $notHidden) }} - {{ $pag := .Paginate ($filtered) }} - -
- {{ range $index, $element := $pag.Pages }} - {{ partial "article-list/default" . }} - {{ end }} -
- - {{- partial "pagination.html" . -}} +
+ {{ range $index, $element := $pag.Pages }} + {{ partial "article-list/default" . }} + {{ end }} +
- {{ partialCached "footer/footer" . }} -
- + {{- partial "pagination.html" . -}} + {{ partialCached "footer/footer" . }} +{{ end }} + +{{ define "right-sidebar" }} {{ partialCached "sidebar/right.html" . }} -
{{ end }} \ No newline at end of file diff --git a/layouts/page/archive.html b/layouts/page/archive.html index 6751ff3..b68e40a 100644 --- a/layouts/page/archive.html +++ b/layouts/page/archive.html @@ -1,42 +1,34 @@ -{{ define "body_class" }}2-column{{ end }} +{{ define "body-class" }}template-archive{{ end }} {{ define "main" }} -
- - {{ partial "sidebar/left.html" . }} - -
- {{ $categories := ($.Site.GetPage "taxonomyTerm" "categories").Pages }} - {{ if $categories }} -
-

Categories

-
-
- {{ range $categories }} - {{ partial "article-list/tile" (dict "context" . "size" "250x150") }} - {{ end }} -
-
-
- {{ end }} - - {{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }} - {{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }} - {{ $filtered := ($pages | intersect $notHidden) }} - - {{ range $filtered.GroupByDate "2006" }} - {{ $id := lower (replace .Key " " "-") }} -
-

{{ .Key }}

-
- {{ range .Pages }} - {{ partial "article-list/compact" . }} + {{ $categories := ($.Site.GetPage "taxonomyTerm" "categories").Pages }} + {{ if $categories }} +
+

Categories

+
+
+ {{ range $categories }} + {{ partial "article-list/tile" (dict "context" . "size" "250x150") }} {{ end }}
- {{ end }} +
+ {{ end }} - {{ partialCached "footer/footer" . }} -
-
+ {{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }} + {{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }} + {{ $filtered := ($pages | intersect $notHidden) }} + {{ range $filtered.GroupByDate "2006" }} + {{ $id := lower (replace .Key " " "-") }} +
+

{{ .Key }}

+
+ {{ range .Pages }} + {{ partial "article-list/compact" . }} + {{ end }} +
+
+ {{ end }} + + {{ partialCached "footer/footer" . }} {{ end }} \ No newline at end of file diff --git a/layouts/page/single.html b/layouts/page/single.html index e5a1ed8..edf53fb 100644 --- a/layouts/page/single.html +++ b/layouts/page/single.html @@ -1,20 +1,12 @@ -{{ define "body_class" }}2-column{{ end }} +{{ define "body-class" }}article-page keep-sidebar{{ end }} {{ define "main" }} -
+ {{ partial "article/article.html" . }} - {{ partial "sidebar/left.html" . }} + {{ if or (not (isset .Params "comments")) (eq .Params.comments "true")}} + {{ partial "comments/include" . }} + {{ end }} -
- {{ partial "article/article.html" . }} - - {{ if or (not (isset .Params "comments")) (eq .Params.comments "true")}} - {{ partial "comments/include" . }} - {{ end }} - - {{ partialCached "footer/footer" . }} -
-
- -{{ partial "article/components/photoswipe" . }} + {{ partialCached "footer/footer" . }} + {{ partial "article/components/photoswipe" . }} {{ end }} \ No newline at end of file