add tags and categories
This commit is contained in:
19
layouts/taxonomy/category.html
Normal file
19
layouts/taxonomy/category.html
Normal file
@ -0,0 +1,19 @@
|
||||
{{ define "main" }}
|
||||
<div id="page-category">
|
||||
<h1 class="ps-lg-2">
|
||||
<i class="far fa-folder-open fa-fw text-muted"></i>
|
||||
{{ .Title }}
|
||||
<span class="lead text-muted ps-2">{{ len .Pages }}</span>
|
||||
</h1>
|
||||
|
||||
<ul class="content ps-0">
|
||||
{{ range .Pages }}
|
||||
<li class="d-flex justify-content-between px-md-3">
|
||||
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
|
||||
<span class="dash flex-grow-1"></span>
|
||||
<span class="text-muted small text-nowrap">{{ .Date | time.Format ":date_medium" }}</span>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</div>
|
||||
{{ end }}
|
114
layouts/taxonomy/category.terms.html
Normal file
114
layouts/taxonomy/category.terms.html
Normal file
@ -0,0 +1,114 @@
|
||||
|
||||
{{ define "main" }}
|
||||
<article class="px-1">
|
||||
<h1 class="dynamic-title">
|
||||
{{ i18n "tabs.categories" }}
|
||||
</h1>
|
||||
<div class="content">
|
||||
<div class="container">
|
||||
{{ $categories := .Site.Taxonomies.categories }}
|
||||
|
||||
<!-- 首先收集所有唯一的父分类 -->
|
||||
{{ $parentCategories := slice }}
|
||||
{{ range $name, $taxonomy := $categories }}
|
||||
{{ range $taxonomy.Pages }}
|
||||
{{ if gt (len .Params.categories) 0 }}
|
||||
{{ $parentCategories = $parentCategories | append (index .Params.categories 0) }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ $parentCategories = $parentCategories | uniq | sort }}
|
||||
|
||||
<!-- 然后为每个父分类创建卡片 -->
|
||||
{{ range $parentCategories }}
|
||||
{{ $parentName := . }}
|
||||
{{ $subcategories := slice }}
|
||||
{{ $parentPages := slice }}
|
||||
|
||||
<!-- 收集与此父分类相关的所有页面和子分类 -->
|
||||
{{ range $name, $taxonomy := $categories }}
|
||||
{{ range $taxonomy.Pages }}
|
||||
{{ if gt (len .Params.categories) 0 }}
|
||||
{{ if eq (index .Params.categories 0) $parentName }}
|
||||
{{ $parentPages = $parentPages | append . }}
|
||||
{{ if gt (len .Params.categories) 1 }}
|
||||
{{ $subcategories = $subcategories | append (index .Params.categories 1) }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ $subcategories = $subcategories | uniq | sort }}
|
||||
|
||||
<div class="card categories mb-3">
|
||||
<div class="card-header d-flex justify-content-between hide-border-bottom">
|
||||
<span class="ms-2">
|
||||
<i class="far fa-folder{{ if gt (len $subcategories) 0 }}-open{{ end }} fa-fw"></i>
|
||||
<a href="{{ "/categories/" | relURL }}{{ $parentName | urlize }}" class="mx-2">{{ $parentName }}</a>
|
||||
<span class="text-muted small font-weight-light">
|
||||
{{ if gt (len $subcategories) 0 }}
|
||||
{{ len $subcategories }}
|
||||
{{ if gt (len $subcategories) 1 }}
|
||||
subcategories,
|
||||
{{ else }}
|
||||
subcategory,
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ len $parentPages }}
|
||||
{{ if gt (len $parentPages) 1 }}
|
||||
posts
|
||||
{{ else }}
|
||||
post
|
||||
{{ end }}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
{{ if gt (len $subcategories) 0 }}
|
||||
<a href="#sub-{{ $parentName | anchorize }}" data-bs-toggle="collapse" aria-expanded="true">
|
||||
<i class="fas fa-fw fa-angle-down"></i>
|
||||
</a>
|
||||
{{ else }}
|
||||
<span class="disabled">
|
||||
<i class="fas fa-fw fa-angle-right"></i>
|
||||
</span>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
{{ if gt (len $subcategories) 0 }}
|
||||
<div id="sub-{{ $parentName | anchorize }}" class="collapse show">
|
||||
<ul class="list-group list-group-flush">
|
||||
{{ range $subcategories }}
|
||||
{{ $subCategoryName := . }}
|
||||
|
||||
<!-- 查找子分类的文章 -->
|
||||
{{ $subPages := slice }}
|
||||
{{ range $parentPages }}
|
||||
{{ if gt (len .Params.categories) 1 }}
|
||||
{{ if eq (index .Params.categories 1) $subCategoryName }}
|
||||
{{ $subPages = $subPages | append . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
<li class="list-group-item">
|
||||
<i class="far fa-folder fa-fw"></i>
|
||||
<a href="{{ "/categories/" | relURL }}{{ $subCategoryName | urlize }}" class="mx-2">{{ $subCategoryName }}</a>
|
||||
<span class="text-muted small font-weight-light">
|
||||
{{ len $subPages }}
|
||||
{{ if gt (len $subPages) 1 }}
|
||||
posts
|
||||
{{ else }}
|
||||
post
|
||||
{{ end }}
|
||||
</span>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{{ end }}
|
20
layouts/taxonomy/tag.html
Normal file
20
layouts/taxonomy/tag.html
Normal file
@ -0,0 +1,20 @@
|
||||
{{ define "main" }}
|
||||
{{ $lang := .Site.Language.Lang }}
|
||||
|
||||
<div id="page-tag">
|
||||
<h1 class="ps-lg-2">
|
||||
<i class="fa fa-tag fa-fw text-muted"></i>
|
||||
{{ .Data.Term }}
|
||||
<span class="lead text-muted ps-2">{{ len .Pages }}</span>
|
||||
</h1>
|
||||
<ul class="content ps-0">
|
||||
{{ range .Pages }}
|
||||
<li class="d-flex justify-content-between px-md-3">
|
||||
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
|
||||
<span class="dash flex-grow-1"></span>
|
||||
{{ partial "datetime.html" (dict "date" .Date "lang" $lang "class" "text-muted small text-nowrap") }}
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</div>
|
||||
{{ end }}
|
28
layouts/taxonomy/tag.terms.html
Normal file
28
layouts/taxonomy/tag.terms.html
Normal file
@ -0,0 +1,28 @@
|
||||
{{ define "main" }}
|
||||
<article class="px-1">
|
||||
<h1 class="dynamic-title">
|
||||
{{ i18n "tabs.tags" }}
|
||||
</h1>
|
||||
<div class="content">
|
||||
<div id="tags" class="d-flex flex-wrap mx-xl-2">
|
||||
{{ $tags := slice }}
|
||||
{{ range $name, $taxonomy := .Site.Taxonomies.tags }}
|
||||
{{ $tags = $tags | append $name }}
|
||||
{{ end }}
|
||||
|
||||
{{ $sorted_tags := sort $tags }}
|
||||
|
||||
{{ range $sorted_tags }}
|
||||
<div>
|
||||
<a class="tag" href="{{ "/tags/" | relLangURL }}{{ . | urlize }}/">
|
||||
{{ . -}}
|
||||
<span class="text-muted">{{ len (index $.Site.Taxonomies.tags .) }}</span>
|
||||
</a>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</article>
|
||||
|
||||
{{ end }}
|
Reference in New Issue
Block a user