From db9dcf6055c2f98a4873ef2768ed4bf0a11bb374 Mon Sep 17 00:00:00 2001 From: Stephan Kulla Date: Tue, 4 Oct 2016 02:14:37 +0200 Subject: [PATCH] widgets: Direct inclusion of widgets (#45) Replace the long if-else block in index.html with a direct inclusion of the widgets. Signed-off-by: Stephan Kulla --- exampleSite/content/home/publications.md | 2 +- .../content/home/publications_selected.md | 2 +- layouts/index.html | 18 +++--------------- layouts/partials/widgets/about.html | 19 +++++++++++-------- layouts/partials/widgets/contact.html | 17 ++++++++++------- layouts/partials/widgets/custom.html | 2 +- 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/exampleSite/content/home/publications.md b/exampleSite/content/home/publications.md index ecfc21b2..ed445a61 100644 --- a/exampleSite/content/home/publications.md +++ b/exampleSite/content/home/publications.md @@ -7,7 +7,7 @@ draft = false title = "Recent Publications" subtitle = "" -widget = "pubs" +widget = "publications" # Order that this section will appear in. weight = 20 diff --git a/exampleSite/content/home/publications_selected.md b/exampleSite/content/home/publications_selected.md index c7771a20..217ae2b0 100644 --- a/exampleSite/content/home/publications_selected.md +++ b/exampleSite/content/home/publications_selected.md @@ -8,7 +8,7 @@ draft = false title = "Selected Publications" subtitle = "" -widget = "pubs_selected" +widget = "publications_selected" # Order that this section will appear in. weight = 10 diff --git a/layouts/index.html b/layouts/index.html index 9fdf18c9..88c0d496 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -7,21 +7,9 @@ {{ $pubs_selected_len := len (where (where .Data.Pages "Type" "publication") ".Params.selected" true) }} {{ range $index, $page := where .Data.Pages "Type" "home" }} - {{ if eq $page.Params.widget "about" }} - {{ partial "widgets/about" $page }} - {{ else if eq $page.Params.widget "pubs_selected" }} - {{ partial "widgets/publications_selected" (dict "root" $ "page" $page "pubs_selected_len" $pubs_selected_len) }} - {{ else if eq $page.Params.widget "pubs" }} - {{ partial "widgets/publications" (dict "root" $ "page" $page "pubs_selected_len" $pubs_selected_len) }} - {{ else if eq $page.Params.widget "posts" }} - {{ partial "widgets/posts" (dict "root" $ "page" $page) }} - {{ else if eq $page.Params.widget "projects" }} - {{ partial "widgets/projects" (dict "root" $ "page" $page) }} - {{ else if eq $page.Params.widget "contact" }} - {{ partial "widgets/contact.html" $page }} - {{ else }} - {{ partial "widgets/custom.html" $page }} - {{ end }} + {{ $params := dict "root" $ "page" $page "pubs_selected_len" $pubs_selected_len }} + {{ $widget := printf "widgets/%s.html" ( or $page.Params.widget "custom" ) }} + {{ partial $widget $params }} {{ end }} diff --git a/layouts/partials/widgets/about.html b/layouts/partials/widgets/about.html index a61f7dbf..b29d827b 100644 --- a/layouts/partials/widgets/about.html +++ b/layouts/partials/widgets/about.html @@ -1,3 +1,6 @@ +{{ $ := .root }} +{{ $page := .page }} +
@@ -7,17 +10,17 @@
+ style="background-image: url('{{ $.Site.BaseURL }}img/{{ $.Site.Params.avatar }}');">
-

{{ .Site.Params.name }}

-

{{ .Site.Params.role }}

- {{ with .Site.Params.organization }}

{{ . }}

{{ end }} +

{{ $.Site.Params.name }}

+

{{ $.Site.Params.role }}

+ {{ with $.Site.Params.organization }}

{{ . }}

{{ end }}