Browse Source

feat(widget): add option to link to archive from Feature widget (#1557)

To add a "See all" link underneath featured content, set `link_to_archive = true` under the `[content]` section in the front matter of the Featured widget.
George 5 years ago
parent
commit
337a554a25
2 changed files with 25 additions and 0 deletions
  1. 3 0
      exampleSite/content/home/featured.md
  2. 22 0
      layouts/partials/widgets/featured.html

+ 3 - 0
exampleSite/content/home/featured.md

@@ -21,6 +21,9 @@ subtitle = ""
   # Page order. Descending (desc) or ascending (asc) date.
   order = "desc"
 
+  # Show a "See all pages" link underneath the featured content?
+  link_to_archive = false
+
   # Filter posts by a taxonomy term.
   [content.filters]
     tag = ""

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

@@ -9,6 +9,7 @@
 
 {{/* Query */}}
 {{ $query := where (where site.RegularPages "Type" $items_type) "Params.featured" true }}
+{{ $archive_page := site.GetPage "Section" $items_type }}
 
 {{/* Filters */}}
 {{ if $st.Params.content.filters.tag }}
@@ -31,6 +32,18 @@
 {{/* Limit */}}
 {{ $query = first $items_count $query }}
 
+{{/* Localisation */}}
+{{ $i18n := "" }}
+{{ if eq $items_type "post" }}
+  {{ $i18n = "more_posts" }}
+{{ else if eq $items_type "talk" }}
+  {{ $i18n = "more_talks" }}
+{{ else if eq $items_type "publication" }}
+  {{ $i18n = "more_publications" }}
+{{ else }}
+  {{ $i18n = "more_pages" }}
+{{ end }}
+
 <div class="row">
   <div class="col-12 col-lg-4 section-heading">
     <h1>{{ with $st.Title }}{{ . | markdownify | emojify }}{{ end }}</h1>
@@ -52,5 +65,14 @@
       {{ end }}
     {{end}}
 
+  {{ if $st.Params.content.link_to_archive }}
+    <div class="see-all">
+      <a href="{{ $archive_page.RelPermalink }}">
+        {{ i18n $i18n | default "See all" }}
+        <i class="fas fa-angle-right"></i>
+      </a>
+    </div>
+  {{ end }}
+
   </div>
 </div>