Skip to content

Commit

Permalink
Added tags support for themes (#2720)
Browse files Browse the repository at this point in the history
* Added tags support for themes

* Docs: updated theme creation documentation, adding the tags optional variable

* Changed taxonomy name to `theme-tags`

* Revert "Changed taxonomy name to `theme-tags`"

This reverts commit 2afd6db.

* resolving

* resolve

* Search by tags not shown if no content with `theme-tags` taxonomy is provided
  • Loading branch information
harrymkt authored Dec 10, 2024
1 parent 3b5c878 commit c19abf8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ description = "Everything you need to make a static site engine in one binary."
compile_sass = true
build_search_index = true

taxonomies = [
{ name = "theme-tags"}
]

[search]
index_format = "elasticlunr_json"

Expand Down
2 changes: 2 additions & 0 deletions docs/content/documentation/themes/creating-a-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ following fields:
```toml
name = "my theme name"
description = "A classic blog theme"
# An optional tags to allow quick search
tags = []
license = "MIT"
homepage = "https://github.com/getzola/hyde"
# The minimum version of Zola required
Expand Down
17 changes: 17 additions & 0 deletions docs/templates/theme-tags/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "index.html" %}

{% block extra_nav_class %}{% endblock extra_nav_class %}
{% block extra_content_class %}content--reversed{% endblock extra_content_class %}

{% block title %}Themes | {{ super() }} {% endblock title %}

{% block content %}
<h1>Tags</h1>
{% set section = get_section(path = "themes/_index.md") %}
<p><a href="{{ get_url(path = "themes") }}">All themes ({{ section.pages | length }}</a></p>
<ul style="list-style-type: none;">
{% for t in terms %}
<li><a href="{{ t.permalink }}">{{ t.name }}({{ t.page_count }}</a></li>
{% endfor %}
</ul>
{% endblock content %}
22 changes: 22 additions & 0 deletions docs/templates/theme-tags/single.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "index.html" %}

{% block extra_nav_class %}{% endblock extra_nav_class %}
{% block extra_content_class %}content--reversed{% endblock extra_content_class %}

{% block title %}Themes | {{ super() }} {% endblock title %}

{% block content %}
<div class="themes-container">
{% block theme_content %}
<h1>Zola themes in {{ term.name }}</h1>
<div class="themes">
{% for theme in term.pages %}
<a class="theme" href="{{theme.permalink}}">
<img src="{{theme.permalink}}screenshot.png" alt="Screenshot of {{theme.title}}">
<span>{{theme.title}}</span>
</a>
{% endfor %}
</div>
{% endblock theme_content %}
</div>
{% endblock content %}
10 changes: 10 additions & 0 deletions docs/templates/theme.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ <h1>{{ page.title }}</h1>
{% if page.extra.demo %}
<p><b>Live Demo:</b> <a href="{{page.extra.demo}}">{{page.extra.demo}}</a></p>
{% endif %}
{% if page.taxonomies["theme-tags"] %}
<div>
<p>Tags:</p>
<ul style="list-style-type: none;">
{% for t in page.taxonomies["theme-tags"] %}
{% set term = get_taxonomy_term(kind="theme-tags", term = t) %}
<li><a href="{{ term.permalink }}">{{ term.name }}</a></li>
{% endfor %}
</div>
{% endif %}
<p><b>Last updated:</b> {{page.extra.updated }}</p>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions docs/templates/themes.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<div class="themes-container">
{% block theme_content %}
<h1>Zola themes</h1>
{% set tax = get_taxonomy(kind = "theme-tags") %}
{% if tax and tax.items | length > 0 %}
<p><a href="{{ get_url(path = "theme-tags") }}">Search by tags</a></p>
{% endif %}
<div class="themes">
{% for theme in section.pages %}
<a class="theme" href="{{theme.permalink}}">
Expand Down

0 comments on commit c19abf8

Please sign in to comment.