Parcourir la source

Enable widgets to be used on other pages, not only homepage (#300)

George Cushen il y a 7 ans
Parent
commit
22ed2d0161

+ 8 - 0
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 @@
 </div>
 {{ partial "footer_container.html" . }}
 {{ partial "footer.html" . }}
+
+{{ end }}

+ 1 - 20
layouts/index.html

@@ -1,20 +1 @@
-{{ partial "header.html" . }}
-{{ partial "navbar.html" . }}
-
-<!-- Flag for jQuery -->
-<span id="homepage" style="display: none"></span>
-
-<!-- Widgets -->
-{{ range $index, $page := where .Data.Pages "Type" "home" }}
-  {{ $params := dict "root" $ "page" $page }}
-  {{ $widget := printf "widgets/%s.html" ( or $page.Params.widget "custom" ) }}
-  <section id="{{ $page.File.TranslationBaseName }}" class="home-section">
-    <div class="container">
-      {{ partial $widget $params }}
-    </div>
-  </section>
-{{ end }}
-
-<!-- Page Footer -->
-{{ partial "footer_container.html" . }}
-{{ partial "footer.html" . }}
+{{ partial "widget_page.html" . }}

+ 27 - 0
layouts/partials/widget_page.html

@@ -0,0 +1,27 @@
+{{ partial "header.html" . }}
+{{ partial "navbar.html" . }}
+
+<!-- Flag for jQuery -->
+<span id="homepage" style="display: none"></span>
+
+{{ if .IsHome }}
+  {{ .Scratch.Set "section" "home" }}
+{{ else }}
+  {{ .Scratch.Set "section" .Section }}
+{{ end }}
+{{ $section := .Scratch.Get "section" }}
+
+<!-- Widgets -->
+{{ range $index, $page := where .Data.Pages "Section" $section }}
+  {{ $params := dict "root" $ "page" $page }}
+  {{ $widget := printf "widgets/%s.html" ( or $page.Params.widget "custom" ) }}
+  <section id="{{ $page.File.TranslationBaseName }}" class="home-section">
+    <div class="container">
+      {{ partial $widget $params }}
+    </div>
+  </section>
+{{ end }}
+
+<!-- Page Footer -->
+{{ partial "footer_container.html" . }}
+{{ partial "footer.html" . }}

+ 3 - 3
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) }}
 
 <!-- Blog Posts widget -->
 <div class="row">
@@ -23,7 +23,7 @@
     {{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ 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 }}

+ 2 - 2
layouts/partials/widgets/projects.html

@@ -32,7 +32,7 @@
     {{ if eq $page.Params.view 0 }}
 
     <div class="row isotope projects-container">
-        {{ range where $.Data.Pages "Type" "project" }}
+        {{ range where $.Site.RegularPages "Type" "project" }}
         <div class="col-md-12 project-item isotope-item {{ delimit .Params.tags " " }}" itemscope itemtype="http://schema.org/CreativeWork">
           <i class="fa fa-files-o pub-icon" aria-hidden="true"></i>
 
@@ -54,7 +54,7 @@
 
     <div class="row isotope projects-container">
 
-      {{ 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 }}

+ 3 - 3
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") }}
 
 <!-- Publications widget -->
 <div class="row">
@@ -20,9 +20,9 @@
     {{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ 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" }}

+ 2 - 2
layouts/partials/widgets/publications_selected.html

@@ -11,9 +11,9 @@
     {{ 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 $.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" }}

+ 2 - 2
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") }}
 
 <!-- Talks widget -->
 <div class="row">
@@ -19,7 +19,7 @@
   <div class="col-xs-12 col-md-8">
     {{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ 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 }}

+ 1 - 1
layouts/partials/widgets/talks_selected.html

@@ -10,7 +10,7 @@
   <div class="col-xs-12 col-md-8">
     {{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ 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 }}