From 22ed2d0161dceafbcb7d5e7177a35eff23037e68 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sun, 15 Oct 2017 00:47:35 +0100 Subject: [PATCH] Enable widgets to be used on other pages, not only homepage (#300) --- layouts/_default/list.html | 8 ++++++ layouts/index.html | 21 +-------------- layouts/partials/widget_page.html | 27 +++++++++++++++++++ layouts/partials/widgets/posts.html | 6 ++--- layouts/partials/widgets/projects.html | 4 +-- layouts/partials/widgets/publications.html | 6 ++--- .../widgets/publications_selected.html | 4 +-- layouts/partials/widgets/talks.html | 4 +-- layouts/partials/widgets/talks_selected.html | 2 +- 9 files changed, 49 insertions(+), 33 deletions(-) create mode 100644 layouts/partials/widget_page.html diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 477932ad..3783d5ae 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,3 +1,9 @@ +{{ if .Params.widgets }} + +{{ partial "widget_page.html" . }} + +{{ else }} + {{ partial "header.html" . }} {{ partial "navbar.html" . }} @@ -30,3 +36,5 @@ {{ partial "footer_container.html" . }} {{ partial "footer.html" . }} + +{{ end }} diff --git a/layouts/index.html b/layouts/index.html index 8e02c171..e1d285b7 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -1,20 +1 @@ -{{ partial "header.html" . }} -{{ partial "navbar.html" . }} - - - - - -{{ range $index, $page := where .Data.Pages "Type" "home" }} - {{ $params := dict "root" $ "page" $page }} - {{ $widget := printf "widgets/%s.html" ( or $page.Params.widget "custom" ) }} -
-
- {{ partial $widget $params }} -
-
-{{ end }} - - -{{ partial "footer_container.html" . }} -{{ partial "footer.html" . }} +{{ partial "widget_page.html" . }} diff --git a/layouts/partials/widget_page.html b/layouts/partials/widget_page.html new file mode 100644 index 00000000..ca7f4354 --- /dev/null +++ b/layouts/partials/widget_page.html @@ -0,0 +1,27 @@ +{{ partial "header.html" . }} +{{ partial "navbar.html" . }} + + + + +{{ if .IsHome }} + {{ .Scratch.Set "section" "home" }} +{{ else }} + {{ .Scratch.Set "section" .Section }} +{{ end }} +{{ $section := .Scratch.Get "section" }} + + +{{ range $index, $page := where .Data.Pages "Section" $section }} + {{ $params := dict "root" $ "page" $page }} + {{ $widget := printf "widgets/%s.html" ( or $page.Params.widget "custom" ) }} +
+
+ {{ partial $widget $params }} +
+
+{{ end }} + + +{{ partial "footer_container.html" . }} +{{ partial "footer.html" . }} diff --git a/layouts/partials/widgets/posts.html b/layouts/partials/widgets/posts.html index 7069cc95..96d7f0f6 100644 --- a/layouts/partials/widgets/posts.html +++ b/layouts/partials/widgets/posts.html @@ -1,6 +1,6 @@ {{ $ := .root }} {{ $page := .page }} -{{ $posts_len := len (where (where $.Data.Pages "Type" "post") ".Params.notonhomepage" nil) }} +{{ $posts_len := len (where (where $.Site.RegularPages "Type" "post") ".Params.notonhomepage" nil) }}
@@ -23,7 +23,7 @@ {{ with $page.Content }}

{{ . | markdownify }}

{{ end }} {{ if gt (len $page.Params.tags_include) 0 }} - {{ $posts := where (where (where $.Data.Pages "Type" "post") ".Params.tags" "intersect" $page.Params.tags_include) ".Params.notonhomepage" nil }} + {{ $posts := where (where (where $.Site.RegularPages "Type" "post") ".Params.tags" "intersect" $page.Params.tags_include) ".Params.notonhomepage" nil }} {{ $.Scratch.Add "show_post" "1" }} {{ range $post := first $page.Params.count $posts }} @@ -50,7 +50,7 @@ {{ end }} {{ else}} - {{ $posts := where (where $.Data.Pages "Type" "post") ".Params.notonhomepage" nil }} + {{ $posts := where (where $.Site.RegularPages "Type" "post") ".Params.notonhomepage" nil }} {{ $.Scratch.Add "show_post" "1" }} {{ range $post := first $page.Params.count $posts }} diff --git a/layouts/partials/widgets/projects.html b/layouts/partials/widgets/projects.html index d3ef585b..d441e44e 100644 --- a/layouts/partials/widgets/projects.html +++ b/layouts/partials/widgets/projects.html @@ -32,7 +32,7 @@ {{ if eq $page.Params.view 0 }}
- {{ range where $.Data.Pages "Type" "project" }} + {{ range where $.Site.RegularPages "Type" "project" }}
@@ -54,7 +54,7 @@
- {{ range $project := where $.Data.Pages "Type" "project" }} + {{ range $project := where $.Site.RegularPages "Type" "project" }} {{ $.Scratch.Set "project_url" $project.Permalink }} {{ $.Scratch.Set "target" "" }} {{ if $project.Params.external_link }} diff --git a/layouts/partials/widgets/publications.html b/layouts/partials/widgets/publications.html index a37484e1..4ad9adce 100644 --- a/layouts/partials/widgets/publications.html +++ b/layouts/partials/widgets/publications.html @@ -1,6 +1,6 @@ {{ $ := .root }} {{ $page := .page }} -{{ $pubs_len := len (where $.Data.Pages "Type" "publication") }} +{{ $pubs_len := len (where $.Site.RegularPages "Type" "publication") }}
@@ -20,9 +20,9 @@ {{ with $page.Content }}

{{ . | markdownify }}

{{ end }} {{ if and ($page.Params.publication_type) (ne $page.Params.publication_type "-1") }} - {{ $.Scratch.Set "recent_pubs" (where (where $.Data.Pages "Type" "publication") ".Params.publication_types" "intersect" (slice $page.Params.publication_type)) }} + {{ $.Scratch.Set "recent_pubs" (where (where $.Site.RegularPages "Type" "publication") ".Params.publication_types" "intersect" (slice $page.Params.publication_type)) }} {{ else }} - {{ $.Scratch.Set "recent_pubs" (where $.Data.Pages "Type" "publication") }} + {{ $.Scratch.Set "recent_pubs" (where $.Site.RegularPages "Type" "publication") }} {{ end }} {{ $recent_pubs := $.Scratch.Get "recent_pubs" }} diff --git a/layouts/partials/widgets/publications_selected.html b/layouts/partials/widgets/publications_selected.html index 42cce398..48f2153e 100644 --- a/layouts/partials/widgets/publications_selected.html +++ b/layouts/partials/widgets/publications_selected.html @@ -11,9 +11,9 @@ {{ with $page.Content }}

{{ . | markdownify }}

{{ end }} {{ if and ($page.Params.publication_type) (ne $page.Params.publication_type "-1") }} - {{ $.Scratch.Set "sel_pubs" (where (where (where $.Data.Pages "Type" "publication") ".Params.selected" true) ".Params.publication_types" "intersect" (slice $page.Params.publication_type)) }} + {{ $.Scratch.Set "sel_pubs" (where (where (where $.Site.RegularPages "Type" "publication") ".Params.selected" true) ".Params.publication_types" "intersect" (slice $page.Params.publication_type)) }} {{ else }} - {{ $.Scratch.Set "sel_pubs" (where (where $.Data.Pages "Type" "publication") ".Params.selected" true) }} + {{ $.Scratch.Set "sel_pubs" (where (where $.Site.RegularPages "Type" "publication") ".Params.selected" true) }} {{ end }} {{ $sel_pubs := $.Scratch.Get "sel_pubs" }} diff --git a/layouts/partials/widgets/talks.html b/layouts/partials/widgets/talks.html index d2bca7f2..58d4697b 100644 --- a/layouts/partials/widgets/talks.html +++ b/layouts/partials/widgets/talks.html @@ -1,6 +1,6 @@ {{ $ := .root }} {{ $page := .page }} -{{ $talks_len := len (where $.Data.Pages "Type" "talk") }} +{{ $talks_len := len (where $.Site.RegularPages "Type" "talk") }}
@@ -19,7 +19,7 @@
{{ with $page.Content }}

{{ . | markdownify }}

{{ end }} - {{ range first $page.Params.count (where $.Data.Pages "Type" "talk") }} + {{ range first $page.Params.count (where $.Site.RegularPages "Type" "talk") }} {{ if eq $page.Params.list_format 1 }} {{ partial "talk_li_detailed" . }} {{ else }} diff --git a/layouts/partials/widgets/talks_selected.html b/layouts/partials/widgets/talks_selected.html index 2211caa3..c8342508 100644 --- a/layouts/partials/widgets/talks_selected.html +++ b/layouts/partials/widgets/talks_selected.html @@ -10,7 +10,7 @@
{{ with $page.Content }}

{{ . | markdownify }}

{{ end }} - {{ range (where (where $.Data.Pages "Type" "talk") ".Params.selected" true) }} + {{ range (where (where $.Site.RegularPages "Type" "talk") ".Params.selected" true) }} {{ if eq $page.Params.list_format 1 }} {{ partial "talk_li_detailed" . }} {{ else }}