From c0a446c1125fa748e794b8db6517fb36bf0e379a Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Sat, 11 Jun 2022 19:24:02 +0200 Subject: [PATCH] Refactor into generic list --- layouts/index.html | 2 +- layouts/partials/generic-list.html | 30 ++++++++++++++++++++++++++++++ layouts/partials/snippet-list.html | 25 ++----------------------- 3 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 layouts/partials/generic-list.html diff --git a/layouts/index.html b/layouts/index.html index f092e13..4a00120 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -1,5 +1,5 @@ {{ define "main" }} -{{ partial "snippet-list" (dict "showAllArticles" true) }} +{{ partial "snippet-list" (dict "showViewAllButton" true) }} {{ end }} {{ define "aside" }} diff --git a/layouts/partials/generic-list.html b/layouts/partials/generic-list.html new file mode 100644 index 0000000..d3e8e32 --- /dev/null +++ b/layouts/partials/generic-list.html @@ -0,0 +1,30 @@ +{{ $labelSingular := index $ "labelSingular" }} +{{ $labelPlural := or (index $ "labelPlural") (print $labelSingular "s") }} +{{ $maximumListSize := or (index $ "maximumListSize") 3 }} +{{ $pageType := index $ "pageType"}} +{{ $viewAllHref := or (index $ "viewAllHref") (print "/" $labelPlural) }} + +
+
+

Latest {{ $labelPlural | title }}

+ + {{ if index $ "showViewAllButton" }} + + {{ end }} +
+
+
    + {{ range ( first $maximumListSize (where site.RegularPages "Type" $pageType).ByDate.Reverse ) }} +
  • + {{ index $ +
    +

    {{ .Title }}

    + {{ .Date.Format "January 2, 2006" }} +
    +
  • + {{ end }} +
+
+
diff --git a/layouts/partials/snippet-list.html b/layouts/partials/snippet-list.html index fcc5806..e950664 100644 --- a/layouts/partials/snippet-list.html +++ b/layouts/partials/snippet-list.html @@ -1,24 +1,3 @@ -
-
-

Latest Articles

+{{ $showViewAllButton := or (index $ "showViewAllButton") false }} - {{ if index $ "showAllArticles" }} - - {{ end }} -
-
-
    - {{ range ( first 3 (where site.RegularPages "Type" "snippets").ByDate.Reverse ) }} -
  • - Article Topic -
    -

    {{ .Title }}

    - {{ .Date.Format "January 2, 2006" }} -
    -
  • - {{ end }} -
-
-
+{{ partial "generic-list" (dict "labelSingular" "snippet" "pageType" "snippets" "showViewAllButton" $showViewAllButton) }}