Skip to content

Commit

Permalink
Merge pull request themefisher#82 from rahulpnath/sidebarWidgets
Browse files Browse the repository at this point in the history
Making sidebar content as widgets
  • Loading branch information
somratpro authored May 11, 2020
2 parents 20622df + 09d596e commit b34e5f9
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 45 deletions.
8 changes: 7 additions & 1 deletion exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ link = "plugins/shuffle/shuffle.min.js"
[[params.plugins.js]]
link = "plugins/google-map/gmap.js"



############################## widgets ###############################

[params.widgets]
sidebar = ["recent_posts", "taxonomy_category", "taxonomy_tags"]


############################## navigation ###############################

# main menu
Expand Down
46 changes: 2 additions & 44 deletions layouts/partials/blog-sidebar.html
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
{{- $sidebarWidgets := .Site.Params.widgets.sidebar -}}
<aside class="sidebar">
<!-- Widget Latest Posts -->
<div class="widget widget-latest-post">
<h4 class="widget-title">{{ i18n "latest_posts" }}</h4>
{{ range first 4 (where .Site.Pages "Type" "post") }}
<div class="media">
<a class="pull-left" href="{{ .Permalink }}">
<img class="media-object" src="{{ .Params.Image | relURL }}" alt="{{ .Title }}">
</a>
<div class="media-body">
<h4 class="media-heading"><a href="{{ .Permalink }}">{{ .Title }}</a></h4>
<p>{{ .Summary | truncate 50 }}</p>
</div>
</div>
{{ end }}
</div>
<!-- End Latest Posts -->

<!-- Widget Category -->
<div class="widget widget-category">
<h4 class="widget-title">{{ i18n "categories" }}</h4>
{{- if isset .Site.Taxonomies "categories" }}
{{- if not (eq (len .Site.Taxonomies.categories) 0) }}
<ul class="widget-category-list">
{{- range $name, $items := .Site.Taxonomies.categories }}
<li><a href="{{ `categories/` | relLangURL }}{{ $name | urlize | lower }}">{{ $name | title | humanize }}</a></li>
{{- end }}
</ul>
{{- end }}
{{- end }}
</div> <!-- End category -->

<!-- Widget tag -->
<div class="widget widget-tag">
<h4 class="widget-title">{{ i18n "tags" }}</h4>
{{- if isset .Site.Taxonomies "tags" }}
{{- if not (eq (len .Site.Taxonomies.tags) 0) }}
<ul class="widget-tag-list">
{{- range $name, $items := .Site.Taxonomies.tags }}
<li><a href="{{ `tags/` | relLangURL }}{{ $name | urlize | lower }}">{{ $name | humanize }}</a></li>
{{- end }}
</ul>
{{- end }}
{{- end }}
</div> <!-- End tag -->
{{- partial "widgets/widget_area" ( dict "Widgets" $sidebarWidgets "Scope" . ) -}}
</aside>
14 changes: 14 additions & 0 deletions layouts/partials/widgets/recent_posts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="widget widget-latest-post">
<h4 class="widget-title">{{ i18n "latest_posts" }}</h4>
{{ range first 4 (where .Site.Pages "Type" "post") }}
<div class="media">
<a class="pull-left" href="{{ .Permalink }}">
<img class="media-object" src="{{ .Params.Image | relURL }}" alt="{{ .Title }}">
</a>
<div class="media-body">
<h4 class="media-heading"><a href="{{ .Permalink }}">{{ .Title }}</a></h4>
<p>{{ .Summary | truncate 50 }}</p>
</div>
</div>
{{ end }}
</div>
12 changes: 12 additions & 0 deletions layouts/partials/widgets/taxonomy_category.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="widget widget-category">
<h4 class="widget-title">{{ i18n "categories" }}</h4>
{{- if isset .Site.Taxonomies "categories" }}
{{- if not (eq (len .Site.Taxonomies.categories) 0) }}
<ul class="widget-category-list">
{{- range $name, $items := .Site.Taxonomies.categories }}
<li><a href="{{ `categories/` | relLangURL }}{{ $name | urlize | lower }}">{{ $name | title | humanize }}</a></li>
{{- end }}
</ul>
{{- end }}
{{- end }}
</div>
12 changes: 12 additions & 0 deletions layouts/partials/widgets/taxonomy_tags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="widget widget-tag">
<h4 class="widget-title">{{ i18n "tags" }}</h4>
{{- if isset .Site.Taxonomies "tags" }}
{{- if not (eq (len .Site.Taxonomies.tags) 0) }}
<ul class="widget-tag-list">
{{- range $name, $items := .Site.Taxonomies.tags }}
<li><a href="{{ `tags/` | relLangURL }}{{ $name | urlize | lower }}">{{ $name | humanize }}</a></li>
{{- end }}
</ul>
{{- end }}
{{- end }}
</div>
9 changes: 9 additions & 0 deletions layouts/partials/widgets/widget_area.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- range .Widgets -}}
{{- if eq . "search" -}}
{{- if not ( eq $.Scope.Layout "search" ) -}}
{{- partial ( print "widgets/" . ) $.Scope -}}
{{- end -}}
{{- else -}}
{{- partial ( print "widgets/" . ) $.Scope -}}
{{- end -}}
{{- end -}}

0 comments on commit b34e5f9

Please sign in to comment.