Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/parsiya/Hugo-Octopress.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorparsiya@gmail.com <parsiya@gmail.com>2016-04-10 04:19:30 +0300
committerparsiya@gmail.com <parsiya@gmail.com>2016-04-10 04:19:30 +0300
commit2d9392535e0bedc63baa71212ce558951c3f252d (patch)
tree125d5e30d2e7e38e2778bc992b6384732c1096f1
parent53c4f18c126599b39235f950f1805700a325d4e9 (diff)
Make Recent Posts section in sidebar optional. Fixes #12.
-rw-r--r--README.md6
-rw-r--r--layouts/partials/sidebar.html31
-rw-r--r--sample-config.toml4
3 files changed, 19 insertions, 22 deletions
diff --git a/README.md b/README.md
index 7c61364..d6b5f3f 100644
--- a/README.md
+++ b/README.md
@@ -57,8 +57,8 @@ post = "/blog/:year-:month-:day-:title/"
[params]
- # number of recent posts that will be shown in the sidebar - default is 5
- SidebarRecentLimit = 5
+ # number of recent posts that will be shown in the sidebar - set to 0 or remove to hide this section
+ sidebarRecentLimit = 10
# sidebar customization - passed to markdownify
sidebar_header = "Sidebar Header"
@@ -242,7 +242,7 @@ This menu can be enabled by setting the `sidebar_menu_enabled` to `true` in conf
weight = 1
### <a name="sidebarrecent"></a>Recent posts
-Last x recent posts can be displayed in the sidebar. This number can be set in the config file using the `SidebarRecentLimit`. If this number is not set, last five posts will be displayed.
+Last x recent posts can be displayed in the sidebar. This number can be set in the config file using the `sidebarRecentLimit`. To hide this section either remove `sidebarRecentLimit` from the config file or set it to zero.
## <a name="shortcodes"></a>Shortcodes
Creating [shortcodes](https://gohugo.io/extras/shortcodes/) in Hugo was surprisingly easy. I used two plugins in Octopress that I re-created in Hugo using shortcodes. They add captions to code blocks and images. These shortcodes are located at `hugo-octopress/layouts/shortcodes/`.
diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html
index 51085dd..9ba3904 100644
--- a/layouts/partials/sidebar.html
+++ b/layouts/partials/sidebar.html
@@ -64,22 +64,19 @@
</section>
{{ end }}
- <!-- add recent posts - limit is .Site.Params.SidebarRecentLimit - example copied from https://gohugo.io/templates/go-templates/ -->
- <section class="even">
- <h1>Recent Posts</h1>
-
- <!-- check if the number of recent posts is set in config file, otherwise use 5 -->
- <ul id="recent_posts">
- {{ $.Scratch.Set "numberofrecentposts" 5 }}
- {{ if isset .Site.Params "SidebarRecentLimit" }}
- {{ $.Scratch.Set "numberofrecentposts" .Site.Params.SidebarRecentLimit }}
- {{ end }}
- {{ range first ($.Scratch.Get "numberofrecentposts") .Site.Pages }}
- <li class="post">
- <a href="{{ .RelPermalink }}">{{ .Title }}</a>
- </li>
- {{ end }}
- </ul>
- </section>
+ <!-- add recent posts - limit is .Site.Params.sidebarRecentLimit - example copied from https://gohugo.io/templates/go-templates/ -->
+ <!-- only display this section if sideBarRecentLimit is not zero -->
+ {{ if not (eq .Site.Params.sidebarRecentLimit 0) }}
+ <section class="even">
+ <h1>Recent Posts</h1>
+ <ul id="recent_posts">
+ {{ range first .Site.Params.sidebarRecentLimit .Site.Pages }}
+ <li class="post">
+ <a href="{{ .RelPermalink }}">{{ .Title }}</a>
+ </li>
+ {{ end }}
+ </ul>
+ </section>
+ {{ end }}
</aside>
diff --git a/sample-config.toml b/sample-config.toml
index 290813d..6943e6d 100644
--- a/sample-config.toml
+++ b/sample-config.toml
@@ -65,8 +65,8 @@ post = "/blog/:year-:month-:day-:title/" # change the post URL to look like the
[params]
- # number of recent posts that will be shown in the sidebar - default is 5
- SidebarRecentLimit = 5
+ # number of recent posts that will be shown in the sidebar - set to 0 or remove to hide this section
+ sidebarRecentLimit = 10
# sidebar customization - passed to markdownify
sidebar_header = "Sidebar Header"