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

Simplify year output logic in post_index #166

Merged
merged 2 commits into from Aug 7, 2015

Conversation

Projects
None yet
2 participants
@andreykurenkov
Contributor

andreykurenkov commented Aug 5, 2015

While modifying the base theme to support tags and multiple categories, the year output on post_index got messed up multiple times due to it assuming all posts in site.posts will be posted on the post_index page (no if statements will be added or such). My post_index is modified in more different ways, but I think this particular change would benefit people forking the code in the future.

{% for post in site.posts %}  
    {% unless post.next %}
        <h3>{{ post.date | date: '%Y' }}</h3>
    {% else %}
        {% capture year %}{{ post.date | date: '%Y' }}{% endcapture %}
        {% capture nyear %}{{ post.next.date | date: '%Y' }}{% endcapture %}
        {% if year != nyear %}
            <h3>{{ post.date | date: '%Y' }}</h3>
        {% endif %}
    {% endunless %}
{% capture written_year %}'None'{% endcapture %}
{% for post in site.posts %}  
    {% capture year %}{{ post.date | date: '%Y' }}{% endcapture %}
    {% if year != written_year %}
        <h3>{{ post.date | date: '%Y' }}</h3>
    {% endif %}
    {% capture written_year %}{{ year }}{% endcapture %}
@mmistakes

This comment has been minimized.

Show comment
Hide comment
@mmistakes

mmistakes Aug 7, 2015

Owner

Thanks!

Owner

mmistakes commented Aug 7, 2015

Thanks!

mmistakes added a commit that referenced this pull request Aug 7, 2015

Merge pull request #166 from andreykurenkov/improve_year_output
Simplify year output logic in post_index

@mmistakes mmistakes merged commit e7489a1 into mmistakes:master Aug 7, 2015

MiteshShah added a commit to MiteshShah/miteshshah.github.io that referenced this pull request Aug 8, 2015

jluccisano added a commit to jluccisano/jluccisano.github.io that referenced this pull request May 6, 2017

antonizoon pushed a commit to antonizoon/antonizoon.github.io that referenced this pull request Jul 27, 2018

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