728x90
반응형
Github Pages 블로그 테마로 minima를 사용하고 있는데 메인 페이지에 페이지네이션 기능이 없었다.
이를 위해 jekyll-paginate
를 _config.yml
과 Gemfile
에 추가하면 된다.
_config.yml
파일에 다음을 추가한다.
...
paginate: 5
paginate_path: "/page/:num/"
plugins:
...
- jekyll-paginate
Gemfile
파일에 다음을 추가한다.
group :jekyll_plugins do
...
gem "jekyll-paginate"
end
그리고 페이지를 넣기 위해 예제 중에 하나를 home.html
에 추가했고,
site.posts
를 paginator.posts
로 변경했다.
{% raw %}{% if paginator.total_pages > 1 %}
<div class="pagination">
{% if paginator.previous_page %}
<a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">« Prev</a>
{% else %}
<span>« Prev</span>
{% endif %}
{% for page in (1..paginator.total_pages) %}
{% if page == paginator.page %}
<em>{{ page }}</em>
{% elsif page == 1 %}
<a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">{{ page }}</a>
{% else %}
<a href="{{ site.paginate_path | prepend: site.baseurl | replace: '//', '/' | replace: ':num', page }}">{{ page }}</a>
{% endif %}
{% endfor %}
{% if paginator.next_page %}
<a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Next »</a>
{% else %}
<span>Next »</span>
{% endif %}
</div>
{% endif %}
{% endif %}{% endraw %}
하지만 다음과 같은 에러가 나면서 동작하지 않았다.
Pagination: Pagination is enabled, but I couldn't find an index.html page to use as the pagination template. Skipping pagination.
여러 시행착오 끝에 index.md
파일을 index.html
파일로 변경하여 위 문제를 해결할 수 있었다.
참고 문헌
반응형