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

Paginate other than index.md file #21

Closed
bsde1245 opened this issue Apr 9, 2017 · 12 comments
Closed

Paginate other than index.md file #21

bsde1245 opened this issue Apr 9, 2017 · 12 comments

Comments

@bsde1245
Copy link

bsde1245 commented Apr 9, 2017

My site index.md is a static page, and I need pagination in the blog.md file
Here is my index.md

---
# You don't need to edit this file, it's empty on purpose.
# Edit theme's home layout instead if you wanna make some changes
# See: https://jekyllrb.com/docs/themes/#overriding-theme-defaults
layout: page
---

blog.md

---
layout: home
pagination: 
  enabled: true
---

_layout/home.html

<div class="home">

  <h1 class="page-heading">Posts</h1>
  
  {{ content }}

  <ul class="post-list">
    {% for post in paginator.posts %}
      <li>
        <span class="post-meta">{{ post.date | date: "%b %-d, %Y" }}</span>

        <h2>
          <a class="post-link" href="{{ post.url | relative_url }}">{{ post.title | escape }}</a>
        </h2>
      </li>
    {% endfor %}
  </ul>

  {% if paginator.total_pages > 1 %}
<ul>
  {% if paginator.previous_page %}
  <li>
    <a href="{{ paginator.previous_page_path | prepend: site.baseurl }}">Newer</a>
  </li>
  {% endif %}
  {% if paginator.next_page %}
  <li>
    <a href="{{ paginator.next_page_path | prepend: site.baseurl }}">Older</a>
  </li>
  {% endif %}
</ul>
{% endif %}


  <p class="rss-subscribe">subscribe <a href="{{ "/feed.xml" | relative_url }}">via RSS</a></p>

</div>

config.yml

# Welcome to Jekyll!
#
# This config file is meant for settings that affect your whole blog, values
# which you are expected to set up once and rarely edit after that. If you find
# yourself editing this file very often, consider using Jekyll's data files
# feature for the data you need to update frequently.
#
# For technical reasons, this file is *NOT* reloaded automatically when you use
# 'bundle exec jekyll serve'. If you change this file, please restart the server process.

# Site settings
# These are used to personalize your new site. If you look in the HTML files,
# you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
# You can create any custom variable you would like, and they will be accessible
# in the templates via {{ site.myvariable }}.
title: Your awesome title
email: [email protected]
description: > # this means to ignore newlines until "baseurl:"
  Write an awesome description for your new site here. You can edit this
  line in _config.yml. It will appear in your document head meta (for
  Google search results) and in your feed.xml site description.
baseurl: "" # the subpath of your site, e.g. /blog
url: "" # the base hostname & protocol for your site, e.g. http://example.com
twitter_username: jekyllrb
github_username:  jekyll

# Build settings
markdown: kramdown
theme: minima
gems:
  - jekyll-feed
gems: [jekyll-paginate-v2]
exclude:
  - Gemfile
  - Gemfile.lock
  
sass:
 load_paths:
  - _sass
  - bower_components
  
  
############################################################
# Site configuration for the Jekyll 3 Pagination Gem
# The values here represent the defaults if nothing is set
pagination:
  
  # Site-wide kill switch, disabled here it doesn't run at all 
  enabled: true

  # Set to 'true' to enable pagination debugging. This can be enabled in the site config or only for individual pagination pages
  debug: false

  # The default document collection to paginate if nothing is specified ('posts' is default)
  collection: 'posts'

  # How many objects per paginated page, used to be `paginate` (default: 0, means all)
  per_page: 10

  # The permalink structure for the paginated pages (this can be any level deep)
  permalink: '/page/:num/' # Pages are index.html inside this folder (default)
  #permalink: '/page/:num.html' # Pages are simple html files 
  #permalink: '/page/:num' # Pages are html files, linked jekyll extensionless permalink style.

  # Optional the title format for the paginated pages (supports :title for original page title, :num for pagination page number, :max for total number of pages)
  title: ':title - page :num'

  # Limit how many pagenated pages to create (default: 0, means all)
  limit: 0
  
  # Optional, defines the field that the posts should be sorted on (omit to default to 'date')
  sort_field: 'date'

  # Optional, sorts the posts in reverse order (omit to default decending or sort_reverse: true)
  sort_reverse: true

  # Optional, the default category to use, omit or just leave this as 'posts' to get a backwards-compatible behavior (all posts)
  category: 'posts'

  # Optional, the default tag to use, omit to disable
  tag: ''

  # Optional, the default locale to use, omit to disable (depends on a field 'locale' to be specified in the posts, 
  # in reality this can be any value, suggested are the Microsoft locale-codes (e.g. en_US, en_GB) or simply the ISO-639 language code )
  locale: '' 

 # Optional,omit or set both before and after to zero to disable. 
 # Controls how the pagination trail for the paginated pages look like. 
  trail: 
    before: 2
    after: 2

############################################################

My problem is posts are showing on index.md not in blog.md

@naffan2014
Copy link

could u show the document structure ?

@bsde1245
Copy link
Author

bsde1245 commented Apr 13, 2017

.
├── _config.yml
├── index.md
├── blog.md
├── _data
|   └── members.yml
├── _drafts
|   ├── begin-with-the-crazy-ideas.md
|   └── on-simplicity-in-technology.md
├── _includes
|   ├── footer.html
     ├── head.html
|   └── header.html
├── _layouts
|   ├── default.html
    ├── page.html
    ├── home.html
|   └── post.html
├── _posts
|   ├── 2007-10-29-why-every-programmer-should-play-nethack.md
|   └── 2009-04-26-barcamp-boston-4-roundup.md
├── _sass
|   ├── _base.scss
|   └── _layout.scss
├── _site
├── .jekyll-metadata
└── index.html # can also be an 'index.md' with valid YAML Frontmatter

Almost like this. I dont know how to generate document structure. Index.md and blog.md are in root folder.

@naffan2014
Copy link

try touch a document named blog and then move blog.md int o document blog.
after you try this ,leave a message

@sverrirs
Copy link
Owner

Consider adding a _layout/page.html to override the theme's default for your index.md page. In this layout file you can add the pagination logic you have in your _layout/home.html file.

alternatively you can change your index.md to use the

layout: home

@bsde1245
Copy link
Author

I dont understand, I already added layout: page to index.md and layout: home to blog.md as I need home layout in blog.md page.

@sverrirs
Copy link
Owner

Turn on debugging in the _config.yml and see if the blog.md is being recognized as a pagination page.

@bsde1245
Copy link
Author

blog.md recognized, but the problem is blog.md file was not created in _site folder for some reason. When I create blog folder in root directory and there I create index.md file and change paginate path in config file give the correct result. Closed. Please reply to this #10

@Fallenstedt
Copy link

Hey sorry to open this again @sverrirs, but I am encountering a similar issue.

I would like to keep a list of my paginated blog posts on my blog route. Something like http://mysite.com/blog.html

I've followed your typical blog example and am able to paginate my posts. However, the problem is that my index route becomes my blog page. So when I visit http://mysite.com/ I see a list of blog posts rather than my original index route. And if I navigate to http://mysite.com/blog.html, I get a 404.

Is there a way to specify what page I can list my blog posts on? I've followed your suggestion here with no success.

@sverrirs
Copy link
Owner

Hi Alexander,

I'd recommend opening a new bug rather than re-opening old tickets, just because I might miss them in my feed and your questions will go unanswered :)

So, does the layout that is included in your index.html page have any pagination logic in it? Make sure that only the layout that is used by your blog.html has pagination code in it.

Example:

Your index.html page has this front matter:

layout: home

then make sure that _layouts/home.html does not include the {% for post in paginator.posts %} loop but rather the normal {% for post in posts %} loop (or what ever it is you want it to include).

Then assuming your blog.html has this front matter

layout: blog
pagination:
  enabled: true

Then have a file _layouts/blog.html that contains the {% for post in paginator.posts %} loop.

@bsde1234
Copy link

OP didn't set permalink for blog.md I think.

@sylhare
Copy link

sylhare commented May 21, 2020

I had the same issue, I have documented it here sylhare/Type-on-Strap#212 👍

@y377
Copy link

y377 commented Dec 5, 2022

I also have the same problem, it will wrongly display the paging content of the post in my index.md static file, I am looking for a solution, the premise is that I need to use permalink: /:name(); in __config.yml to save me Use permalink: ** in all *.md files; I like clean urls

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

No branches or pull requests

7 participants