Skip to content

Commit

Permalink
Add sidebar ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
tummychow committed Mar 14, 2014
1 parent 77c1f34 commit 5a57507
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ You can alter the content of the custom 404 via [`fixed/404.md`](content/fixed/4

### Sidebar Links

To indicate that a given piece of content should be linked in the sidebar, add a key `sidebar` to the front matter, and set it to `true`. See [`about.md`](content/fixed/about.md) for an example of this. Sidebar links currently appear in an arbitrary order; this will be improved in the future. You can pin content to the sidebar regardless of whether it is a post, or if it is fixed.
To indicate that a given piece of content should be linked in the sidebar, add a key `sidebar` to the front matter, and set it to `true`. See [`about.md`](content/fixed/about.md) for an example of this. You can pin content to the sidebar regardless of whether it is a post, or if it is fixed.

Sidebar content is ordered by weight, specified in the front matter. The lowest weight goes to the top and the greatest weight goes to the bottom. I've included an extra example file, [`altab.md`](content/fixed/altab.md), to demonstrate this feature. If no weight is specified in the front matter, then the weight is zero (this behavior probably comes from the zero-value of integers in Go). You can set negative weights to exploit this feature. Note that the weight must be wrapped in quotes (ie a string). Looks like Hugo converts it to an integer internally.

Note for Jekyll users: In the original Lanyon, any content that had the `page` layout would be added to the sidebar. However, in Lanyon-Hugo, content with the `fixed` type will not be added to the sidebar automatically. You must specify the `sidebar` flag in the front matter.

Expand Down
3 changes: 2 additions & 1 deletion content/fixed/about.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"title": "About",
"sidebar": true
"sidebar": true,
"weight": "1"
}

<p class="message">
Expand Down
7 changes: 7 additions & 0 deletions content/fixed/altab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"title": "Another Fixed Page",
"sidebar": true,
"weight": "2"
}

This is just another example of a fixed page, to demonstrate ordered elements in the sidebar.
2 changes: 1 addition & 1 deletion layouts/chrome/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<a class="sidebar-nav-item {{ if eq .Url "/" }} active {{ end }}" href="/">Home</a>

{{ $thisperma := .Permalink }}
{{ range .Site.Recent }}
{{ range .Site.Recent.ByWeight }}
{{ if isset .Params "sidebar" }}
<a class="sidebar-nav-item {{ if eq .Permalink $thisperma }} active {{ end }}" href="{{ .Permalink }}">{{ .Title }}</a>
{{ end }}
Expand Down

0 comments on commit 5a57507

Please sign in to comment.