๐ [GithubPages] Jekyll hydejack ๊ฒ์๋ฌผ prev, next ๋ฒํผ ์ถ๊ฐ - 5
![๐ [GithubPages] Jekyll hydejack ๊ฒ์๋ฌผ prev, next ๋ฒํผ ์ถ๊ฐ - 5](/assets/img/thumbnail/githubpages-thumbnail.png)
[GithubPages] Jekyll hydejack ํฌ์คํ prev, next ๋ฒํผ ์ถ๊ฐ
๊ฒ์๋ฌผ์ prev, next ๋ฒํผ์ ์ถ๊ฐํจ์ผ๋ก์จ ๊ธ์ ์ฝ์ ํ ๋ค์ ๋ฉ๋ด๋ก ๊ฐ์ง ์๊ณ ์์ฐ์ค๋ฝ๊ฒ ๋ค์ ์ด์ด์ง ๊ธ๋ก ์ด์ด์ง ์ ์๊ณ ํนํ ๋ชจ๋ฐ์ผ ํ๊ฒฝ์์ ํ์ด์ง ํ์ ๋ฒํผ์ ์กด์ฌ ์ ๋ฌด๊ฐ ํฐ ์ฐจ์ด๋ฅผ ๋ง๋ ๋ค. ์ฆ ์ ์ ์ ํธ์์ฑ์ ํฅ์์ํค๊ธฐ ์ํด ๋ฒํผ์ ์ถ๊ฐํ๊ธฐ๋ก ๊ฒฐ์ ํ๋ค.
Jekyll hydejack ํ ๋ง๋ ๊ธฐ๋ณธ์ ์ผ๋ก prev, next ๋ฒํผ ๊ธฐ๋ฅ์ด ์ ๊ณต๋๋ค. ์ํ๋ ํ์ด์ง์ include๋ง ํด์ฃผ๋ฉด ํธ๋ฆฌํ๊ฒ ์ฌ์ฉํ ์ ์๋ค.
โ
_includes/components/pagination.html
# file: `_includes/components/pagination.html`
<h2 class="sr-only">{{ site.data.strings.pagination | default:"Pagination" }}</h2>
<nav class="pagination heading clearfix" role="navigation">
<ul>
<li class="pagination-item older" >
{% assign next_title = site.data.strings.older | default:"Prev" %}
{% assign next_href = page.next.url %}
{% include components/link.html rel="next" title=next_title href=next_href %}
</li>
<li class="pagination-item newer" >
{% assign prev_title = site.data.strings.newer | default:"Next" %}
{% assign prev_href = page.previous.url %}
{% include components/link.html rel="prev" title=prev_title href=prev_href %}
</li>
</ul>
</nav>
โ
_includes/components/link.html
# file: `_includes/components/link.html`
{% if include.href.size > 0 %}
<a
class="{{ include.class }} {{ include.a_class }}"
href="{{ include.href }}"
{% if include.rel %}rel="{{ include.rel }}"{% endif %}
{% if include.property %}property="{{ include.property }}"{% endif %}
>
{{- include.title -}}
</a>
{% else %}
<span class="{{ include.class }} {{ include.span_class }}">{{ include.title }}</span>
{% endif %}
๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณต๋๋ ๊ธฐ๋ฅ์ด๋ค. ํ์ด์ง ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ next.url, prev.url ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ๊ฐ ๋ฒํผ์ ๋งํฌ๋ฅผ ๊ฑธ์ด์ฃผ๋ ๋ฐฉ์์ด๋ค.
[!note] ์ด์ ์ํ๋ ํ์ด์ง์ include๋ง ํด์ฃผ๋ฉด ๋๋ค. ๋๋ list.html, post.html์ include๋ฅผ ํด์ฃผ์๋ค. {%include components/pagination.html %}
# file: list.html
{{ content }}
{% assign posts = site.categories[page.slug] | default:site.tags[page.slug] | default:site.posts %}
{% assign date_formats = site.data.strings.date_formats %}
{% assign list_group_by = date_formats.list_group_by | default:"%Y" %}
{% assign list_entry = date_formats.list_entry | default:"%d %b" %}
{%include components/pagination.html %}
{% assign prev_date = 0 %}
{% if page.no_groups %}<ul class="related-posts">{% endif %}
{% for post in posts %}
{% assign current_date = post.date | date:list_group_by %}
{% unless page.no_groups %}{% if current_date != prev_date %}
{% unless forloop.first %}</ul>{% endunless %}
<h2 id="{{ list_group_by | slugify }}-{{ current_date | slugify }}" class="hr-bottom">{{ current_date }}</h2>
<ul class="related-posts">
{% assign prev_date = current_date %}
{% endif %}{% endunless %}
{% include_cached components/post-list-item.html post=post format=list_entry %}
{% if forloop.last %}</ul>{% endif %}
{% endfor %}
#file: post.html
{% assign version = jekyll.version | split:'.' %}
{% assign major = version[0] | plus:0 %}
{% assign minor = version[1] | plus:0 %}
{% assign patch = version[2] | plus:0 %}
{% include_cached components/post.html post=page no_link_title=true no_excerpt=true hide_image=page.hide_image hide_description=page.hide_description %}
{%include components/pagination.html %}
<!-- {% include components/dingbat.html %} -->
{% assign addons = page.addons | default:site.hydejack.post_addons %}
{% unless addons %}{% assign addons = "about,newsletter,related,random" | split:"," %}{% endunless %}
{% for addon in addons %}
{% case addon %}
{% when 'about' %}
{% include_cached components/about.html author=page.author %}
{% when 'related' %}
{% include if-non-null try="components/related-posts.html" %}
{% when 'comments' %}
{% include body/comments.html %}
{% else %}
{% endcase %}
{% endfor %}
์นดํ ๊ณ ๋ฆฌ ์ ๋ ฌ ๊ธฐ์ค์ ์ํ๋ฒณ์ ๊ฒ์๋ฌผ ์ ๋ ฌ ๊ธฐ์ค์ ๋ ์ง์์ผ๋ก ์ด์ ๊ธ, ๋ค์๊ธ ํ์ด์ง๊ฐ ์ด๋๋๋ค. order์ ์๋ฒ์ ์ ํด์ ์ ๋ ฌ์ ํ๋ ๋ฐฉ๋ฒ๋ ์์ง๋ง ๊ธฐํ๊ฐ ๋๋ฉด ๋์ค์ ํ์ํ๋ฉด ๊ตฌํ ํด๋ณผ ์์ ์ด๋ค.