news-tab.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {{ $p := slice }}
  2. {{ range site.Taxonomies.categories }}
  3. {{ $p = $p | append .Page }}
  4. {{ end }}
  5. <div class="d-flex align-items-center position-relative tab-category mt-5 pt-5 pb-3">
  6. <section class="w-100">
  7. <h3 class="post-block-title">
  8. <span>Topics</span>
  9. </h3>
  10. </section>
  11. {{/* 收集所有 categories,並帶上文章數量 */}}
  12. {{ $cats := slice }}
  13. {{ range $name, $taxonomy := site.Taxonomies.categories }}
  14. {{ $cats = $cats | append (dict
  15. "name" $name
  16. "count" (len $taxonomy.Pages)
  17. "page" $taxonomy.Page
  18. ) }}
  19. {{ end }}
  20. {{/* 依照 count 由多到少排序(熱門分類優先) */}}
  21. {{ $cats = sort $cats "count" "desc" }}
  22. <ul class="nav nav-pills mb-3 ps-3 position-absolute" id="pills-tab" role="tablist"
  23. style="right: 0; background: #fff;">
  24. {{ range $index, $cat := first 5 $cats }}
  25. {{ $page := index $cat "page" }}
  26. <li class="nav-item" role="presentation">
  27. <button class="nav-link {{ if eq $index 0 }}active{{ end }}" id="pills-home-tab-{{$index}}" data-bs-toggle="pill"
  28. data-bs-target="#pills-home-{{$index}}" type="button" role="tab" aria-controls="pills-home-{{$index}}"
  29. aria-selected="{{ if eq $index 0 }}true{{ else }}false{{ end }}">
  30. {{ $page.LinkTitle }}
  31. </button>
  32. </li>
  33. {{ end }}
  34. </ul>
  35. </div>
  36. <!-- <div class="d-flex align-items-center position-relative tab-category mt-5 pt-5 pb-3">
  37. <section class="w-100">
  38. <h3 class="post-block-title">
  39. <span>Topics</span>
  40. </h3>
  41. </section>
  42. {{ $p := slice }}
  43. {{ range site.Taxonomies.categories }}
  44. {{ $p = $p | append .Page }}
  45. {{ end }}
  46. <ul class="nav nav-pills mb-3 ps-3 position-absolute" id="pills-tab" role="tablist"
  47. style="right: 0; background: #fff;">
  48. {{ range $index, $element := first 5 $p }}
  49. <li class="nav-item" role="presentation">
  50. <button class="nav-link {{ if (eq $index 0) }}active{{ end }}" id="pills-home-tab-{{$index}}"
  51. data-bs-toggle="pill" data-bs-target="#pills-home-{{$index}}" type="button" role="tab"
  52. aria-controls="pills-home-{{$index}}" aria-selected="true">{{ .LinkTitle }}</button>
  53. </li>
  54. {{ end }}
  55. </ul>
  56. </div> -->
  57. <div class="tab-content" id="pills-tabContent">
  58. {{ range $index, $element := first 6 $p }}
  59. <div class="tab-pane fade show {{ if (eq $index 0) }}active{{ end }}" id="pills-home-{{$index}}" role="tabpanel"
  60. aria-labelledby="pills-home-tab">
  61. <div class="row">
  62. {{ $t := slice .LinkTitle }}
  63. {{ range $index, $element := where .Site.Pages ".Params.categories" "intersect" $t }}
  64. {{ if or (eq $index 0) (eq $index 1) }}
  65. <div class="col-12 col-lg-6 mt-3">
  66. <div class="bg-img"
  67. style="background-image: linear-gradient(to bottom,rgba(0,0,0, 0) 50%, rgba(0,0,0, 100)),url('{{ .Params.image | relURL }}');"
  68. onclick="location.href='{{ .Permalink }}'">
  69. <section>
  70. {{ range (.GetTerms "categories") }}
  71. <a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
  72. {{ end }}
  73. <small>{{ .Date | time.Format ":date_long" }}</small>
  74. <h2 class="post-title">
  75. <a href="{{ .Permalink }}">{{ .Params.title }}</a>
  76. </h2>
  77. </section>
  78. </div>
  79. </div>
  80. {{ else if or (eq $index 2) (eq $index 3) (eq $index 4) (eq $index 5) }}
  81. <div class="col-12 col-lg-6 mt-3">
  82. <div class="row">
  83. <div class="col-5">
  84. <a href="{{ .Permalink }}">
  85. <img src="{{ .Params.image | relURL }}" alt="" class="news-thumbnail">
  86. </a>
  87. </div>
  88. <div class="col-7 border-bottom">
  89. <section class="news-info">
  90. {{ range (.GetTerms "categories") }}
  91. <a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
  92. {{ end }}
  93. <small>{{ .Date | time.Format ":date_long" }}</small>
  94. </section>
  95. <h2 class="post-title">
  96. <a href="{{ .Permalink }}">{{ .Params.title }}</a>
  97. </h2>
  98. <p class="post-depiction">
  99. <a href="{{ .Permalink }}">{{ .Summary }}</a>
  100. </p>
  101. </div>
  102. </div>
  103. </div>
  104. {{ end }}
  105. {{ end }}
  106. </div>
  107. </div>
  108. {{ end }}
  109. </div>