Blog tags help categorize topics and function as a very basic type of search mechanism
Non Official Guide: https://www.getlektor.com/plugins/lektor-tags/
Quick Note: This is a bit more custom than other plugins. What follows is my implementation. Not for the faint of heart!
lektor plugins add lektor-tags
configs
directory in main project base locationtags.ini
file in configs
directorytags.ini
fileparent = /blog tags_field = tags ignore_missing = true template = tags.html url_path = {{ this.parent.url_path }}tag/{{ tag }} items = this.parent.children.filter(F.tags.contains(tag))
blog-post.ini
model in your models
directory[fields.tags] type = strings
Add this to your blog-post.html
template in your templates
directory
<div class="tags"> <h1>All posts tagged:</h1> <ul> {% for t in this.tags -%} <li> <a href="{{ ('/blog@tag/' ~ t.lower())|url }}"> {{ t }} </a> </li> {% endfor %} </ul> </div>
Add this to your blog.html
template in your templates
directory
{% set tags = site.query('/blog').distinct('tags') %} {% if tags %} <div class="tags"> <h1>By Tag:</h1> <ul> {% for tag in tags|sort %} <li> <a href="{{ ('/blog@tag/' ~ tag.lower())|url }}">{{ tag }}</a> </li> {% else %} <li><em>No items.</em></li> {% endfor %} </ul> </div> {% endif %}
Create tags
directory in your content
directory
contents.lr
file in your tags
directoryAdd this to the contents.lr
file
_model: tags --- title: Tags
Add this to your tags.html
template in your templates
directory
{% extends "layout.html" %} {% block title %}{{ this.title }}{% endblock %} {% block body %} <h1>Tag: {{ this.tag }}</h1> <h1>Items:</h1> <ul> {% for i in this.items %} <li><a href="{{ i|url }}">{{ i._id }}</a></li> {% else %} <li><em>No items.</em></li> {% endfor %} </ul> {% endblock %}
At this point you need to crack open a celebratory beverage and possibly even pull out the peace pipe...