Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't link to pagination pages #93

Closed
kitbeck opened this issue May 26, 2018 · 19 comments
Closed

Can't link to pagination pages #93

kitbeck opened this issue May 26, 2018 · 19 comments

Comments

@kitbeck
Copy link

kitbeck commented May 26, 2018

Setup

I've installed and set up the plugin but it doesn't seem to be working correctly. I have the following:

  1. In guides/index.html I have the following front matter:
---
layout: category
title: Guides Cat
pagination: 
  enabled: true
  category: guides
---
  1. This page uses "_layouts/category" with the following front matter and pagination from the examples:
---
layout: default
pagination: 
  enabled: true
---

<main role="main" class="page">
          
  <h1 class="uk-hidden">Homepage</h1>

  <div class="uk-container uk-margin-large-top uk-margin-large-bottom">

    <div id="pagination">

      <div class="cg-grid">
      <!-- display posts -->
      {% for post in paginator.posts %}


        <div>
          <div class="uk-card uk-card-default uk-box-shadow-medium">
            <div class="uk-card-media-top uk-cover-container">
              <img src="{{ post.hero-img | relative_url }}" alt="" uk-cover>
              <canvas width="600" height="400"></canvas>
            </div>
            <div class="uk-card-body">
              <h2 class="uk-card-title">{{ post.title | escape }}</h2><span class="uk-label">{{ post.categories }}</span>
              {% assign date_format = site.minima.date_format | default: "%b %-d, %Y" %}
              <div class="post-meta">{{ post.date | date: date_format }}</div>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p>
                <a class="uk-button uk-button-default uk-width-1-1" href="{{ post.url | relative_url }}">Read More</a>
              </div>
            </div>
          </div>

        {% endfor %}
      </div>

      <!-- trail -->
      <ul class="uk-pagination uk-flex-center">
      {% if paginator.page_trail %}
      {% if paginator.previous_page %}
        <li class="previous">
          <a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}"><span uk-pagination-previous></span></a>
</li>
      {% endif %}
      {% for trail in paginator.page_trail %}
        <li {% if page.url == trail.path %}class="uk-active"{% endif %}>
          <a href="{{ trail.path | prepend: site.baseurl }}" title="{{trail.title}}">{{ trail.num }}</a>
</li>
      {% endfor %}
      {% if paginator.next_page %}
        <li class="next">
<a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}"><span uk-pagination-next></span></a>
</li>
      {% endif %}
      {% endif %}
      </ul>
<!-- end of pagination test -->  
    <div>{{ page.categories }}</div>

    </div><!-- .cg-grid -->

  </div><!--/ cg-container -->

</main>

The '_layouts/category.html' then uses '_layouts/default.html' as follows

<!DOCTYPE html>
<html lang="{{ page.lang | default: site.lang | default: "en" }}">

  {% include head.html %}

  <body>

    {% include header.html %}
    
    {{ content }}
    
    {% include footer.html %}
    
    <script src="https://code.jquery.com/jquery-3.2.0.min.js" integrity_no="sha256-JAW99MJVpJBGcbzEuXk4Az05s/XyDdBomFqNlM3ic+I=" crossorigin="anonymous"></script>
<!--     <script>window.jQuery || document.write('<script src="lib/jquery_3-2-0.min.js"><\/script>')</script> -->

    <script src="{{ "/assets/js/uikit.min.js" | relative_url }}"></script>
    <script src="{{ "/assets/js/uikit-icons.min.js" | relative_url }}"></script>
    <script src="{{ "/assets/js/main.js" | relative_url }}"></script>

  </body>

</html>

The Problem

If I browse directly to the URL localhost:4000/guides/index.html the pagination works and page is displayed.

If I add a link in my _includes/header.html to this page like so:

{% link guides/index.html %}

I get the following error:

Liquid Exception: Could not find document 'guides/index.html' in tag 'link'. Make sure the document exists and the path is correct. in /_layouts/default.html
...error:
             Error: Could not find document 'guides/index.html' in tag 'link'. Make sure the document exists and the path is correct. 
             Error: Run jekyll build --trace for more information.
[2018-05-26 09:05:38] ERROR `/_includes/header.html' not found.

I've tried simply using

<a href="guides/index.html">Guides</a></li>

and this works, but every time I click on the link I get an extra guides/ added to the path, for example:

guides/guides/guides/guides/index.html

Link has been clicked three times.


I've been trying to get this working myself and I just can't understand what's happening here; everything looks ok to me, and seems analogous with the examples. Not sure if I'm doing something wrong or if this is a bug.

Any help would be greatly appreciated.

@cameronmcefee
Copy link

I ran into this myself and did some debugging. When I inspect the contents of the various page objects, it appears the pagination pages, including the first one that is the one the link points to, have a name value of .html, which I assume is what Jekyll looks for to make the link connection. Given that I imagine a nameless value isn't intentional, I suspect this is a bug.

@cameronmcefee
Copy link

cameronmcefee commented May 30, 2018

Digging further, here's where things break: https://github.com/sverrirs/jekyll-paginate-v2/blob/master/lib/jekyll-paginate-v2/generator/paginationModel.rb#L266

It looks like jekyll-paginate-v2 generates new pages, and uses the value from the indexpage configuration option to generate the name value of the new page, which is an empty string by default. I was able make the link work again by setting indexpage to my original file name, but this would then create (for me) an undesired link because index.html would no longer be the output file name.

@sverrirs would it be possible to do something like set indexPageName differently so it doesn't clobber the object that Jekyll links to?

@kitbeck
Copy link
Author

kitbeck commented May 31, 2018

Thanks for the info. I really appreciate it.

From my config settings it gives the page a name of index.html by default which seems logical. It seems to me that the plugin is generating the pages at least. If I look at my files I can see a directory named "guides" which contains a file named" index.html" but I just can't get my head around why the Liquid link fails - the path is correct and the file exists.

I'm not sure I understand why changing the default indexpage name would make any difference. My file is named "index.html". I could still be missing something here, though.

@cameronmcefee
Copy link

The issue is that the link tag appears to look at the Jekyll data objects, not the actual files. I think the flow looks like this:

  • Your file is parsed, create an entry in site.pages with the value name: guides/index.html
  • Jekyll paginate removes that entry, replaces it with one that has a value name: .html
  • link looks for an entry in the datas that has a value name: guides/index.html

You can check this by removing the links (so the build will work), adding {{ site.pages | map: 'name' | inspect }} to a page somewhere, and then toggle the enabled: true value in your file to see the difference. When disabled, you should see your file in the list, but when enabled, the list is just a bunch of .html values.

@kitbeck
Copy link
Author

kitbeck commented May 31, 2018

When I add the {{ site.pages | map: 'name' | inspect }} to my guides/index.html I see this:

["404.html", "about.md", "main.scss", "terms.md", "feed.xml", "index.html", "index.html", "index.html", "index.html", "index.html", "index.html"]

and when I enabled: false, I get this (the same, but one "index.html" fewer)

["404.html", "about.md", "index.html", "main.scss", "terms.md", "feed.xml", "index.html", "index.html", "index.html", "index.html"]

I don't seem to be getting any .html values in the list. Do you mean just the extension appears in the list with no name attached?

@cameronmcefee
Copy link

I don't seem to be getting any .html values in the list. Do you mean just the extension appears in the list with no name attached?

Ah, hmm… do you have indexpage set? Mine isn't set, which causes the extension-only values. Whatever the case, I'm just describing why I think the behavior is breaking, I'm not proposing a workaroudn.

@kitbeck
Copy link
Author

kitbeck commented May 31, 2018

I just wanted to clarify that you were getting different results to me. I have indexpage set.

@cameronmcefee
Copy link

👍 Hopefully this will be good debug data for someone closer to the problem to fix it.

@kitbeck
Copy link
Author

kitbeck commented May 31, 2018

Hopefully, yes. Many thanks for your help. I think you've pointed me in the right direction. Those multiple index.html files are bugging me a bit. I need to have a think about that.

@cameronmcefee
Copy link

cameronmcefee commented May 31, 2018

To add some clarity, you can map a different value other than name like slug or path which can help you get insight into the files that those objects represent. You can also instead do something like {{ site.pages[0] | inspect }} and then increment the number one at a time to see the complete object for each page.

@kitbeck
Copy link
Author

kitbeck commented May 31, 2018

Brilliant. Thanks. I'll try that tomorrow. I feel like I'm getting somewhere now.

@mkpankov
Copy link

I've come to same problem. What are your workarounds guys? @kitbeck @cameronmcefee

@cameronmcefee
Copy link

I removed the link tags in favor of urls. It's obviously not ideal, but it's low enough priority that the url solution is fine for us.

@kitbeck
Copy link
Author

kitbeck commented Jun 29, 2018

I should have posted this earlier, but I've been a bit busy with other stuff lately. I've got several related projects on the go at the moment, but I should be staying on top of this.

The way I got around it was to use regular html anchors with URLs instead of the link tag as @cameronmcefee did. This works fine. It didn't at first, but I realised that I was missing a leading slash on the href. However, when I click on any of the numbered page links I get a Can't Find Server error, even though the URL seems correct. It works fine if I click on the previous or next page links. It seemed to be working before, and I haven't had much time to look into why it isn't working anymore. I'm using the following for that:

{% for trail in paginator.page_trail %}
     <li {% if page.url == trail.path %}class="uk-active"{% endif %}>
        <a href="{{ trail.path | prepend: site.baseurl }}" title="{{trail.title}}">{{ trail.num }}</a>
    </li>
 {% endfor %}

After following Cameron's advice of using the following:

{{ site.pages[0] | inspect }}

I could see that I was getting the correct URLs generated for each category like this:

For my Guides category

{"layout"=>"category", "title"=>"Guides", "description"=>"Here you'll find all of the latest guides on the latest products and services", "pagination"=>{"enabled"=>true, "category"=>"guides"}, "pagination_info"=>{"curr_page"=>1, "total_pages"=>2}, "content"=>"", "dir"=>"/guides/", "name"=>"index.html", "path"=>"index.html", "url"=>"/guides/index.html"}

and for my Mods category

{"layout"=>"category", "title"=>"Mods Articles", "description"=>"Modifying your guitar can be a very satisfying experience.", "pagination"=>{"enabled"=>true, "category"=>"mods"}, "pagination_info"=>{"curr_page"=>1, "total_pages"=>2}, "content"=>"", "dir"=>"/mods/", "name"=>"index.html", "path"=>"index.html", "url"=>"/mods/index.html"}

So... it looks like it should be working... but it isn't.

I think I've pretty much have decided to ditch this plugin. This seems like a bug but I cannot shake the feeling that I'm doing something wrong. The plugin seems to have been abandoned. I've looked at another plugin (I can't remember what it was called and can no longer find it), but that also seems to have its problems also.

I'm wondering how feasible it is just to do the pagination manually. I'm going to try and get back on to fixing the problem next week.

@ibrado
Copy link
Contributor

ibrado commented Jun 30, 2018

This sounds very similar to (if not the same as) #77 (relative_path / link tag) ..

If so, have you tried PR #79 ? It fixes #77 among others.

@mkpankov
Copy link

mkpankov commented Jul 1, 2018

@ibrado I still have paginator.first_page_path producing incorrect URL. For a tag exclusives put into /exclusives site sub-path via permalink, it creates http://127.0.0.1:4000/exclusives/exclusives/index.html, while the correct one would be http://127.0.0.1:4000/exclusives/index.html or http://127.0.0.1:4000/exclusives/.

@ibrado
Copy link
Contributor

ibrado commented Jul 2, 2018

@mkpankov Hmmm. Could you please doublecheck the config? There might be something causing the tag to be inserted in the URL twice.

I'd like to work on this as it seems related to my other patches. I would appreciate it if someone could setup a test repo (perhaps based on one of the examples) that clearly shows this problem...

@kitbeck
Copy link
Author

kitbeck commented Jul 2, 2018

@mkpankov @ibrado I also had the problem of duplicates in the path, but this was when using html urls instead of link. This was because of a missing leading slash. Every time I clicked on the link it would add to the path like this:

<a href="guides/index.html">Guides</a> gives:

http://127.0.0.1:4000/guides/index.html
http://127.0.0.1:4000/guides/guides/index.html
http://127.0.0.1:4000/guides/guides/guides/index.html

and so on. The link works fine with the leading slash.

<a href="/guides/index.html">Guides</a>

@ibrado I'll create a repo for my site later on this week if that's any use to you for testing.

@kitbeck
Copy link
Author

kitbeck commented Jul 6, 2018

@ibrado @mkpankov @cameronmcefee I'll be creating a repo for testing soon, but I have a question. What is the correct usage of the link tag? Assuming I have links in list items:

<li><a href="{% link pages/about.md %}">About</a></li>

or simply

<li>{% link pages/about.md %}</li>

I've been using the former, but the latter seems more correct after looking at the docs again. I thought I'd cracked it and had been using the link tag incorrectly, but this gives the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants