Parcourir la source

feat: consolidate Featured Talks/Pubs widgets into Featured widget

See #918
George Cushen il y a 6 ans
Parent
commit
2e146eed9c

+ 1 - 1
exampleSite/content/home/posts.md

@@ -62,5 +62,5 @@ subtitle = ""
  css_style = ""
  
  # CSS class.
- css_class = ""  
+ css_class = ""
 +++

+ 1 - 1
exampleSite/content/home/publications.md

@@ -62,7 +62,7 @@ subtitle = ""
  css_style = ""
  
  # CSS class.
- css_class = ""  
+ css_class = ""
 +++
 
 {{% alert note %}}

+ 53 - 22
exampleSite/content/home/publications_featured.md

@@ -1,32 +1,63 @@
 +++
-# Featured Publications widget.
-# This widget displays publications from `content/publication/` which have
+# A Featured Publications section created with the Featured Content widget.
+# This section displays publications from `content/publication/` which have
 # `featured = true` in their front matter.
-widget = "publications_featured"  # Do not modify this line!
+
+widget = "featured"  # Do not modify this line!
 active = true  # Activate this widget? true/false
+weight = 10  # Order that this section will appear.
 
 title = "Featured Publications"
 subtitle = ""
 
-# Order that this section will appear in.
-weight = 10
+[content]
+  # Page type to display. E.g. post, talk, or publication.
+  page_type = "publication"
+  
+  # Choose how much pages you would like to display (0 = all pages)
+  count = 0
 
-# View.
-#   1 = List
-#   2 = Compact
-#   3 = Card
-#   4 = Citation
-view = 3
+  # Page order. Descending (desc) or ascending (asc) date.
+  order = "desc"
 
-# Filter by publication type.
-# -1: Any
-#  0: Uncategorized
-#  1: Conference proceedings
-#  2: Journal
-#  3: Work in progress
-#  4: Technical report
-#  5: Book
-#  6: Book chapter
-publication_type = "-1"
-+++
+  # Filter posts by a taxonomy term.
+  [content.filters]
+    tag = ""
+    category = ""
+    publication_type = ""
+  
+[design]
+  # Toggle between the various page layout types.
+  #   1 = List
+  #   2 = Compact
+  #   3 = Card
+  #   4 = Citation (publication only)
+  view = 3
+  
+[design.background]
+  # Apply a background color, gradient, or image.
+  #   Uncomment (by removing `#`) an option to apply it.
+  #   Choose a light or dark text color by setting `text_color_light`.
+  #   Any HTML color name or Hex value is valid.
+  
+  # Background color.
+  # color = "navy"
+  
+  # Background gradient.
+  # gradient_start = "DeepSkyBlue"
+  # gradient_end = "SkyBlue"
+  
+  # Background image.
+  # image = "background.jpg"  # Name of image in `static/img/`.
+  # image_darken = 0.6  # Darken the image? Range 0-1 where 0 is transparent and 1 is opaque.
 
+  # Text color (true=light or false=dark).
+  # text_color_light = true  
+  
+[advanced]
+ # Custom CSS. 
+ css_style = ""
+ 
+ # CSS class.
+ css_class = ""
++++

+ 1 - 1
exampleSite/content/home/talks.md

@@ -62,5 +62,5 @@ subtitle = ""
  css_style = ""
  
  # CSS class.
- css_class = ""  
+ css_class = ""
 +++

+ 0 - 17
exampleSite/content/home/talks_featured.md

@@ -1,17 +0,0 @@
-+++
-# Featured Talks widget.
-widget = "talks_featured"  # Do not modify this line!
-active = false  # Activate this widget? true/false
-
-title = "Featured Talks"
-subtitle = ""
-
-# Order that this section will appear in.
-weight = 29
-
-# View.
-#   1 = List
-#   2 = Compact
-#   3 = Card
-view = 3
-+++

+ 61 - 0
layouts/partials/widgets/featured.html

@@ -0,0 +1,61 @@
+{{/* Featured Content Widget */}}
+
+{{/* Initialise */}}
+{{ $ := .root }}
+{{ $st := .page }}
+{{ $items_type := $st.Params.content.page_type | default "post" }}
+{{ $items_count := $st.Params.content.count | default 65535 }}
+{{ $items_sort := $st.Params.content.order| default "desc" }}
+
+{{/* Query */}}
+{{ $query := where (where $.Site.RegularPages "Type" $items_type) "Params.featured" true }}
+
+{{/* Filters */}}
+{{ if $st.Params.content.filters.tag }}
+  {{ $archive_page := $.Site.GetPage (printf "tags/%s" $st.Params.filters.content.tag) }}
+  {{ $query = $query | intersect $archive_page.Pages }}
+{{ end }}
+{{ if $st.Params.content.filters.category }}
+  {{ $archive_page := $.Site.GetPage (printf "categories/%s" $st.Params.filters.content.category) }}
+  {{ $query = $query | intersect $archive_page.Pages }}
+{{ end }}
+{{ if $st.Params.content.filters.publication_type }}
+  {{ $archive_page := $.Site.GetPage (printf "publication_types/%s" $st.Params.content.filters.publication_type) }}
+  {{ $query = $query | intersect $archive_page.Pages }}
+{{ end }}
+
+{{/* Sort */}}
+{{ $sort_by := "" }}
+{{ if eq $items_type "talk" }}
+  {{ $sort_by = "Params.time_start" }}
+{{ else }}
+  {{ $sort_by = "Date" }}
+{{ end }}
+{{ $query = sort $query $sort_by $items_sort }}
+
+{{/* Limit */}}
+{{ $query = first $items_count $query }}
+
+<div class="row">
+  <div class="col-12 col-lg-4 section-heading">
+    <h1>{{ with $st.Title }}{{ . | markdownify | emojify }}{{ end }}</h1>
+    {{ with $st.Params.subtitle }}<p>{{ . | markdownify | emojify }}</p>{{ end }}
+  </div>
+  <div class="col-12 col-lg-8">
+
+    {{ with $st.Content }}<p>{{ . }}</p>{{ end }}
+
+    {{ range $post := $query }}
+      {{ if eq $st.Params.design.view 1 }}
+        {{ partial "li_list" . }}
+      {{ else if eq $st.Params.design.view 3 }}
+        {{ partial "li_card" . }}
+      {{ else if eq $st.Params.design.view 3 | and (eq $st.Type "publication") }}
+        {{ partial "li_citation" . }}
+      {{ else }}
+        {{ partial "li_compact" . }}
+      {{ end }}
+    {{end}}
+
+  </div>
+</div>

+ 15 - 10
layouts/partials/widgets/pages.html

@@ -5,8 +5,13 @@
 {{ $st := .page }}
 {{ $items_type := $st.Params.content.page_type | default "post" }}
 {{ $items_offset := $st.Params.content.offset | default 0 }}
-{{ $items_count := $st.Params.content.count | default 5 }}
-{{ $items_sort := $st.Params.content.order| default "desc" }}
+{{ $items_count := $st.Params.content.count }}
+{{ if eq $items_count 0 }}
+  {{ $items_count = 65535 }}
+{{ else }}
+  {{ $items_count = $items_count | default 5 }}
+{{ end }}
+{{ $items_sort := $st.Params.content.order | default "desc" }}
 
 {{/* Query */}}
 {{ $query := where $.Site.RegularPages "Type" $items_type }}
@@ -29,13 +34,6 @@
   {{ $query = where $query "Params.featured" "!=" true }}
 {{ end }}
 
-{{/* Offset */}}
-{{ if gt $items_offset 0 }}
-  {{ $query = first $items_count (after $items_offset $query) }}
-{{ else }}
-  {{ $query = first $items_count $query }}
-{{ end }}
-
 {{/* Sort */}}
 {{ $sort_by := "" }}
 {{ if eq $items_type "talk" }}
@@ -43,8 +41,15 @@
 {{ else }}
   {{ $sort_by = "Date" }}
 {{ end }}
-
 {{ $query = sort $query $sort_by $items_sort }}
+
+{{/* Offset and Limit */}}
+{{ if gt $items_offset 0 }}
+  {{ $query = first $items_count (after $items_offset $query) }}
+{{ else }}
+  {{ $query = first $items_count $query }}
+{{ end }}
+
 {{ $count := len $query }}
 
 {{/* Localisation */}}

+ 0 - 33
layouts/partials/widgets/publications_featured.html

@@ -1,33 +0,0 @@
-{{ $ := .root }}
-{{ $page := .page }}
-
-<!-- Featured Publications widget -->
-<div class="row">
-  <div class="col-12 col-lg-4 section-heading">
-    <h1>{{ with $page.Title }}{{ . | markdownify }}{{ end }}</h1>
-    {{ with $page.Params.subtitle }}<p>{{ . | markdownify }}</p>{{ end }}
-  </div>
-  <div class="col-12 col-lg-8">
-    {{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ end }}
-
-    {{ if and ($page.Params.publication_type) (ne $page.Params.publication_type "-1") }}
-      {{ $.Scratch.Set "sel_pubs" (where (where (where $.Site.RegularPages "Type" "publication") ".Params.featured" true) ".Params.publication_types" "intersect" (slice $page.Params.publication_type)) }}
-    {{ else }}
-      {{ $.Scratch.Set "sel_pubs" (where (where $.Site.RegularPages "Type" "publication") ".Params.featured" true) }}
-    {{ end }}
-
-    {{ $sel_pubs := $.Scratch.Get "sel_pubs" }}
-    {{ range $sel_pubs }}
-      {{ if eq $page.Params.view 1 }}
-        {{ partial "li_list" . }}
-      {{ else if eq $page.Params.view 3 }}
-        {{ partial "li_card" . }}
-      {{ else if eq $page.Params.view 4 }}
-        {{ partial "li_citation" . }}
-      {{ else }}
-        {{ partial "li_compact" . }}
-      {{ end }}
-    {{ end }}
-
-  </div>
-</div>

+ 0 - 23
layouts/partials/widgets/talks_featured.html

@@ -1,23 +0,0 @@
-{{ $ := .root }}
-{{ $page := .page }}
-
-<!-- Featured Talks widget -->
-<div class="row">
-  <div class="col-12 col-lg-4 section-heading">
-    <h1>{{ with $page.Title }}{{ . | markdownify }}{{ end }}</h1>
-    {{ with $page.Params.subtitle }}<p>{{ . | markdownify }}</p>{{ end }}
-  </div>
-  <div class="col-12 col-lg-8">
-    {{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ end }}
-
-    {{ range (sort (where (where $.Site.RegularPages "Type" "talk") ".Params.featured" true) ".Params.time_start" "desc") }}
-      {{ if eq $page.Params.view 1 }}
-        {{ partial "li_list" . }}
-      {{ else if eq $page.Params.view 3 }}
-        {{ partial "li_card" . }}
-      {{ else }}
-        {{ partial "li_compact" . }}
-      {{ end }}
-    {{ end }}
-  </div>
-</div>