最近更新したページの表示条件を変更する

トップページのリンク

トップページのRecently postedに更新日時の順でリンク表示をしています。
このリンクにはセクションページやタグのページへのリンクも含まれていました。そのため一つの記事を更新すると関連するタグのページなどもリンクも表示されていました。

変更前

最終更新日でソートして先頭12件のリンクを表示しています。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<aside id="recentlySection" class="recently-section">
  <h2 class="label">Recently posted</h2>
  <div class="articles">
    {{ range first 12 .Site.Pages.ByLastmod.Reverse }}
    <a class="content-card" href="{{.RelPermalink}}">
      <section class="card-text">
        <h3>{{.Title}}</h3>
        <p>{{.Summary}}</p>
        <p><small>Last Mod: {{.Lastmod.Format "Jan 2, 2006"}}</small></p>
      </section>
    </a>
  {{ end }}
  </div>
</aside>

変更後

条件を追加しました。

  • Kindがpage
  • 指定したSectionの場合(“about” “pmp” “hugo” “vue”)

件数を120件に増やしました。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<aside id="recentlySection" class="recently-section">
  <h2 class="label">Recently posted</h2>
  <div class="articles">
    {{ range first 120 (where (where .Site.Pages.ByLastmod.Reverse "Kind" "page") "Section" "in" (slice "about" "pmp" "hugo" "vue")) }}
    <a class="content-card" href="{{.RelPermalink}}">
      <section class="card-text">
        <h3>{{.Title}}</h3>
        <p>{{.Summary}}</p>
        <p><small>Last Mod: {{.Lastmod.Format "Jan 2, 2006"}}</small></p>
      </section>
    </a>
  {{ end }}
  </div>
</aside>  

リンク

HUGO Where

Last Mod: May 15, 2022