Pagination implementation (FEEDBACK APPRECIATED)

I’m not telling that your code don’t work, it’s obviously a problem on my side, I have to figure it out…

@bjornerik is there an easy other way to see if my version of Hugo works ?

Hi Julien,
I’ve checked in your git fork and your basic foobar example and it does not for me either.

I’m able to go direct to the article links and they are displayed, however I can’t see any pagination on the index.
There is no error on the console. however the index page has only the following code, is this how it was supposed to be?

Ive installed https://github.com/bjornerik/hugo on /opt/hugopagination/hugo

rm -rf public/* && /opt/hugopagination/hugo/hugo server --source=/opt/hugopagination/Hugo-pagination-testing/ --buildDrafts --watch -v --theme=foobar

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us"><head>
  <link href="http://gmpg.org/xfn/11" rel="profile">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">

  
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">

  <title>my new hugo site · </title>

  
  <link rel="stylesheet" href="http://localhost:1313/css/poole.css">
  <link rel="stylesheet" href="http://localhost:1313/css/hyde.css">
  <link rel="stylesheet" href="http://localhost:1313/css/poole-overrides.css">
  <link rel="stylesheet" href="http://localhost:1313/css/hyde-overrides.css">
  <link rel="stylesheet" href="http://localhost:1313/css/hyde-x.css">
  
  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">

  
  <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144-precomposed.png">
  <link href="/favicon.png" rel="icon">

  
  <link href="http://localhost:1313/index.xml" rel="alternate" type="application/rss+xml" title="my new hugo site · ">

  <meta name="description" content="">
  <meta name="keywords" content="">
  
</head>
<body>
<div class="sidebar">
  <div class="container sidebar-sticky">
    <div class="sidebar-about">
      
      <h1></h1>
      
    </div>

    <ul class="sidebar-nav">
      <li class="sidebar-nav-item"><a href="http://localhost:1313/">Blog</a></li>
      
    </ul>

    <ul class="sidebar-nav">
      
      
      
      
      
    </ul>

    <p>Copyright © 2015 <a href="http://localhost:1313/license">License</a><br>
       Powered by <a href="http://hugo.spf13.com">Hugo</a> and <a href="https://github.com/zyro/hyde-x">Hyde-X</a></p>
  </div>
</div>

<div class="content container">
  <div class="posts">
    
  </div>
</div>




<script>document.write('<script src="http://'
        + (location.host || 'localhost').split(':')[0]
		+ ':1313/livereload.js?mindelay=10"></'
        + 'script>')</script><script src="http://localhost:1313/livereload.js?mindelay=10"></script>
</body></html>

As I stated in the pull request, this works on list pages (sections, taxonomies).

Not on the index page.

Something more clever would be needed for a “magic general solution for all lists” (have a look at all the template functions that returns slices, and you will understand). The section/taxonomiy-paginators could be made available to the index, of course.

Hmm… Writing the above, I think I got an idea about how to solve the “pagination on index” puzzle. Let me think about it, I might take a stab on implementing it later today. MAYBE …

I have upgraded my PR to also support paginators on the home page + support for using the available filter/query functions if needed.

I have updated the description on the PR, see:

A live sample is still:

The “paginator” on the front page is kind of ugly, but if proves that it works.

To see how the API has changed, have a look at this commit:

2 Likes

And now it’s merged into master:

2 Likes

@bjornerik I tested the PR and it works like a charm. I’ve updated my example according to the code changes.

@thomasmodeneis If you want to give a try to the demo website you should now see the pager on the index page and on the categories list page.

I’ll try to document the feature

2 Likes

Good to hear.

Just shout if something breaks or could be improved. Easier to fix/change stuff now than later.

I added some quick docs here:

https://github.com/spf13/hugo/blob/master/docs/content/extras/pagination.md

But I’m from Norway (“I’m from Barcelona!”), so please add and improve.

1 Like

What could be the Problem when i get the following error when i want to create pagination in my “blog” section in the file:

> ...theme/layouts/section/blog.html

ERROR .... at <.Paginator.Pages>: Paginator is not a field of struct type *hugolib.Node 

the code i use is very simple

{{range .Paginator.Pages}}{{.Title}}{{end}}

i compiled the master branch from spf13
do i have to create some files somewhere to make it work, or should it work ‘out-of-the-box’?

It’s not released yet.

Your code would work if you built Hugo yourself with the current master branch.

OK, I see you built from master.

Then you’re not running what you’re seeing, a problem with GOPATH or similar. I believe the updated README in Hugo has some tips.

hugo --version will confirm which build you are running.
Best,Steve

Steve Francia
http://stevefrancia.comhttp://spf13.comhttp://twitter.com/spf13

i will go look at the readme my version is:

Hugo Static Site Generator v0.13-DEV buildDate: 2015-02-03T23:46:24+01:00

and it is

hugo version

i think :slight_smile:

In this case it only shows when it was built, not how fresh the source is (if you build with “make install” you will also get a Git hash into the “hugo version”).

And since Paginator is not a field of struct type *hugolib.Node isn’t true for the latest code base, I still believe this must be a version issue.

To help you, either

  1. Rebuild hugo with “make install” (if you’re on Windows, this might be no-go) and rerun hugo version
  2. Put a demo-project out there somewhere that I could look at / test

ha. the problem could be solved by re-setting my go-lang paths - i don’t know why this happened, but the problem was something with the paths in my go installation.

pagination now runs as expected - great job - and thank you for your help :slight_smile:

It’s also working for me! :slight_smile:
Many Thanks for the demo and all the job involved on this!! :slight_smile:
Cheers

Thanks!

Applause is the food on the open sourcers plate :slight_smile:

A little tip:

Even if it’s not released, the up-to-date is available and readable here:

https://github.com/spf13/hugo/blob/master/docs/content/extras/pagination.md

2 Likes