Skip to content

Commit

Permalink
Render tag cloud on tags page (#37)
Browse files Browse the repository at this point in the history
Tags page was quite boring and didn't use horizontal space efficiently.
This commit replaces plain tag list with tag cloud that gracefully scales
to any screen (Attila's responsive design principle is not violated).

Details:

- Tags are still sorted alphabetically
- Tags with more articles have bigger font size
- Number of font size steps is defined via TAG_CLOUD_STEPS variable.
  If that variable is not set or is zero, default value of 5 steps is
  used. Stylesheet is written to support up to 10 steps.
- Tag tooltip shows number of articles with that tag

There exists a separate plugin for tag cloud[1], but using it still
requires making changes to the theme. Trivial math calculations can be
done as easily in Jinja as in Python, so the dependency on external
package can and should be avoided.

Screenshots: before [[2]], after [[3]]

[1]: https://github.com/getpelican/pelican-plugins/tree/master/tag_cloud
[2]: https://i.imgur.com/ivZQIxi.png
[3]: https://i.imgur.com/fLNVKpj.png
  • Loading branch information
sio authored and arulrajnet committed Sep 29, 2018
1 parent 6de60cb commit 84e7843
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
12 changes: 12 additions & 0 deletions README.adoc
Expand Up @@ -293,6 +293,18 @@ All image paths are relative from the site root directory. You can also
use absolute URLs for `og_image` and `twitter_image`.


[[tag-cloud]]
=== Tag Cloud

Attila renders tags page as a tag cloud.

Use `TAG_CLOUD_STEPS` configuration variable to specify number of font size
steps for the tag cloud. Default value is 5, stylesheet is written to support
up to 10 steps. If you want more steps, you'll need to configure your CSS
manually (see `CSS_OVERRIDE`)



[[other-configuration]]
=== Other configuration

Expand Down
22 changes: 22 additions & 0 deletions static/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions templates/tags.html
Expand Up @@ -44,11 +44,16 @@ <h1 class="post-title">{{ SITENAME }} - Tags</h1>
{% endblock header %}

{% block content %}
{% for tag, articles in tags|sort %}
<article class="post">
<div class="inner">
<a href="{{ SITEURL }}/{{ tag.url }}">{{ tag }}</a> ({{ articles|count }})
</div>
</article>
{% endfor %}
{% set max_count = (tags|map('last')|map('count')|max) or 1 %}
{% set steps = (TAG_CLOUD_STEPS|default(5, true)) - 1 %}
<article class="post">
<div class="inner tag-cloud">
{% for tag, articles in tags|sort %}
{% set count = articles|count %}
<div class="tag tag-weight-{{ (count/(max_count/steps))|int + 1 }}">
<a href="{{ SITEURL }}/{{ tag.url }}" title="{{ count }} article(s) tagged '{{ tag }}'">{{ tag }}</a>
</div>
{% endfor %}
</div>
</article>
{% endblock content %}

2 comments on commit 84e7843

@lapofran
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jinja2 'max' filter has only been introduced recently in version 2.10. Trying to compile with previous versions of jinja2 yields a "CRITICAL: TemplateAssertionError: no filter named 'max'" error.

@arulrajnet
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lapofran Thanks for let us know. Will add jinja 2.10 as minimum dependency to use.

Please sign in to comment.