Jekyll pagination on multiple pages - html

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.

Related

Can I generate a references index/ book index from markdown to html (ideally in a static site)?

For an academic project, I would like to make an index. You know, that boring list of words that indicates in which pages every word listed is. This : https://www.pdfindexgenerator.com/what-is-a-book-index/. But for a website.
My goal is, let's say, from Markdown, to generate HTML pages. I would love to do this with a static site, because the content won't evolve every day, and it appears to me that I'd have to parse all the content anyway. Maybe the solution is just using a wiki.
Here's how I would have done it : you write a bunch of text into page.md, inside this text you identify a [word] that you want to see in your index with a specific markup. And then you mention this same [word] with the same markup into otherpage.md.
Then, the generator extracts all the marked words, makes a list, and generates a page with the links to all the references to each marked word.
Word:
page.html
otherpage.html
A reference index. Yay.
What I want is like a simpler version of LaTeX's MakeIndex. Like, closer to this https://wordpress.org/plugins/lexicographer/, but not for definitions, only for internal references.
Pandoc seems to not be supporting indices, maybe because MakeIndex is very complex (but indices are actually, so well, that's fair play) or just because it's made for page numbers and not html links.
So :
I know indices are actually complicated stuff. It's impossible to fully
automatize. My only goal here is to be able to tag the words as I
write and having some computer help to make the listing at the end and render a neat HTML page
with all the links because this part is really boring (like MakeIndex does). But maybe just this
part is impossible and I'd be fine with this.
Is this already implemented somewhere, if it's not impossible? There is plenty of static sites and wikis and stuff, maybe someone thought about it before me, as indices are academic stuff used for CENTURIES. Maybe there's a plugin or a piece of software I just don't know.
I would appreciate just pointers to know where to go to do this if its doable. There is a start here How to generate (book) indexes? but it's too little for me to understand what to do next.
Thanks a lot <3
Using Pelican you can use tags that way.
You can add the following to your index.html template to loop through existing tags :
{% if tags %}
{% for tag, articles in tags %}
{{tag }} :
<ul>
{%for article in articles%}
<li>{{ article.title }}</li>
{% endfor %}
</ul>
{% endfor %}
{% endif %}
Then you will get the following result :
You can't directly tag your text the way you showed though. You'll have to add the tag line in your article's headings :
Title: mytitle
Date: 2020-05-19
Tags: firsttag, othertag
...
You can add this to your index.html template or to tags.html, as you see fit.

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.

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/

Hide an entry from the TOC (table of contents) in Jekyll

I have a site that has a lot of markdown files sorted into appropriate folders.
Jekyll creates their HTML versions and the TOC (table of contents) automatically.
In the _config.yml file I can rename some folders, rearrange them (e.g., if I don't want them sorted alphabetically).
I went through their documentation (http://jekyllrb.com/docs/home/) and I did not see a way to hide a file/folder from the TOC. I hope I have missed something.
What I want is to hide some folders and files from the TOC, but keep them live so people with the correct URL can still read the articles. As to why - legacy stuff I don't want people to find by themselves, but old links must still work and I must keep the information online.
Thus, I cannot use the published: false approach in the heading of the markdown file itself, as this will bring it offline.
Here is an example of my config file:
"someFolderWithChildren":
title: "Name of my folder"
position: 10
"someFolderWithChildren/child-folder-I-want-hidden":
title: "hidden folder 1"
published: false
visible: false
noToc: true
hidden: true # these did not work (I admit to guessing in frustration a lot)
"someFolderWithChildren/another-folder-I-want-hidden":
title: "hidden folder 2"
position: 8
"someFolderWithChildren/folder-i-want-in-the-toc":
title: "some live folder"
position: 1
"someFolderWithChildren/folder-i-want-in-the-toc/child-folder-i-want live":
title: "yet another live foder"
position: 0
I really hope someone can point me in the right direction.
EDIT: to answer the comment and answer - I do not use posts, I am afraid, I am tied with other types of content. Further digging showed that the TOC tree is actually a custom JS widget and it seems I need to look into the way its data source is generated by the existing plugins. Thank you for your assistance and your time.
Well, depends what you exactly want. If you just want to have a unpaginated list of all your posts (TOC), then you a are fine and that can be done easily. But if you want a paginated list, you might be comfortable with a workaround.
Without paginator
In your index.html modify {% for post in site.posts %} to
{% assign posts = site.posts | where:"hide", "false" %}
{% for post in posts %}
...
and add a entry hide:[true,false] in the yaml-header of your posts. You can work with front matter defaults so you just have to set hide:false in the posts you want to exclude.
With paginator
First of all, up to now (Jekyll 2.5.3) and to my knowledge there is no possibility to filter the output of the paginator without using a plugin. But as far, as i remember things might change in the upcoming versions of jekyll.
I would recommend, to work with a collection of documents for the posts that should not show up. Collections are rendered like posts (if you pass the same layout to the collection), but since the paginator only works on posts your documents (posts) in a separate collection won't show up in the paginated list of posts as rendered by the paginator.
I hope, i could help...
It turned out that the site i had had a custom plugin that goes through all md files, creates a list for the TOC and serializes it to a json file that is then used by a client-side treeview widget (kendo ui, btw) for its data source. So, i ended up with a few lines of ruby code that skipped adding the folders i want hidden to that json.
While that worked for me, i see the idea in the posted answer and it is perhaps the way to go in a more oob scenario.