Skip to content
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
Merged

Simplify year output logic in post_index #166

merged 2 commits into from
Aug 7, 2015

Conversation

andreykurenkov
Copy link
Contributor

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
Copy link
Owner

Thanks!

mmistakes added a commit that referenced this pull request Aug 7, 2015
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
theRealSuperMario pushed a commit to theRealSuperMario/therealsupermario.github.io that referenced this pull request Jul 18, 2020
makaroniame added a commit to makaroniame/makaroniame-old.github.io that referenced this pull request May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants