Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the archive widget #540

Merged
merged 1 commit into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ viewer = true # Image Viewer

[sidebar]
# fixed = true
# archive = false

[codeBlock]
# maxLines = 8
Expand Down
1 change: 1 addition & 0 deletions exampleSite/content/docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ See also [All Configuration Settings](https://gohugo.io/getting-started/configur
| **Sidebar**
| `sidebar` | Object | - |
| `sidebar.fixed` | Boolean | `false` | Fix default sidebar.
| `sidebar.archive` | Boolean | `true` | Show the archive widget on the sidebar.
| **Meta Tag**
| `metaRobots` | String | - | Empty means that turn it off.
| `contact` | Object | - | [Contact Form]({{< ref "docs/layouts/contact-form" >}})
Expand Down
1 change: 1 addition & 0 deletions exampleSite/content/docs/configuration/index.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ aliases = [
| **Sidebar**
| `sidebar` | Object | - |
| `sidebar.fixed` | Boolean | `false` | 固定默认侧边栏。
| `sidebar.archive` | Boolean | `true` | 于侧边栏显示归档挂件。
| **Meta Tag**
| `metaRobots` | String | - | 空字符串表示禁用。
| `contact` | Object | - | [联系表单]({{< ref "docs/layouts/contact-form" >}})
Expand Down
1 change: 1 addition & 0 deletions exampleSite/content/docs/configuration/index.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ aliases = [
| **Sidebar**
| `sidebar` | Object | - |
| `sidebar.fixed` | Boolean | `false` | 固定默認側邊欄。
| `sidebar.archive` | Boolean | `true` | 於側邊欄顯示歸檔掛件。
| **Meta Tag**
| `metaRobots` | String | - | 空字符串表示禁用。
| `contact` | Object | - | [聯系表單]({{< ref "docs/layouts/contact-form" >}})
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{- end -}}
<div class="archive card row component">
<div class="card-header">
<h2 class="archive-title card-title">{{ $currentYear }}</h2>
<h2 class="archive-title card-title" id="archive-{{ $currentYear }}">{{ $currentYear }}</h2>
</div>
<div class="card-body">
<ul class="archive-posts post-list">
Expand Down
38 changes: 38 additions & 0 deletions layouts/partials/sidebar/archive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- if default true $.Site.Params.sidebar.archive -}}
{{- $baseURL := "" -}}
{{- with where $.Site.Pages "Layout" "archive" -}}
{{- $baseURL = (index . 0).Permalink -}}
{{- end -}}
<section class="row card component">
<div class="card-header">
<h2 class="card-title">
{{- with $baseURL -}}
<a href="{{ . }}">{{ i18n "archives" }}</a>
{{- else -}}
{{ i18n "archives" }}
{{- end -}}
</h2>
</div>
<div class="card-body">
<ul class="post-list">
{{- $totalCount := 0 -}}
{{ range (where $.Site.RegularPages "Type" "in" $.Site.Params.mainSections).GroupByDate "2006" }}
<li>
{{- $pageNumber := 0 -}}
{{- if $baseURL -}}
{{- $pageNumber := div $totalCount (default 100 $.Site.Params.archive.paginate) | add 1 -}}
{{- if eq $pageNumber 1 -}}
<a href="{{ printf "%s#archive-%s" $baseURL .Key }}">{{ .Key }}({{ len .Pages }})</a>
{{- else -}}
<a href="{{ printf "%spage/%d/#archive-%s" $baseURL $pageNumber .Key }}">{{ .Key }}({{ len .Pages }})</a>
{{- end -}}
{{- else -}}
{{ .Key }}({{ len .Pages }})
{{- end -}}
</li>
{{- $totalCount = add $totalCount (len .Pages) -}}
{{ end }}
</ul>
</div>
</section>
{{- end -}}
1 change: 1 addition & 0 deletions layouts/partials/sidebar/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
{{- partialCached "sidebar/featured-posts" . .Section -}}
{{- partialCached "sidebar/recent-posts" . .Section -}}
{{- partialCached "sidebar/taxonomies" . -}}
{{- partialCached "sidebar/archive" . -}}