Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements tag cloud sorting #1598

Closed

Conversation

magnunleno
Copy link

For those (like me) who don't like the tag cloud to be randomly organized, I've implemented some sorting options:

  • Alphabetically;
  • Alphabetically Reverse (descending);
  • Size;
  • Size Reverse (descending);
  • Random.

For those (like me) who don't like the tag cloud to be randomly
organized, I've implemented some sorting options:

* Alphabetically;
* Alphabetically Reverse (descending);
* Size;
* Size Reverse (descending);
* Random.
@ingwinlu
Copy link
Contributor

Hi,
this was always possible in themes, i.e. jinja2's build in sort filter.

Might be worth adding this as a plugin instead of an addition to pelican.

@magnunleno
Copy link
Author

Hi,

Despite it being possible to implement it in themes (as I used to do in my site), it will cause the site's building time to grow considerably. Since the sorting will be done in the theme, the tag cloud list sorting will be repeatedly executed for every generated page. Nowadays my site has something around 2000 pages, and it's taking 180190 seconds to compile. With this feature implemented my site build time went down to 3040 seconds.

Thanks anyway.

@ingwinlu
Copy link
Contributor

set in my base.html

{% set tag_cloud = tag_cloud|sort(attribute='0')%}
{% set tag_cloud_rev = tag_cloud|sort(attribute='0',reverse=True)%}
{% set tag_cloud_size = tag_cloud|sort(attribute='1')%}
{% set tag_cloud_size_rev = tag_cloud|sort(attribute='1',reverse=True)%}
{% macro list_tag_cloud(tags) -%}
<ul>
    {% for tag in tags %}
        <li class="tag-{{ tag.1 }}">
            <a href="{{ SITEURL }}/{{ tag.0.url }}">
                {{ tag.0 }}
            </a>
        </li>
    {% endfor %}
</ul>
{%- endmacro %}

used like this in tags.html: here (only quickly hacked it together, i don't use a tag list usually)

{% block content %}
<div class="row">
    <div class="col-lg-12">
    <h2>tag_cloud</h2>
    {{ list_tag_cloud(tag_cloud)}}
    <h2>tag_cloud_rev</h2>
    {{ list_tag_cloud(tag_cloud_rev)}}
    <h2>tag_cloud_size</h2>
    {{ list_tag_cloud(tag_cloud_size)}}
    <h2>tag_cloud_size_rev</h2>
    {{ list_tag_cloud(tag_cloud_size_rev)}}
    </div>
</div>
{% endblock %}

no noticable slowdown on a rpi, 125s vs 130s
Done: Processed 37 article(s), 1 draft(s) and 1 page(s) in 129.08 seconds.

then again, there is use in having this functionality as a plugin.

Edit: that should help with generating on every site, since it should only be sorted once

@magnunleno
Copy link
Author

Setting it in base.html is even worse, it will sort the tag_cloud even when it isn't needed. In my theme I set the sorting to occur only when the tag cloud is included.

Your haven't had any noticeable slowdowns because you have a "small" site. My site has nearly 180 articles and something around 400 tags.

@ingwinlu
Copy link
Contributor

ah i thought the jinja environment would take care of caching then

@magnunleno
Copy link
Author

As far as I'm concerned it doesn't cache, since the tagcloud is altered and is never "written back" to the context that pelican uses.

@ingwinlu
Copy link
Contributor

that might be worth considering together with #1566.

feel like it needs tests even though you are basically just testing the build in sorting function.

@avaris
Copy link
Member

avaris commented Apr 19, 2015

Maybe tag_cloud should become a plugin.

@ingwinlu
Copy link
Contributor

that certainly is an even better way forward

On 20 April 2015 at 01:20, Deniz Turgut notifications@github.com wrote:

Maybe tag_cloud should become a plugin.


Reply to this email directly or view it on GitHub
#1598 (comment).

@iKevinY
Copy link
Member

iKevinY commented Apr 20, 2015

I agree with turning tag_cloud into a plugin, since tag clouds aren't really a core feature for blogs, nor are they relevant at all to regular static sites.

@ingwinlu
Copy link
Contributor

I will prepare a PR then

@ingwinlu ingwinlu mentioned this pull request Apr 20, 2015
3 tasks
@ingwinlu
Copy link
Contributor

@justinmayer pewpew here as well

@justinmayer
Copy link
Member

Since tag clouds are now out of core and implemented via a plugin, it would appear this pull request is no longer relevant. (Thanks for the reminder, @ingwinlu.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants