However, it is 2021 now, the site was last generated/built in 2021 but still in the built website the post is shown under This year’s posts. Why please?
Should it not be visible under another section, namely last year’s posts?
What could be wrong or how can I troubleshoot this? In the original theme’s demo, there is a differentiation between the years:
The code above lumps everything together as This year.
It does not even check what the current year is and whether to show post. But that is okay.
If that snippet is in the theme then you should copy the file to your own repo but edit it.
Take out the first H3 about “this year’s posts”. That heading is inaccurate and not useful (especially if you most recent post was last year)
See if the rest of the code works for you as is - to group posts by year. No filtering needed.
The indentation makes it hard to reason about but I am figuring out the intention.
The code checks the current post in the loop against the next post (which will be older). If they are not in the same year, then it shows the year only as a kind of heading. See %Y
which gives you a sense of when the year starts and all post under it are the same.
Hi @MichaelCurrin. Thanks a lot for your help. I am really lucky to receive your lending of experience and knowledge.
Indeed, as per your comments I now understand better what is going on! Since I had no “this year’s post” last year’s post was stilll showing under “this year’s post”, exactly like you predicted.
Let me try and see if I can fiidle with it according to your suggestions.
I use a Jekyll extension on VS Code and set .md and .html files (in a project) to format as “jekyll”. That gives me syntax highlighting.
It does not format for me.
So if I want to format ie prettify, I change to HTML format and then run the formatter (or save).
That generally helps with long lines and getting HTML overall to indent well. Especially if you have a really long and nested snippet that you want spread over multiple lines.
The downside is that items nested in an if statement and or loop are not indented. That might be okay for you. My personal preference is based on Python etc so I indent manually. And switch back to “jekyll” as a format so that it doesn’t auto format HTML.
Using HTML
<div>
{% for x in y %}
<p>{{ x }}</p>
{% endfor %}
</div>
My custom indent added to that.
<div>
{% for x in y %}
<p>{{ x }}</p>
{% endfor %}
</div>
I tried a Liquid extension and setting Liquid as the format. I didn’t like it though
With regards to the removal of / (remove: "/"), I notice that the author of the theme does this continuously. See e.g. the links from the default sidebar file:
Or the article/keyword search file:
Or the links creation file (I have not well understood this yet):
On the other hand, there is a portion permalink: … in the pages and posts YAML frontmatter.
Is the code wrong then?
Should I change all instances of | remove: "/" into | relative_url? Thanks for any help making me understand.
Yes the code by author is wrong and you should fix it. Removing a forward slash on most URLs anywhere in the URL (ie beginning and middle and end) is very weird and not something that Jekyll sites do.
It might work fine if all your pages are at the same level, but as it will break otherwise.
For example
Given you are on page
/a/b/c.html
And you want to link to
/a/d.html
If your URL is this without any forwardslash it will break.
ad.html
Firstly, it will be a relative URL as ./ad.html
Which means from c.html it will link to
/a/b/c.html/ad.html
Secondly, the / between a and d is important.
Doing this works from anywhere on the site because it is absolute and not relative.
href="/a/d.html"
And if you use relative_url then that will prepend /repo-name, which is needed on GH Pages.
The absolute URL is especially important for assets. As you need to access /css/styles.css an absolute URL from anywhere. If it was css/styles.css in the HTML then the browser would see it as /a/b/c.html/css/styles.css for example.