Skip to content

Commit

Permalink
feat: Allow to limit the number of articles listed per taxonomy entry (
Browse files Browse the repository at this point in the history
…#148)

* Fixes #147 - Allow to limit the number of articles listed per taxonomy entry

* Improved styling of the "Read more" link

* Move the position and respect the ruler of 42

* Add new param to zh-cn/config.toml

* Correct zh-cn translation of readMore

* Update resources folder

Co-authored-by: reuixiy <reuixiy@gmail.com>
  • Loading branch information
palant and reuixiy authored May 15, 2020
1 parent 5353fec commit f3d9ad0
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 10 deletions.
5 changes: 5 additions & 0 deletions assets/scss/layout/_list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
color: var(--color-contrast-medium);
line-height: 1.5;
}
.list-read-more {
margin-top: 1em;
font-size: 1.2em;
line-height: 1.5;
}

.list-year {
display: flex;
Expand Down
7 changes: 6 additions & 1 deletion config-examples/en/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enableGitInfo = false
# Enable generation of `robots.txt` file?
enableRobotsTXT = true

# Number of items per page in paginated
# Number of items per page in paginated
# lists (valid for the `posts` homepage
# layout in MemE)
paginate = 5
Expand Down Expand Up @@ -463,6 +463,11 @@ uglyURLs = false
# taxonomy term?
displayTaxonomyTermCount = true

# Set to a non-negative number to limit
# the number of posts displayed per
# taxonomy term.
limitEntriesLimit = -1


######################################
# Post Sections
Expand Down
3 changes: 3 additions & 0 deletions config-examples/zh-cn/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ uglyURLs = false
# 是否显示每一类别项下的文章数
displayTaxonomyTermCount = true

# 设置一个非负数来限制每一类别项下展示的文章数
limitEntriesLimit = -1


######################################
# 文章分区范围
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Target":"css/meme.min.edf743ebac09bfd5aeb7be4496e6bd60fc76966bfbcb41f913f95a4149fc4050.css","MediaType":"text/css","Data":{"Integrity":"sha256-7fdD66wJv9Wut75Elua9YPx2lmv7y0H5E/laQUn8QFA="}}
{"Target":"css/meme.min.123893da0ad2f3e34bfbdc37ba47a437fad955d0ad5d4642cd640578cd8569a8.css","MediaType":"text/css","Data":{"Integrity":"sha256-EjiT2grS8+NL+9w3ukekN/rZVdCtXUZCzWQFeM2Faag="}}
2 changes: 1 addition & 1 deletion i18n/zh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ other = "分钟"
other = "目录"

[readMore]
other = "阅读全文"
other = "阅读更多"

[prevPage]
other = "上一页"
Expand Down
4 changes: 2 additions & 2 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ <h2 class="list-year">{{ $year }}{{ if $.Site.Params.chineseZodiac }}{{ partial
{{ end }}
{{ $month := $.Scratch.Get "month" }}
<h3 class="list-month">{{ $month }}</h3>
{{ partial "utils/list-item.html" . }}
{{ partial "utils/list-item.html" (dict "Deliver" .) }}
{{ end }}
{{ else }}
{{ partial "utils/list-item.html" . }}
{{ partial "utils/list-item.html" (dict "Deliver" .) }}
{{ end }}
</ul>
{{ end }}
Expand Down
7 changes: 4 additions & 3 deletions layouts/partials/pages/taxonomy.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ <h1 class="list-title">{{ .Title | default (.Type | title) }}</h1>
{{ $name := .Name }}
<ul class="list-part">
<h2 class="term-title">
{{ with $.Site.GetPage (printf "/%s/%s" $type $name) }}
{{ $page := $.Site.GetPage (printf "/%s/%s" $type $name) }}
{{ with $page }}
<a href="{{ .RelPermalink }}" class="term-title-link">{{ .LinkTitle | default .Data.Term | default $name }}</a>
{{ end }}
{{ if $.Site.Params.displayTaxonomyTermCount }}
<span class="term-count">{{ printf "(%d)" .Count }}</span>
{{ end }}
</h2>
{{ partial "utils/list-item.html" . }}
{{ partial "utils/list-item.html" (dict "Deliver" . "linkTarget" $page) }}
</ul>
{{ end }}
</div>
</div>
</main>
</main>
20 changes: 19 additions & 1 deletion layouts/partials/utils/list-item.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
{{ range .Pages }}
{{- $linkTarget := .linkTarget -}}
{{- $pages := .Deliver.Pages -}}
{{- $limit := -1 -}}
{{- with $linkTarget -}}
{{- if isset (index $pages 0).Site.Params "limitentrieslimit" -}}
{{- $limit = (index $pages 0).Site.Params.limitEntriesLimit -}}
{{- end -}}
{{- end -}}
{{- if ge $limit 0 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}
{{ range $pages }}
<li class="list-item">
<a href="{{ .RelPermalink }}" class="list-item-title">{{ .LinkTitle }}</a>
<time datetime="{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" }}" class="list-item-time">{{ .PublishDate.Format .Site.Params.listDateFormat }}</time>
</li>
{{ end }}
{{ if and (gt $limit 0) (gt (len .Deliver.Pages) $limit) }}
{{ with $linkTarget }}
<li class="list-read-more">
<a href="{{ $linkTarget.RelPermalink }}">{{ i18n "readMore" }} »</a>
</li>
{{ end }}
{{ end }}

0 comments on commit f3d9ad0

Please sign in to comment.