news-tab.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <!-- Topics 區塊 -->
  2. <div class="d-flex align-items-center position-relative tab-category mt-5 pt-5 pb-3">
  3. <section class="w-100">
  4. <h3 class="post-block-title">
  5. <span>Topics</span>
  6. </h3>
  7. </section>
  8. <!-- 收集所有 categories,並帶上文章數量 -->
  9. {{ $cats := slice }}
  10. {{ range $name, $taxonomy := site.Taxonomies.categories }}
  11. {{ $cats = $cats | append (dict
  12. "name" $name
  13. "count" (len $taxonomy.Pages)
  14. "page" $taxonomy.Page
  15. ) }}
  16. {{ end }}
  17. <!-- 依照 count 由多到少排序(熱門分類優先) -->
  18. {{ $cats = sort $cats "count" "desc" }}
  19. <ul class="nav nav-pills mb-3 ps-3 position-absolute" id="pills-tab" role="tablist"
  20. style="right: 0; background: #fff;">
  21. {{ range $index, $cat := first 5 $cats }}
  22. {{ $page := index $cat "page" }}
  23. <li class="nav-item" role="presentation">
  24. <button class="nav-link {{ if eq $index 0 }}active{{ end }}" id="pills-home-tab-{{$index}}" data-bs-toggle="pill"
  25. data-bs-target="#pills-home-{{$index}}" type="button" role="tab" aria-controls="pills-home-{{$index}}"
  26. aria-selected="{{ if eq $index 0 }}true{{ else }}false{{ end }}">
  27. {{ $page.LinkTitle }}
  28. </button>
  29. </li>
  30. {{ end }}
  31. </ul>
  32. </div>
  33. <!-- 對應的 tab content -->
  34. <div class="tab-content" id="pills-tabContent">
  35. {{ range $index, $cat := first 5 $cats }}
  36. {{ $catName := index $cat "name" }}
  37. <div class="tab-pane fade show {{ if eq $index 0 }}active{{ end }}" id="pills-home-{{$index}}" role="tabpanel"
  38. aria-labelledby="pills-home-tab-{{$index}}">
  39. <div class="row">
  40. {{/* 取出這個 category 底下的文章 */}}
  41. {{ $t := slice $catName }}
  42. {{ range $i, $post := where site.RegularPages ".Params.categories" "intersect" $t }}
  43. {{/* 第 0、1 則:大圖卡片 */}}
  44. {{ if or (eq $i 0) (eq $i 1) }}
  45. <div class="col-12 col-lg-6 mt-3">
  46. <div class="bg-img" style="background-image: linear-gradient(
  47. to bottom,
  48. rgba(0,0,0, 0) 50%,
  49. rgba(0,0,0, 100)
  50. ),
  51. url('{{ $post.Params.image | relURL }}');" onclick="location.href='{{ $post.Permalink }}'">
  52. <section>
  53. {{ range ($post.GetTerms "categories") }}
  54. <a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
  55. {{ end }}
  56. <small>{{ $post.Date | time.Format ":date_long" }}</small>
  57. <h2 class="post-title">
  58. <a href="{{ $post.Permalink }}">{{ $post.Params.title }}</a>
  59. </h2>
  60. </section>
  61. </div>
  62. </div>
  63. {{/* 第 2~5 則:右側小圖列表 */}}
  64. {{ else if or (eq $i 2) (eq $i 3) (eq $i 4) (eq $i 5) }}
  65. <div class="col-12 col-lg-6 mt-3">
  66. <div class="row">
  67. <div class="col-5">
  68. <a href="{{ $post.Permalink }}">
  69. <img src="{{ $post.Params.image | relURL }}" alt="" class="news-thumbnail">
  70. </a>
  71. </div>
  72. <div class="col-7 border-bottom">
  73. <section class="news-info">
  74. {{ range ($post.GetTerms "categories") }}
  75. <a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
  76. {{ end }}
  77. <small>{{ $post.Date | time.Format ":date_long" }}</small>
  78. </section>
  79. <h2 class="post-title">
  80. <a href="{{ $post.Permalink }}">{{ $post.Params.title }}</a>
  81. </h2>
  82. <!--
  83. <p class="post-depiction">
  84. <a href="{{ $post.Permalink }}">{{ $post.Summary }}</a>
  85. </p>
  86. -->
  87. </div>
  88. </div>
  89. </div>
  90. {{ end }}
  91. {{ end }} {{/* range posts in this category */}}
  92. </div>
  93. </div>
  94. {{ end }} {{/* range $cats for tab panes */}}
  95. </div>
  96. <!-- {{ $p := slice }}
  97. {{ range site.Taxonomies.categories }}
  98. {{ $p = $p | append .Page }}
  99. {{ end }}
  100. <div class="d-flex align-items-center position-relative tab-category mt-5 pt-5 pb-3">
  101. <section class="w-100">
  102. <h3 class="post-block-title">
  103. <span>Topics</span>
  104. </h3>
  105. </section>
  106. {{ $p := slice }}
  107. {{ range site.Taxonomies.categories }}
  108. {{ $p = $p | append .Page }}
  109. {{ end }}
  110. <ul class="nav nav-pills mb-3 ps-3 position-absolute" id="pills-tab" role="tablist"
  111. style="right: 0; background: #fff;">
  112. {{ range $index, $element := first 5 $p }}
  113. <li class="nav-item" role="presentation">
  114. <button class="nav-link {{ if (eq $index 0) }}active{{ end }}" id="pills-home-tab-{{$index}}"
  115. data-bs-toggle="pill" data-bs-target="#pills-home-{{$index}}" type="button" role="tab"
  116. aria-controls="pills-home-{{$index}}" aria-selected="true">{{ .LinkTitle }}</button>
  117. </li>
  118. {{ end }}
  119. </ul>
  120. </div>
  121. <div class="tab-content" id="pills-tabContent">
  122. {{ range $index, $element := first 6 $p }}
  123. <div class="tab-pane fade show {{ if (eq $index 0) }}active{{ end }}" id="pills-home-{{$index}}" role="tabpanel"
  124. aria-labelledby="pills-home-tab">
  125. <div class="row">
  126. {{ $t := slice .LinkTitle }}
  127. {{ range $index, $element := where .Site.Pages ".Params.categories" "intersect" $t }}
  128. {{ if or (eq $index 0) (eq $index 1) }}
  129. <div class="col-12 col-lg-6 mt-3">
  130. <div class="bg-img"
  131. style="background-image: linear-gradient(to bottom,rgba(0,0,0, 0) 50%, rgba(0,0,0, 100)),url('{{ .Params.image | relURL }}');"
  132. onclick="location.href='{{ .Permalink }}'">
  133. <section>
  134. {{ range (.GetTerms "categories") }}
  135. <a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
  136. {{ end }}
  137. <small>{{ .Date | time.Format ":date_long" }}</small>
  138. <h2 class="post-title">
  139. <a href="{{ .Permalink }}">{{ .Params.title }}</a>
  140. </h2>
  141. </section>
  142. </div>
  143. </div>
  144. {{ else if or (eq $index 2) (eq $index 3) (eq $index 4) (eq $index 5) }}
  145. <div class="col-12 col-lg-6 mt-3">
  146. <div class="row">
  147. <div class="col-5">
  148. <a href="{{ .Permalink }}">
  149. <img src="{{ .Params.image | relURL }}" alt="" class="news-thumbnail">
  150. </a>
  151. </div>
  152. <div class="col-7 border-bottom">
  153. <section class="news-info">
  154. {{ range (.GetTerms "categories") }}
  155. <a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
  156. {{ end }}
  157. <small>{{ .Date | time.Format ":date_long" }}</small>
  158. </section>
  159. <h2 class="post-title">
  160. <a href="{{ .Permalink }}">{{ .Params.title }}</a>
  161. </h2>
  162. </div>
  163. </div>
  164. </div>
  165. {{ end }}
  166. {{ end }}
  167. </div>
  168. </div>
  169. {{ end }}
  170. </div> -->