pages.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. {{/* Pages Widget */}}
  2. {{/* https://wowchemy.com/docs/widget/ */}}
  3. {{/* Initialise */}}
  4. {{ $ := .root }}
  5. {{ $st := .page }}
  6. {{ $items_offset := $st.Params.content.offset | default 0 }}
  7. {{ $items_count := $st.Params.content.count }}
  8. {{ if eq $items_count 0 }}
  9. {{ $items_count = 65535 }}
  10. {{ else }}
  11. {{ $items_count = $items_count | default 5 }}
  12. {{ end }}
  13. {{ $items_sort := $st.Params.content.order | default "desc" }}
  14. {{/* Query */}}
  15. {{ $query := site.RegularPages }}
  16. {{ $archive_page := "" }}
  17. {{/* Filters */}}
  18. {{ if $st.Params.content.page_type }}
  19. {{ $query = where $query "Type" $st.Params.content.page_type }}
  20. {{ $archive_page = site.GetPage "Section" $st.Params.content.page_type }}
  21. {{ end }}
  22. {{ if $st.Params.content.filters.folders }}
  23. {{ $folders := $st.Params.content.filters.folders }}
  24. {{ $query = where $query "Section" "in" $folders }}
  25. {{/* Init archive page to main folder */}}
  26. {{ $main_folder := index $folders 0 }}
  27. {{ $archive_page = site.GetPage "Section" $main_folder }}
  28. {{ end }}
  29. {{ if $st.Params.content.filters.tag }}
  30. {{ $archive_page = site.GetPage (printf "tags/%s" (urlize $st.Params.content.filters.tag)) }}
  31. {{ $query = $query | intersect $archive_page.Pages }}
  32. {{ end }}
  33. {{ if $st.Params.content.filters.category }}
  34. {{ $archive_page = site.GetPage (printf "categories/%s" (urlize $st.Params.content.filters.category)) }}
  35. {{ $query = $query | intersect $archive_page.Pages }}
  36. {{ end }}
  37. {{ if $st.Params.content.filters.publication_type }}
  38. {{ $archive_page = site.GetPage (printf "publication_types/%s" $st.Params.content.filters.publication_type) }}
  39. {{ $query = $query | intersect $archive_page.Pages }}
  40. {{ end }}
  41. {{ if $st.Params.content.filters.author }}
  42. {{ $archive_page = site.GetPage (printf "authors/%s" (urlize $st.Params.content.filters.author)) }}
  43. {{ $query = $query | intersect $archive_page.Pages }}
  44. {{ end }}
  45. {{ if $st.Params.content.filters.exclude_featured }}
  46. {{ $query = where $query "Params.featured" "!=" true }}
  47. {{ end }}
  48. {{ if $st.Params.content.filters.exclude_past }}
  49. {{ $query = where $query "Date" ">=" now }}
  50. {{ end }}
  51. {{ if $st.Params.content.filters.exclude_future }}
  52. {{ $query = where $query "Date" "<" now }}
  53. {{ end }}
  54. {{ $count := len $query }}
  55. {{/* Sort */}}
  56. {{ $sort_by := "Date" }}
  57. {{ $query = sort $query $sort_by $items_sort }}
  58. {{/* Offset and Limit */}}
  59. {{ if gt $items_offset 0 }}
  60. {{ $query = first $items_count (after $items_offset $query) }}
  61. {{ else }}
  62. {{ $query = first $items_count $query }}
  63. {{ end }}
  64. {{ $columns := $st.Params.design.columns | default "2" }}
  65. <div class="col-12 {{if eq $columns "2"}}col-lg-8{{end}}">
  66. {{ with $st.Content }}{{ . }}{{ end }}
  67. {{ range $index, $item := $query }}
  68. {{ partial "functions/render_view" (dict "page" $st "item" . "view" ($st.Params.design.view | default "compact") "index" $index) }}
  69. {{end}}
  70. {{/* Archive link */}}
  71. {{ $show_archive_link := $st.Params.content.archive.enable | default (gt $count $items_count) }}
  72. {{ if $show_archive_link | and $archive_page }}
  73. {{ $archive_link := "" }}
  74. {{ if $st.Params.content.archive.link }}
  75. {{ $archive_link = $st.Params.content.archive.link | relLangURL }}
  76. {{ else }}
  77. {{ $archive_link = $archive_page.RelPermalink }}
  78. {{ end }}
  79. {{/* Localisation */}}
  80. {{ $items_type := $archive_page.Type }}
  81. {{ $i18n := "" }}
  82. {{ if eq $items_type "post" }}
  83. {{ $i18n = "more_posts" }}
  84. {{ else if eq $items_type "event" }}
  85. {{ $i18n = "more_talks" }}
  86. {{ else if eq $items_type "publication" }}
  87. {{ $i18n = "more_publications" }}
  88. {{ else }}
  89. {{ $i18n = "more_pages" }}
  90. {{ end }}
  91. {{ $archive_text := $st.Params.content.archive.text | default (i18n $i18n) | default "See all" }}
  92. <div class="see-all">
  93. <a href="{{ $archive_link }}">
  94. {{ $archive_text | emojify }}
  95. <i class="fas fa-angle-right"></i>
  96. </a>
  97. </div>
  98. {{ end }}
  99. </div>