Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/reuixiy/hugo-theme-meme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorreuixiy <reuixiy@gmail.com>2020-06-12 06:45:07 +0300
committerreuixiy <reuixiy@gmail.com>2020-06-12 06:45:07 +0300
commit0c2f6c0e8afa077cbbe12318accd10122427b33a (patch)
tree84b352e75290f3ff4daf9fb10a1be28350596bd4 /layouts
parent6f3aebab7ebaeb52bcf564efee04745febc5bc87 (diff)
refactor: use semantic HTML for tree posts
Fixed #197
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/pages/tree-categories.html89
-rw-r--r--layouts/partials/pages/tree-sections.html70
-rw-r--r--layouts/partials/utils/limit-tree-posts.html26
-rw-r--r--layouts/partials/utils/tree-sections.html5
4 files changed, 129 insertions, 61 deletions
diff --git a/layouts/partials/pages/tree-categories.html b/layouts/partials/pages/tree-categories.html
index 8311a77..26a64bd 100644
--- a/layouts/partials/pages/tree-categories.html
+++ b/layouts/partials/pages/tree-categories.html
@@ -17,44 +17,75 @@
{{ end }}
{{ end }}
{{ $categories := uniq (.Scratch.Get "categories") | sort }}
- {{ range $categories }}
- {{ $categoryTerms := (split (strings.TrimPrefix "/" .) "/") }}
- {{ $depth := (len $categoryTerms) }}
- {{ $padding := (mul (mul $depth 2) 1.2) }}
- {{ $lastTerm := (delimit (last 1 $categoryTerms) " ") }}
- {{ $url := urls.Parse $lastTerm }}
- {{ $path := $url.Path }}
- {{ $linkTarget := "" }}
- {{ with $.Site.GetPage (printf `/categories/%s` $path) }}
- {{ $linkTarget = . }}
- <p style="padding-left: {{ $padding }}em">
+
+ <ul class="list-categories">
+ {{ range $index, $value := $categories }}
+ {{ $categoryTerms := (split (strings.TrimPrefix "/" .) "/") }}
+ {{ $depth := (len $categoryTerms) }}
+ {{ $lastTerm := (delimit (last 1 $categoryTerms) " ") }}
+ {{ $url := urls.Parse $lastTerm }}
+ {{ $path := $url.Path }}
+
+ {{ with $.Site.GetPage (printf `/categories/%s` $path) }}
+ {{ $linkTarget := . }}
+
+ {{ $depthPrev := 0 }}
+ {{ if ge $index 1 }}
+ {{ $categoryPrev := index $categories (sub $index 1) }}
+ {{ $depthPrev = len (split (strings.TrimPrefix "/" $categoryPrev) "/") }}
+ {{ end }}
+
+ {{ $depthNext := 0 }}
+ {{ if lt $index (sub (len $categories) 1) }}
+ {{ $categoryNext := index $categories (add $index 1) }}
+ {{ $depthNext = len (split (strings.TrimPrefix "/" $categoryNext) "/") }}
+ {{ end }}
+
+ {{ if or (le $depth $depthPrev) (eq $index 0) }}
+ <li>
+ {{ end }}
+ {{ if and (gt $depth $depthPrev) (ne $index 0) }}
+ <ul class="list-categories"><li>
+ {{ end }}
+
<a href="{{ .RelPermalink }}" class="category-item">{{ .LinkTitle | default .Data.Term | default $path }}</a>
{{ if $.Site.Params.displayPostsCount }}
<span class="category-count">{{ printf "(%d)" (len .Data.category) }}</span>
{{ end }}
- </p>
- {{ end }}
- {{ if $.Site.Params.displayPosts }}
- {{ $context := . }}
- {{ $.Scratch.Delete "pages" }}
- {{ range $.Site.RegularPages }}
- {{ $page := . }}
- {{ with .Param "categories" }}
- {{ $.Scratch.Delete "category" }}
- {{ range . }}
- {{ $category := (printf `/%s` (. | urlize)) }}
- {{ $.Scratch.Add "category" $category }}
+
+ {{ if $.Site.Params.displayPosts }}
+ {{ $.Scratch.Delete "pages" }}
+ {{ range $.Site.RegularPages }}
+ {{ $page := . }}
+ {{ with .Param "categories" }}
+ {{ $.Scratch.Delete "category" }}
+ {{ range . }}
+ {{ $category := (printf `/%s` (. | urlize)) }}
+ {{ $.Scratch.Add "category" $category }}
+ {{ end }}
+ {{ $category := $.Scratch.Get "category" }}
+ {{ if eq $value $category }}
+ {{ $.Scratch.Add "pages" (slice $page) }}
+ {{ end }}
+ {{ end }}
{{ end }}
- {{ $category := $.Scratch.Get "category" }}
- {{ if eq $context $category }}
- {{ $.Scratch.Add "pages" (slice $page) }}
+ {{ $pages := $.Scratch.Get "pages" }}
+ {{ partial "utils/limit-tree-posts.html" (dict "$" $ "pages" $pages "linkTarget" $linkTarget) }}
+ {{ end }}
+
+ {{ if and (gt $depth $depthNext) (ne $index (sub (len $categories) 1)) }}
+ {{ range seq (sub $depth $depthNext) }}
+ {{ if le . (sub $depth $depthNext) }}
+ </li></ul>
+ {{ end }}
{{ end }}
{{ end }}
+ {{ if ge $depth $depthNext }}
+ </li>
+ {{ end }}
{{ end }}
- {{ $pages := $.Scratch.Get "pages" }}
- {{ partial "utils/limit-tree-posts.html" (dict "$" $ "pages" $pages "linkTarget" $linkTarget "padding" $padding) }}
{{ end }}
- {{ end }}
+ </ul>
</div>
</div>
</div>
diff --git a/layouts/partials/pages/tree-sections.html b/layouts/partials/pages/tree-sections.html
index d9b5f9e..5c5d279 100644
--- a/layouts/partials/pages/tree-sections.html
+++ b/layouts/partials/pages/tree-sections.html
@@ -5,14 +5,36 @@
<h1 class="list-title">{{ .Title | default (.Type | title) }}</h1>
{{ end }}
<div class="tree">
- {{ partial "utils/tree-sections.html" . }}
- {{ $pages := (.Scratch.Get "pages") }}
- {{ range $page, $name := $pages }}
- {{ $depth := (len (split (strings.TrimPrefix "/" $page) "/")) }}
- {{ with $.Site.GetPage $page }}
- {{ $linkTarget := . }}
- {{ $padding := (mul (mul $depth 2) 1.2) }}
- <p style="padding-left: {{ $padding }}em">
+ <ul class="list-categories">
+ {{ partial "utils/tree-sections.html" . }}
+ {{ $sections := .Scratch.Get "sections" }}
+ {{ $pages := .Scratch.Get "pages" }}
+ {{ range $index, $page := $pages }}
+ {{ $depth := (len (split (strings.TrimPrefix "/" $page) "/")) }}
+
+ {{ with $.Site.GetPage $page }}
+ {{ $linkTarget := . }}
+
+ {{ $depthPrev := 0 }}
+ {{ if ge $index 1 }}
+ {{ $pagePrev := index $pages (sub $index 1) }}
+ {{ $depthPrev = len (split (strings.TrimPrefix "/" $pagePrev) "/") }}
+ {{ end }}
+
+ {{ $depthNext := 0 }}
+ {{ if lt $index (sub (len $pages) 1) }}
+ {{ $pageNext := index $pages (add $index 1) }}
+ {{ $depthNext = len (split (strings.TrimPrefix "/" $pageNext) "/") }}
+ {{ end }}
+
+ {{ if or (le $depth $depthPrev) (eq $index 0) }}
+ <li>
+ {{ end }}
+ {{ if and (gt $depth $depthPrev) (ne $index 0) }}
+ <ul class="list-categories"><li>
+ {{ end }}
+
+ {{ $name := index $sections $index }}
<a href="{{ .RelPermalink }}" class="category-item">{{ .LinkTitle | default $name }}</a>
{{ if $.Site.Params.displayPostsCount }}
{{ $sectionPage := .CurrentSection }}
@@ -25,20 +47,32 @@
{{ $pages := $.Scratch.Get "pages" }}
<span class="category-count">{{ printf "(%d)" (len $pages) }}</span>
{{ end }}
- </p>
- {{ if $.Site.Params.displayPosts }}
- {{ $sectionPage := .CurrentSection }}
- {{ $.Scratch.Delete "pages" }}
- {{ range $.Site.RegularPages }}
- {{ if (.InSection $sectionPage) }}
- {{ $.Scratch.Add "pages" (slice .) }}
+
+ {{ if $.Site.Params.displayPosts }}
+ {{ $sectionPage := .CurrentSection }}
+ {{ $.Scratch.Delete "pages" }}
+ {{ range $.Site.RegularPages }}
+ {{ if (.InSection $sectionPage) }}
+ {{ $.Scratch.Add "pages" (slice .) }}
+ {{ end }}
+ {{ end }}
+ {{ $pages := $.Scratch.Get "pages" }}
+ {{ partial "utils/limit-tree-posts.html" (dict "$" $ "pages" $pages "linkTarget" $linkTarget) }}
+ {{ end }}
+
+ {{ if and (gt $depth $depthNext) (ne $index (sub (len $pages) 1)) }}
+ {{ range seq (sub $depth $depthNext) }}
+ {{ if le . (sub $depth $depthNext) }}
+ </li></ul>
+ {{ end }}
{{ end }}
{{ end }}
- {{ $pages := $.Scratch.Get "pages" }}
- {{ partial "utils/limit-tree-posts.html" (dict "$" $ "pages" $pages "linkTarget" $linkTarget "padding" $padding) }}
+ {{ if ge $depth $depthNext }}
+ </li>
+ {{ end }}
{{ end }}
{{ end }}
- {{ end }}
+ </ul>
</div>
</div>
</div>
diff --git a/layouts/partials/utils/limit-tree-posts.html b/layouts/partials/utils/limit-tree-posts.html
index 6d1ea57..1254d27 100644
--- a/layouts/partials/utils/limit-tree-posts.html
+++ b/layouts/partials/utils/limit-tree-posts.html
@@ -1,7 +1,6 @@
{{- $ := index . "$" -}}
{{- $pages := .pages -}}
{{- $linkTarget := .linkTarget -}}
-{{- $padding := .padding -}}
{{ with $pages }}
{{ $rawPages := . }}
@@ -12,16 +11,19 @@
{{ if ge $limit 0 }}
{{ $pages = $pages | first $limit -}}
{{ end }}
- {{ range $pages }}
- <p style="padding-left: {{ add $padding (mul 2 1.2) }}em">
- <a href="{{ .RelPermalink }}" class="category-post">{{ (partial "utils/title.html" (dict "$" . "title" .LinkTitle)).htmlTitle }}</a>
- </p>
- {{ end }}
- {{ if and (gt $limit 0) (gt (len $rawPages) $limit) }}
- {{ with $linkTarget }}
- <p style="padding-left: {{ add $padding (mul 2 1.2) }}em">
- <a href="{{ $linkTarget.RelPermalink }}" class="category-post">{{ i18n "readMore" }} »</a>
- </p>
+
+ <ul class="list-posts">
+ {{ range $pages }}
+ <li>
+ <a href="{{ .RelPermalink }}" class="category-post">{{ (partial "utils/title.html" (dict "$" . "title" .LinkTitle)).htmlTitle }}</a>
+ </li>
{{ end }}
- {{ end }}
+ {{ if and (gt $limit 0) (gt (len $rawPages) $limit) }}
+ {{ with $linkTarget }}
+ <li>
+ <a href="{{ $linkTarget.RelPermalink }}" class="category-post more">{{ i18n "readMore" }} »</a>
+ </li>
+ {{ end }}
+ {{ end }}
+ </ul>
{{ end }}
diff --git a/layouts/partials/utils/tree-sections.html b/layouts/partials/utils/tree-sections.html
index 8569c83..1ec1bf6 100644
--- a/layouts/partials/utils/tree-sections.html
+++ b/layouts/partials/utils/tree-sections.html
@@ -3,6 +3,7 @@
{{- $.Scratch.Delete "pages" -}}
{{- $contentDir := $.Site.Params.contentDir -}}
{{- template "treeSections" (dict "$" $ "path" (cond $.Site.IsMultiLingual (printf `./%s` $contentDir) (printf `./content`))) -}}
+
{{- define "treeSections" -}}
{{- $ := index . "$" -}}
{{- $path := .path -}}
@@ -12,8 +13,8 @@
{{- $pagePath := (cond $.Site.IsMultiLingual (strings.TrimPrefix (printf `./%s` $.Site.Params.contentDir) (printf `%s/%s` $path $fileName)) (strings.TrimPrefix "./content" (printf `%s/%s` $path $fileName))) -}}
{{- with $.Site.GetPage $pagePath -}}
{{- if and (eq .Kind "section") (in $.Site.Params.mainSections .Section) -}}
- {{- $.Scratch.Add "sections" (printf "%s, " $fileName) -}}
- {{- $.Scratch.SetInMap "pages" $pagePath $fileName -}}
+ {{- $.Scratch.Add "sections" (slice $fileName) -}}
+ {{- $.Scratch.Add "pages" (slice $pagePath) -}}
{{- end -}}
{{- end -}}
{{- template "treeSections" (dict "$" $ "path" (printf `%s/%s` $path $fileName)) -}}