list.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {{ define "main" }}
  2. <div class="page-wrapper">
  3. <div class="container">
  4. <div class="row" style="padding-top:60px;">
  5. <div class="col-md-8">
  6. {{ $paginator := .Paginate .Data.Pages }}
  7. {{ range $paginator.Pages }}
  8. <div class="mb-5 post">
  9. <div class="mb-4">
  10. <a href="{{ .Permalink }}">
  11. <img class="img-fluid" src="{{ .Params.Image | relURL }}" alt="{{ .Title }}">
  12. </a>
  13. </div>
  14. <h3><a href="{{ .Permalink }}" style="color:black;">{{ .Title }}</a></h3>
  15. <p class="blog-content" style="font-size:0.8rem;">{{ .PublishDate.Format "January 2, 2006" }}</p>
  16. <div class="blog-content">
  17. <p>{{ .Summary }}</p>
  18. <a href="{{ .Permalink }}" class="btn btn-light">繼續閱讀</a>
  19. </div>
  20. </div>
  21. {{ end }}
  22. <!-- pagination -->
  23. {{ $paginator := .Paginator }}
  24. {{ $adjacent_links := 2 }}
  25. {{ $max_links := (add (mul $adjacent_links 2) 1) }}
  26. {{ $lower_limit := (add $adjacent_links 1) }}
  27. {{ $upper_limit := (sub $paginator.TotalPages $adjacent_links) }}
  28. {{ if gt $paginator.TotalPages 1 }}
  29. <nav class="text-center">
  30. <ul class="pagination post-pagination">
  31. <!-- Previous page. -->
  32. {{ if $paginator.HasPrev }}
  33. <li>
  34. <a href="{{ $paginator.Prev.URL }}" class="page-link">上一頁</a>
  35. </li>
  36. {{ end }}
  37. <!-- Page numbers. -->
  38. {{ range $paginator.Pagers }}
  39. {{ $.Scratch.Set "page_number_flag" false }}
  40. <!-- Advanced page numbers. -->
  41. {{ if gt $paginator.TotalPages $max_links }}
  42. <!-- Lower limit pages. -->
  43. <!-- If the user is on a page which is in the lower limit. -->
  44. {{ if le $paginator.PageNumber $lower_limit }}
  45. <!-- If the current loop page is less than max_links. -->
  46. {{ if le .PageNumber $max_links }}
  47. {{ $.Scratch.Set "page_number_flag" true }}
  48. {{ end }}
  49. <!-- Upper limit pages. -->
  50. <!-- If the user is on a page which is in the upper limit. -->
  51. {{ else if ge $paginator.PageNumber $upper_limit }}
  52. <!-- If the current loop page is greater than total pages minus $max_links -->
  53. {{ if gt .PageNumber (sub $paginator.TotalPages $max_links) }}
  54. {{ $.Scratch.Set "page_number_flag" true }}
  55. {{ end }}
  56. <!-- Middle pages. -->
  57. {{ else }}
  58. {{ if and ( ge .PageNumber (sub $paginator.PageNumber $adjacent_links) ) ( le .PageNumber (add $paginator.PageNumber $adjacent_links) ) }}
  59. {{ $.Scratch.Set "page_number_flag" true }}
  60. {{ end }}
  61. {{ end }}
  62. <!-- Simple page numbers. -->
  63. {{ else }}
  64. {{ $.Scratch.Set "page_number_flag" true }}
  65. {{ end }}
  66. <!-- Output page numbers. -->
  67. {{ if eq ($.Scratch.Get "page_number_flag") true }}
  68. <li class="{{ if eq . $paginator }} active {{ end }}">
  69. <a href="{{ .URL }}">
  70. {{ .PageNumber }}
  71. </a>
  72. </li>
  73. {{ end }}
  74. {{ end }}
  75. <!-- Next page. -->
  76. {{ if $paginator.HasNext }}
  77. <li>
  78. <a href="{{ $paginator.Next.URL }}">下一頁</a>
  79. </li>
  80. {{ end }}
  81. </ul>
  82. </nav>
  83. {{ end }}
  84. </div>
  85. <div class="col-md-4">
  86. {{ partial "blog-sidebar.html" . }}
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. {{ end }}