Browse Source

projects widget: Add support for tags containing spaces

Fix case where tag may contain spaces

Allow `tag` to be set directly to the name of an existing tag,
e.g. `tag = "Deep Learning"` rather than requiring the CSS class name
like `tag = ".deep-learning"`.

Close #602
George Cushen 7 years ago
parent
commit
4661fbcce6
2 changed files with 12 additions and 6 deletions
  1. 4 3
      exampleSite/content/home/projects.md
  2. 8 3
      layouts/partials/widgets/projects.html

+ 4 - 3
exampleSite/content/home/projects.md

@@ -26,7 +26,8 @@ view = 1
 filter_default = 0
 
 # Add or remove as many filters (`[[filter]]` instances) as you like.
-# Use "*" tag to show all projects or an existing tag prefixed with "." to filter by specific tag.
+# To show all items, set `tag` to "*".
+# To filter by a specific tag, set `tag` to an existing tag name.
 # To remove toolbar, delete/comment all instances of `[[filter]]` below.
 [[filter]]
   name = "All"
@@ -34,11 +35,11 @@ filter_default = 0
 
 [[filter]]
   name = "Deep Learning"
-  tag = ".deep-learning"
+  tag = "Deep Learning"
 
 [[filter]]
   name = "Other"
-  tag = ".demo"
+  tag = "Demo"
 
 +++
 

+ 8 - 3
layouts/partials/widgets/projects.html

@@ -22,7 +22,12 @@
         <div class="btn-toolbar">
           <div class="btn-group">
             {{ range $idx, $item := $page.Params.filter }}
-              <a href="#" data-filter="{{ .tag }}" class="btn btn-primary btn-large{{ if eq $idx $filter_default }} active{{ end }}">{{ .name }}</a>
+              {{ if or (eq (substr .tag 0 1) "*") (eq (substr .tag 0 1) ".") }}
+                {{ $.Scratch.Set "tag" .tag }}
+              {{ else }}
+                {{ $.Scratch.Set "tag" (printf ".%s" (urlize .tag)) }}
+              {{ end }}
+              <a href="#" data-filter="{{ $.Scratch.Get "tag" }}" class="btn btn-primary btn-large{{ if eq $idx $filter_default }} active{{ end }}">{{ .name }}</a>
             {{ end }}
           </div>
         </div>
@@ -35,7 +40,7 @@
 
     <div class="row isotope projects-container js-layout-row">
         {{ range where $.Site.RegularPages "Type" ($page.Params.folder | default "project") }}
-        <div class="col-md-12 project-item isotope-item {{ delimit .Params.tags " " }}" itemscope itemtype="http://schema.org/CreativeWork">
+        <div class="col-md-12 project-item isotope-item {{ delimit (apply .Params.tags "urlize" ".") " " }}" itemscope itemtype="http://schema.org/CreativeWork">
           <i class="fa fa-files-o pub-icon" aria-hidden="true"></i>
 
           <span class="project-title">
@@ -63,7 +68,7 @@
       {{   $.Scratch.Set "project_url" $project.Params.external_link }}
       {{   $.Scratch.Set "target" "target=\"_blank\"" }}
       {{ end }}
-      <div class="col-xs-12 col-sm-6 col-md-4 col-lg-6 project-item isotope-item {{ delimit .Params.tags " " }}">
+      <div class="col-xs-12 col-sm-6 col-md-4 col-lg-6 project-item isotope-item {{ delimit (apply .Params.tags "urlize" ".") " " }}">
         <div class="card">
           {{ with $project.Params.image_preview }}
           <a href="{{ $.Scratch.Get "project_url" }}" title="" class="card-image hover-overlay"