How to show modified posts first in Jekyll? - jekyll

I know that, Jekyll will show the list of posts depending on the day given in the file like that
2015-01-29-name-of-post.md
On some days later, for example, on 2015-05-12, I have an update on this post and I want Jekyll show it first on the list of "new" posts. I know I can "force" Jekyll to do that by changing the name like
2015-05-12-name-of-post.md
This is not a good idea whereas I want it does automatically. Anyone has other answers?

Here (http://jekyllrb.com/docs/frontmatter/) says there is a special front matter vairable for posts that seem to do what you want:
"date A date here overrides the date from the name of the post. This can be used to ensure correct sorting of posts. A date is specified in the format YYYY-MM-DD HH:MM:SS +/-TTTT; hours, minutes, seconds, and timezone offset are optional."
So looks like you could add date to your post's front matter and change it that way.

Jekyll's 'last modified at' plugin/Gem does exactly what you want: https://github.com/gjtorikian/jekyll-last-modified-at
It determines the last time a post (or page) file was modified on the disk, and adds a last_modified_at feature to the elements without changing their post dates or urls. Apart from displaying the post.last_modified_at field wherever you like it, you should then also be able to list the posts in the order of their last modification:
<ul>
{% assign posts = site.posts | sort: 'last_modified_at' %}
{% for post in posts %}
<li>{{ post.title }} (original post date: {{ post.date }})</li>
{% endfor %}
</ul>
Note that the plugin does not work on github pages, so you'll have to build your pages locally. (Due to the way github pages are built, even if they whitelisted the Gem it would show the time of the last push for all files rather than their last edit date.)

Related

Jekyll include content from another collection

Hope someone can help me, I'm really stuck working with collections.
At the moment I have two setup, :guides :places.
What I'd like to do is setup a place once in the places collection and include attributes like location, website, image etc.
Then I want to be able to reference the place in the guide collection. My guide could be coffee shops so I can reference the place one and pull in all the content. A place might be in a few different guides so I'll be able to update the image of the place and automatically update all the guides.
I've tried using the following:-
{% include_relative coffee-shop.md %}
But it tries to find it within the same collection? Not sure how I can get out of the current collection and grab this from the place collection?
Any advice would be awesome!
Working with your:
collections:
places:
...
guides:
...
You'll get the matching data in site.places and site.guides. If you just want to insert the content, you'd have to do something like:
{% assign place = site.places | where: "name","Toronto" | first %}
{{ place.content }}

Jekyll Internal Post Links

This is a pretty niche problem, but... I run a blog that runs on Jekyll and I post very regularly. To keep my editing sane I regularly archive posts, and those archived posts get a pretty strict structure. But, I go a full year before archiving.
Where this hurts is in links to other posts. I used to be able to absolutely reference the file name (per jekyll markdown internal links), but this appears to be being deprecated:
Deprecation: A call to '{% post_url 2018-09-06-peppermint %}' did not match a post using the new matching method of checking name (path-date-slug) equality. Please make sure that you change this tag to match the post's name exactly.
Now, if I have to include the full path to the file, then when I archive my posts for the year I have to parse all of the posts for the entire year and update any links between them to include the new file path for their archived location, defeating the point of using this tool at all. A direct link to the page would actually be better, given that I change my URL structure less often.
Is there a better solution for internal links that doesn't depend on the file structure, allowing a file to be moved without having to update every link to that file?
Example File structure:
_posts
-2018
-post1
-post2
-etc
-Archive
-2017
-2016
If there's no better answer, I may just have to go back to using absolute external links.
Solution 1. Use your own include
Create an post_url.html file and write this:
{% include post_url.html slug="2018-09-06-peppermint" %}
The include (called post_url.html) should find the post with the right slug and echo the link, like this:
{% assign link = site.posts | where:'slug',include.slug %}
{{ link[0].title }}
Solution 2. Search and replace
You have to parse posts? A simple search and replace on all files, looking for (/2018/ and replace with (/Archive/2018/ should do the trick (if you use markdown links). This should take just a few seconds.

Hide some posts in Jekyll, but allow their content to be included elsewhere

I am using Jekyll to generate a static website. I currently display posts by category on their own pages using some simple liquid syntax:
{%- for post in site.categories.whatever -%}
{{ post.content }}
{%- endfor -%}
However, the posts are still generated independently (in /category/year/month/day/title.html per the Jekyll defaults), which I don't need.
How can I prevent each post from generating its own independent HTML page while still being able to loop over site.categories and include them in a page with multiple posts? Setting published: false unfortunately prevents the posts from being added to site.categories, which breaks the above for loop. permalink: none also has no apparent effect. Excluding the pages (via exclude: [xyzzy, plugh, ...] in _config.yml) does the same. A previous StackOverflow answer suggested setting the permalink to an existing page, but in Jekyll 3.6.2 this simply overwrites that page.
My current hack is to set the permalink for that category to /.trash which is then easy to ignore when uploading the published site, but it seems like there ought to be a better way.
It seems that simply setting the permalink to the empty string (mostly) works! With
defaults:
- scope:
path: category/_posts
values:
permalink: ''
in your _config.yml, none of those posts will have a generated page.
Unfortunately, the pages are still included in site.documents and similar pages, but at least it suppresses the output. I sadly think that it's not possible to exclude these from site.documents, but it's easy enough to avoid them in Liquid.

Display Multiple posts on Github pages using poole

I am trying to set up my blog on Github pages using Jekyll, as per the following template. https://github.com/poole/poole
The problem is, it displays only one post on the page, whereas I want it to display multiple posts on a single page, with the title and some part of the content. Has anyone dealt with this issue before? Any help will be appreciated. Thanks.
After going through the Jekyll documentation, I did figure it out. I will post what I did so that it helps anyone trying to do the same.
In config.yml, change the value of paginate from 1 to 5(or whatever number of posts you want to display)
In index.html, change {{ post.content }} to {{ post.excerpt }}. By default it displays the first paragraph. You can learn about excerpts and how to set a different separator here. http://jekyllrb.com/docs/posts/

Jekyll pagination on multiple pages

I am new to html/css but am attempting to create a blog using Jekyll and this theme I found here https://github.com/rosario/kasper
The homepage index.html has the all the posts in a paginated list. This is cool. However i would like to group my posts into different categories and have an additional page for each group which would have a paginated list of just posts of that groups.
I can create the additional pages but can't get the lists using any sort of variant of the code in index.html but specifying a group.
Is this possible?
There is also another way to do that. Is using Jekyll Collections.
For each collection you can have a _folder containing your markdown files. Then you can call your posts within this folder from whatever page you want.
To do so, you will need to: 1st. add your collections to your _config.yml file:
collections:
example1:
permalink: /example1/:path/
example2:
permalink: /example2/:path/
example3:
permalink: /example3/:path/
2nd. create a folder to each collection, like: _example1, _example2 and _example3
3rd. create a new html file from which you call each collection:
{% for article in site.example1 %} ... {% endfor %}
That's it! I hope to have helped. If I have, please mark this answer as useful. If you need more assistance, feel free to contact me.
You should share your code with your answer if you want a more detailed answer for your question. As far as I understood you are having trouble with creating a list of blog posts that are all same category. If this is correct then you can achieve it by using liquid for loop. If you look into the code on your index.html it has this for loop
{% for post in paginator.posts %}
If you modify it like below
{% for post in site.categories.comedy %}
Where comedy is a category name. This way we access the category within the site object and get all the posts under this category. If you place similar loops on your separate pages while changing the category names you can have different category lists on different pages. Make sure that you correctly input the category names in your post's front matter. If I succeeded in answering your question please mark the answer as correct.