sverrirs / jekyll-paginate-v2

Pagination Generator for Jekyll 3 (enhanced replacement for the old built-in jekyll-paginate gem) ⛺
https://rubygems.org/gems/jekyll-paginate-v2
MIT License
517 stars 285 forks source link

Avoid using the index file name, when accessing the / path of the website, it shows the content of the blog page #244

Closed y377 closed 1 year ago

y377 commented 1 year ago

It will wrongly display the paging content of the post in my index.md static file, and I am looking for a solution, provided that I need to use: image This way I don't need to write permalink again in every *.md file image 那位请问,不改变下图文件结构,如何修复这个错误!

.
├── about.md
├── assets
│   ├── css
│   └── image
├── blog.md
├── _config.yml
├── _data
│   └── navigation.yml
├── _drafts
├── Gemfile
├── Gemfile.lock
├── _includes
│   ├── footer.html
│   └── navigation.html
├── index.md
├── _layouts
│   └── default.html
├── linux
│   ├── centos.md
│   └── debian.md
├── _posts
│   ├── 2018-08-21-zzz.md
│   ├── 2021-12-12-pt.md
│   ├── 2021-12-16-1.md
│   ├── 2021-12-16-wuxu.md
│   ├── 2022-01-03-testhtml.md
│   └── 2022-01-04-ip.md
├── _sass
│   ├── main.scss
│   └── stylesheets
├── _site
│   ├── 2018-08-21-zzz.html
│   ├── 2021-12-12-pt.html
│   ├── 2021-12-16-1.html
│   ├── 2021-12-16-wuxu.html
│   ├── 2022-01-03-testhtml.html
│   ├── 2022-01-04-ip.html
│   ├── about.html
│   ├── assets
│   ├── blog
│   ├── centos.html
│   ├── feed.xml
│   ├── home.html
│   ├── linux
│   ├── robots.txt
│   ├── sitemap.xml
│   ├── test1.md
│   ├── test2.md
│   └── test3.md
├── test1.md
├── test2.md
└── test3.md

blog.md:

<div class="container">
    <div class="col bg-dark">        
            {% if paginator.total_pages > 1 %}
            <ul class="pagination">
                {% if paginator.previous_page %}
                <li class="page-item">
                    <a class="page-link" aria-label="Previous" href="{{ paginator.previous_page_path | relative_url }}"><span aria-hidden="true">&laquo;</span></a>
                    {% else %}
                </li>
                {% endif %}
                {% for page in (1..paginator.total_pages) %}
                {% if page == paginator.page %}
                <li class="page-item active" aria-current="page"><a class="page-link">{{ page }}</a></li>
                {% elsif page == 1 %}
               <!--  <li class="page-item"><a class="page-link" href="{{ '/' | relative_url }}">{{ page }}</a></li> -->
                {% else %}
                <li class="page-item"><a class="page-link" href="{{ site.paginate_path | relative_url | replace: 'page/:num', page }}">{{ page }}</a></li>
                {% endif %}
                {% endfor %}
                {% if paginator.next_page %}
                <li class="page-item"><a class="page-link" aria-label="Next" href="{{ paginator.next_page_path  }}"><span aria-hidden="true">&raquo;</span></a></li>
                {% else %}
                {% endif %}
            </ul>        
        {% endif %}
    </div>
</div>

now:

image

Thanks for some workarounds!

y377 commented 1 year ago

before: permalink: '/blog/:num/'

after repair :

  permalink: '/page/:num/' # Pages are index.html inside this folder (default)
  #permalink: '/page/:num.html' # Pages are simple html files 
  #permalink: '/page/:num'

Conclusion: This is the code written by the beginner Jekyll in 2021. I used the blog incorrectly. In 2022 this year, I challenged Jekyll again, so there is no change (I copied the semi-finished code before, because the directory structure has changed), so pagination There is no problem with V2 release