diff options
author | bep <bjorn.erik.pedersen@gmail.com> | 2014-12-27 14:11:19 +0100 |
---|---|---|
committer | bep <bjorn.erik.pedersen@gmail.com> | 2015-01-26 12:59:37 +0100 |
commit | 37445bc6aa6273a819724eb25f24f08265d21d4b (patch) | |
tree | ed96a311dd12c5fd7ab6195071a3c12b57da77b0 /helpers/url.go | |
parent | 407e80a9abbb3b22397d1ed6c62ce7cefcdd312a (diff) |
Add pagination support for home page, sections and taxonomies
Two new configuration properties, `Paginate` (default `0`) and `PaginatePath` (default `page`) are added.
Setting `paginate` to a positive value will split the list pages for the home page, sections and taxonomies into chunks of size of the `paginate` property.
A `.Paginator` is provided to help building a pager menu.
There are two ways to configure a `.Paginator`:
1. The simplest way is just to call `.Paginator.Pages` from a template. It will contain the pages for "that page" (`.Data.Pages` will (like today) contain all the pages).
2. Select a sub-set of the pages with the available template functions and pass the slice to `.Paginate` : `{{ range (.Paginate (where .Data.Pages "Type" "post")).Pages }}`
**NOTE:** For a given Node, it's one of the options above. It's perfectly legitimate to iterate over the same pager more than once, but it's static and cannot change.
The `.Paginator` contains enough information to build a full-blown paginator interface.
The pages are built on the form (note: BLANK means no value, i.e. home page):
```
[SECTION/TAXONOMY/BLANK]/index.html
[SECTION/TAXONOMY/BLANK]/page/1/index.html => redirect to [SECTION/TAXONOMY/BLANK]/index.html
[SECTION/TAXONOMY/BLANK]/page/2/index.html
....
```
Fixes #96
Diffstat (limited to 'helpers/url.go')
-rw-r--r-- | helpers/url.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/helpers/url.go b/helpers/url.go index 1b7608178..558ed9c97 100644 --- a/helpers/url.go +++ b/helpers/url.go @@ -16,6 +16,7 @@ package helpers import ( "fmt" "github.com/PuerkitoBio/purell" + "github.com/spf13/viper" "net/url" "path" "strings" @@ -97,6 +98,10 @@ func AddContextRoot(baseUrl, relativePath string) string { return newPath } +func UrlizeAndPrep(in string) string { + return UrlPrep(viper.GetBool("UglyUrls"), Urlize(in)) +} + func UrlPrep(ugly bool, in string) string { if ugly { x := Uglify(SanitizeUrl(in)) |