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

[FEATURE] 标签,分类,合集,列表中的文章可以按照文章名称来排序吗,主页不需要这样 #423

Open
ooooo-youwillsee opened this issue Mar 5, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ooooo-youwillsee
Copy link

Describe the feature you want 描述你的功能需求

我写文章的命名方式

01 xxx
02 xxx
03 xxx
...
10 xxx

目前这些文件都是按照时间来排序的,从一开始写文档,我就会按照01,02把内容都划分好了,按照填空式写文章,并不是从01 依次写到 10,这样导致我每次都要调整时间

Useful reference 有价值的参考

No response

@ooooo-youwillsee ooooo-youwillsee added the enhancement New feature or request label Mar 5, 2024
@ooooo-youwillsee
Copy link
Author

我尝试了下面的修改,可以达到我想要的效果

新建 layouts/partials/function/page.html 来处理分页逻辑

{{- $pages := .Pages -}}
{{- if eq .Site.Params.list.orderBy "title" -}}
  {{- $pages = .Pages.ByTitle -}}
{{- else if eq .Site.Params.list.orderBy "weight" -}}
  {{- $pages = .Pages.ByWeight -}}
{{- else -}}
  {{- $pages = .Pages.GroupByDate "2006" -}}
{{- end -}}
{{- with .Site.Params.list.paginate | default .Site.Params.paginate -}}
  {{- $pages = $.Paginate $pages . -}}
{{- end -}}
{{- return $pages -}}

修改 layouts/taxonomy/list.html 的分页展示逻辑

{{- /* Paginate */ -}}
    {{- if .Pages -}}
      {{- $pages := partial "function/page.html" . -}}
      {{- if eq .Site.Params.list.orderBy "" -}}
        {{- /* page group start */ -}}
        {{- range $pages.PageGroups -}}
          <h2 class="group-title">
            {{- dict "Class" "fa-regular fa-calendar fa-fw me-1" | partial "plugin/icon.html" -}}
            {{- .Key -}}
          </h2>
          {{- range .Pages -}}
            <article class="archive-item">
              <a href="{{ .RelPermalink }}" class="archive-item-link">
                {{- $repost := .Params.repost | default dict -}}
                {{- if eq $repost.enable true -}}
                  {{- dict "Class" "fa-solid fa-share fa-fw text-success me-1" | partial "plugin/icon.html" -}}
                {{- end -}}
                {{- .LinkTitle -}}
              </a>
              <span class="archive-item-date" title='{{ "2006-01-02 15:04:05" | .Date.Format }}'>
                {{- .Date | dateFormat ($.Site.Params.list.dateFormat | default "01-02") -}}
              </span>
            </article>
          {{- end -}}
        {{- end -}}
        {{- /* page group end */ -}}
      {{- else -}}
        {{- /* page start */ -}}
        {{- range $pages.Pages -}}
        <article class="archive-item">
          <a href="{{ .RelPermalink }}" class="archive-item-link">
            {{- $repost := .Params.repost | default dict -}}
            {{- if eq $repost.enable true -}}
            {{- dict "Class" "fa-solid fa-share fa-fw text-success me-1" | partial "plugin/icon.html" -}}
            {{- end -}}
            {{- .LinkTitle -}}
          </a>
          <span class="archive-item-date" title='{{ "2006-01-02 15:04:05" | .Date.Format }}'>
                    {{- .Date | dateFormat ($.Site.Params.list.dateFormat | default "01-02") -}}
                  </span>
        </article>
        {{- end -}}
        {{- /* page end */ -}}
      {{- end -}}
      {{- partial "paginator.html" . -}}
    {{- end -}}

新增配置

[params.list]
    // order of pages, options values is ["title", "weight"], default value is "groupByDate" if empty
    orderBy = "title"

我发现 tagscollections,都是共用同一个 list.html 文件,这个有啥办法解决吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant