Last active
March 11, 2019 06:56
-
-
Save 867/f60b20625e8afa88e1a641208d80e057 to your computer and use it in GitHub Desktop.
公式ブログ用:Nunjucks-news2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set news_category1 = 'pro' %} | |
{% set news_category2 = '' %} | |
{% set news_current = 1 %} | |
{% block contents -%} | |
<section> | |
<header> | |
<h2>ニュース>製品情報</h2> | |
</header> | |
{# ここからニュース一覧 #} | |
<ul> | |
{% if news_category1 != '' and news_category2 == '' -%} | |
{% for category1, items in news | groupby('category1') -%} | |
{% if category1 == news_category1 -%} | |
{% for item in items -%} | |
{% if loop.index > (news_current - 1) * 10 and loop.index <= news_current * 10 -%} | |
<li> | |
<dl> | |
<dt>{{ item.date }}</dt> | |
{% if item.category1 == 'ir' -%} | |
<dd>IR</dd> | |
{% elif item.category1 == 'company' -%} | |
<dd>企業情報</dd> | |
{% elif item.category1 == 'pro' -%} | |
<dd>製品情報</dd> | |
{% endif -%} | |
<dd><a href="{{ item.url }}">{{ item.title }}</a></dd> | |
</dl> | |
</li> | |
{% endif -%} | |
{% endfor -%} | |
{% endif -%} | |
{% endfor -%} | |
{% endif -%} | |
</ul> | |
{# ここからページング #} | |
<div> | |
<ul> | |
{% if news_category1 != '' and news_category2 == '' -%} | |
{% for category1, items in news | groupby('category1') -%} | |
{% if category1 == news_category1 -%} | |
{% set pages = (items.length / 10) | round(0, "ceil") -%} | |
{% for i in range(1, pages + 1) -%} | |
{% if i == 1 -%} | |
{% if news_current == 1 -%} | |
<li><em>1</em></li> | |
{% else -%} | |
<li><a href="./">1</a></li> | |
{% endif -%} | |
{% else -%} | |
{% if news_current == i -%} | |
<li><em>{{ i }}</em></li> | |
{% else -%} | |
<li><a href="./page{{ i }}.html">{{ i }}</a></li> | |
{% endif -%} | |
{% endif -%} | |
{% endfor -%} | |
{% endif -%} | |
{% endfor -%} | |
{% endif -%} | |
</ul> | |
</div> | |
</section> | |
{%- endblock -%} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment