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

archive won't display posts in reverse order (most recent first) #1058

Closed
2 of 5 tasks
taunsquared opened this issue Jun 8, 2017 · 6 comments
Closed
2 of 5 tasks

Comments

@taunsquared
Copy link

  • This is a question about using the theme.
  • This is a feature request.
  • I have updated all gems with bundle update.
  • I have tested locally with bundle exec jekyll build.
  • I believe this to be a bug with the theme --- not Jekyll, GitHub Pages or one of the bundled plugins.

Environment informations

  • Minimal Mistakes version: forked online (v4.4.1)
  • github-pages or jekyll gem version: 'github-pages', I'm doing everything through the browser
  • Operating system: Microsoft 10

Expected behavior

I'm trying to list posts in reverse order, so that the most recent post shows up first.

Steps to reproduce the behavior

Repository for my website is here: https://github.com/taunsquared/taunsquared.github.io

The two pages I'm trying to get to list posts are
/_pages/brainplay.md
and
/_pages/scribbles.md

I took the code directly from Minimal Mistakes' documentation, and I see that it's working correctly on the demo site, so I'm wondering why mine doesn't do the same?

Sorry if this is super obvious, I checked past issues and no one seems to have had this problem before...

@mmistakes
Copy link
Owner

You may want to ask this question on https://talk.jekyllrb.com/ as it's not a theme specific one. I believe your issue is your trying to list collection documents (_brainplay and _scribbles) in reverse cron but they don't have any concept of date like _posts do.

To do that I believe you'd have to add a date field to their YAML front matter and then sort on that in your for loops.

@taunsquared
Copy link
Author

Interesting - where is the date field added on the demo site? I don't see it in the YAML front matter of the posts.

The defaults for _scribbles and _brainplay were copied from _posts, so shouldn't they work the same way?

@mmistakes
Copy link
Owner

mmistakes commented Jun 8, 2017

The date field isn't add to the demo site. That's because what you're seeing there are "posts"... which automatically get date populated by their filename.

You're trying to do that with "collections", which don't share that behavior. Instead I believe they are sorted alphabetically by default. I'd inquire in the Jekyll forum or Stackoverflow as it's a core Jekyll behavior and not theme related.

@taunsquared
Copy link
Author

ok, I see now - so re-naming _scribbles to _post got the reverse chrono listing to work, but now the "year" headers won't render properly in the webpage. Is this also a Jekyll behaviour?

@mmistakes
Copy link
Owner

mmistakes commented Jun 8, 2017

That's because you're using Markdown and it thinks the indented <h2> line should be a "code block", which isn't rendering it as HTML.

Either rename the file to .html instead or collapse the indents to something like this:

{% capture written_year %}'None'{% endcapture %}
{% for post in site.posts %}
{% capture year %}{{ post.date | date: '%Y' }}{% endcapture %}
{% if year != written_year %}
<h2 id="{{ year | slugify }}" class="archive__subtitle">{{ year }}</h2>
{% capture written_year %}{{ year }}{% endcapture %}
{% endif %}
{% include archive-single.html %}
{% endfor %}

@taunsquared
Copy link
Author

Amazing! Thanks for the super fast and helpful replies!

koyumi0601 pushed a commit to koyumi0601/koyumi0601.github.io that referenced this issue Jul 31, 2023
Relatively self-explanatory, pulled out of mmistakes#1058
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants