Explorar el Código

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 <git.mail@kulla.me>
Stephan Kulla hace 8 años
padre
commit
db9dcf6055

+ 1 - 1
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

+ 1 - 1
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

+ 3 - 15
layouts/index.html

@@ -7,21 +7,9 @@
 <!-- Widgets -->
 {{ $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 }}
 
 <!-- Page Footer -->

+ 11 - 8
layouts/partials/widgets/about.html

@@ -1,3 +1,6 @@
+{{ $ := .root }}
+{{ $page := .page }}
+
 <!-- About/Biography widget -->
 <section id="bio" class="home-section">
   <div class="container">
@@ -7,17 +10,17 @@
         <div id="profile">
 
           <div class="portrait" itemprop="image"
-               style="background-image: url('{{ .Site.BaseURL }}img/{{ .Site.Params.avatar }}');">
+               style="background-image: url('{{ $.Site.BaseURL }}img/{{ $.Site.Params.avatar }}');">
           </div>
 
           <div class="portrait-title">
-            <h2 itemprop="name">{{ .Site.Params.name }}</h2>
-            <h3 itemprop="jobTitle">{{ .Site.Params.role }}</h3>
-            {{ with .Site.Params.organization }}<h3 itemprop="worksFor">{{ . }}</h3>{{ end }}
+            <h2 itemprop="name">{{ $.Site.Params.name }}</h2>
+            <h3 itemprop="jobTitle">{{ $.Site.Params.role }}</h3>
+            {{ with $.Site.Params.organization }}<h3 itemprop="worksFor">{{ . }}</h3>{{ end }}
           </div>
 
           <ul class="social-icon" aria-hidden="true">
-            {{ range .Site.Params.social }}
+            {{ range $.Site.Params.social }}
             <li>
               <a href="{{ .link }}">
                 <i class="{{ .icon_pack | default "fa" }} {{ .icon_pack | default "fa" }}-{{ .icon }} big-icon"></i>
@@ -33,11 +36,11 @@
 
       <div class="col-xs-12 col-md-8" itemprop="description">
 
-        {{ .Content }}
+        {{ $page.Content }}
 
         <div class="row">
 
-          {{ with .Params.interests }}
+          {{ with $page.Params.interests }}
           <div class="col-sm-5">
             <h3>{{ .title | default "Interests" | markdownify }}</h3>
             <ul class="ul-interests">
@@ -48,7 +51,7 @@
           </div>
           {{ end }}
 
-          {{ with .Params.education }}
+          {{ with $page.Params.education }}
           <div class="col-sm-7">
             <h3>{{ .title | default "Education" | markdownify }}</h3>
             <ul class="ul-edu fa-ul">

+ 10 - 7
layouts/partials/widgets/contact.html

@@ -1,18 +1,21 @@
+{{ $ := .root }}
+{{ $page := .page }}
+
 <!-- Contact widget -->
 <section id="contact" class="home-section">
   <div class="container">
 
     <div class="row">
       <div class="col-xs-12 col-md-4 section-heading">
-        <h1>{{ with .Title }}{{ . | markdownify }}{{ end }}</h1>
-        {{ with .Params.subtitle }}<p>{{ . | markdownify }}</p>{{ end }}
+        <h1>{{ with $page.Title }}{{ . | markdownify }}{{ end }}</h1>
+        {{ with $page.Params.subtitle }}<p>{{ . | markdownify }}</p>{{ end }}
       </div>
       <div class="col-xs-12 col-md-8">
-        {{ with .Content }}<p>{{ . | markdownify }}</p>{{ end }}
+        {{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ end }}
 
         <ul class="list-unstyled">
 
-          {{ with .Site.Params.email }}
+          {{ with $.Site.Params.email }}
           <li>
             <i class="fa fa-envelope fa-fw big-icon" aria-hidden="true"></i>
             {{ if and (isset $.Params "autolink") (eq $.Params.autolink false) }}
@@ -23,7 +26,7 @@
           </li>
           {{ end }}
 
-          {{ with .Site.Params.keybase }}
+          {{ with $.Site.Params.keybase }}
           <li>
             <i class="fa fa-lock fa-fw big-icon" aria-hidden="true"></i>
             <span>
@@ -32,7 +35,7 @@
           </li>
           {{ end }}
 
-          {{ with .Site.Params.phone }}
+          {{ with $.Site.Params.phone }}
           <li>
             <i class="fa fa-phone fa-fw big-icon" aria-hidden="true"></i>
             {{ if and (isset $.Params "autolink") (eq $.Params.autolink false) }}
@@ -43,7 +46,7 @@
           </li>
           {{ end }}
 
-          {{ with .Site.Params.address }}
+          {{ with $.Site.Params.address }}
           <li>
             <i class="fa fa-map-marker fa-fw big-icon" aria-hidden="true"></i>
             <span>{{ . }}</span>

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

@@ -1,4 +1,4 @@
-{{ $page := . }}
+{{ $page := .page }}
 {{ $title_words := split $page.Title " " }}
 
 <!-- Custom widget -->