samarsault / plainwhite-jekyll

A configurable portfolio-style jekyll theme for writers.
https://samarsault.com
MIT License
458 stars 479 forks source link

About tags #8

Open GhostBasenji opened 5 years ago

GhostBasenji commented 5 years ago

There are tags? And they will work (i.e. click to select articles according to labels)?

skoruba commented 4 years ago

Is it possible to add support for filtering posts using tags? Thanks

DotIN13 commented 4 years ago

Is it possible to add support for filtering posts using tags? Thanks

If you want to paginate your posts by tags, you could check Jekyll plugin paginate v2. You should be able to easily filter posts with it.

If not, you can always use liquid like this:

{% for post in site.posts %}
{% if post.tags contains "yourfilter" %}
Your post
{% endif %}
{% endfor %}
Krinkle commented 4 years ago

I'm using this theme as well, and ended up creating my own minimal way to do tags.

I looked at several themes and plugins for Jekyll, but most do this client-side which I think delivers an unacceptable user-experience, often without a permalink to "posts with tag X" as it relied on clicking buttons.

The way I do it is to create an empty placeholder page for each of the tags I want to use, which then gets generated by Jekyll into the list of posts. For most themes, this tag page layout would be similar to your home page, except iterating for post in site.tags[page.tag] instead of or post in site.posts. Note that site.tags[] is a Jekyll built-in – it works by default! (no custom filter logic needed).

Source code: github.com/Krinkle/timotijhof.net

- _posts/
   - 2020-04-04-example.md
   -  …
- _layouts/
   - tag.html
- tags/
   - some.md
   - tags.md
   - here.md

posts/2020-04-04-example.md:

---
layout: post
title: "Example"
tags: some here
---
Content here. …

tags/some.md:

---
layout: tag
title: Something
tag: some
---

Example: https://timotijhof.net/tags/wikipedia/.

skoruba commented 4 years ago

@Krinkle - thanks for sharing your work, I will use your version, I really like your improvements.