Skip to content

Commit

Permalink
Merge pull request getpelican#1703 from ingwinlu/remove_tag_cloud
Browse files Browse the repository at this point in the history
Remove tag_cloud from Pelican core
  • Loading branch information
justinmayer committed May 13, 2015
2 parents 42d2c4d + 3effe46 commit 8786732
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 79 deletions.
9 changes: 9 additions & 0 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,12 @@ purposes. This can be achieved by explicitly specifying only the
filenames of those articles in ``ARTICLE_PATHS``. A list of such
filenames could be found using a command similar to ``cd content;
find -name '*.md' | head -n 10``.

My tag-cloud is missing/broken since I upgraded Pelican
=======================================================

In an ongoing effort to steamline Pelican, `tag_cloud` generation has been
moved out of the pelican core and into a separate `plugin
<https://github.com/getpelican/pelican-plugins/tree/master/tag_cloud>`_.
See the :ref:`plugins` documentation further information about the
Pelican plugin system.
47 changes: 0 additions & 47 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -625,53 +625,6 @@ This would cause the first page to be written to
``page/{number}`` directories.


Tag cloud
=========

If you want to generate a tag cloud with all your tags, you can do so using the
following settings.

================================================ =====================================================
Setting name (followed by default value) What does it do?
================================================ =====================================================
``TAG_CLOUD_STEPS = 4`` Count of different font sizes in the tag
cloud.
``TAG_CLOUD_MAX_ITEMS = 100`` Maximum number of tags in the cloud.
================================================ =====================================================

The default theme does not include a tag cloud, but it is pretty easy to add one::

<ul class="tagcloud">
{% for tag in tag_cloud %}
<li class="tag-{{ tag.1 }}"><a href="{{ SITEURL }}/{{ tag.0.url }}">{{ tag.0 }}</a></li>
{% endfor %}
</ul>

You should then also define CSS styles with appropriate classes (tag-1 to tag-N,
where N matches ``TAG_CLOUD_STEPS``), tag-1 being the most frequent, and
define a ``ul.tagcloud`` class with appropriate list-style to create the cloud.
For example::

ul.tagcloud {
list-style: none;
padding: 0;
}

ul.tagcloud li {
display: inline-block;
}

li.tag-1 {
font-size: 150%;
}

li.tag-2 {
font-size: 120%;
}

...


Translations
============

Expand Down
32 changes: 2 additions & 30 deletions pelican/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import os
import six
import math
import random
import logging
import shutil
import fnmatch
Expand All @@ -14,7 +12,7 @@
from collections import defaultdict
from functools import partial
from itertools import chain, groupby
from operator import attrgetter, itemgetter
from operator import attrgetter

from jinja2 import (Environment, FileSystemLoader, PrefixLoader, ChoiceLoader,
BaseLoader, TemplateNotFound)
Expand Down Expand Up @@ -554,32 +552,6 @@ def generate_context(self):
self.dates.sort(key=attrgetter('date'),
reverse=self.context['NEWEST_FIRST_ARCHIVES'])

# create tag cloud
tag_cloud = defaultdict(int)
for article in self.articles:
for tag in getattr(article, 'tags', []):
tag_cloud[tag] += 1

tag_cloud = sorted(tag_cloud.items(), key=itemgetter(1), reverse=True)
tag_cloud = tag_cloud[:self.settings.get('TAG_CLOUD_MAX_ITEMS')]

tags = list(map(itemgetter(1), tag_cloud))
if tags:
max_count = max(tags)
steps = self.settings.get('TAG_CLOUD_STEPS')

# calculate word sizes
self.tag_cloud = [
(
tag,
int(math.floor(steps - (steps - 1) * math.log(count)
/ (math.log(max_count)or 1)))
)
for tag, count in tag_cloud
]
# put words in chaos
random.shuffle(self.tag_cloud)

# and generate the output :)

# order the categories per name
Expand All @@ -591,7 +563,7 @@ def generate_context(self):
self.authors.sort()

self._update_context(('articles', 'dates', 'tags', 'categories',
'tag_cloud', 'authors', 'related_posts'))
'authors', 'related_posts'))
self.save_cache()
self.readers.save_cache()
signals.article_generator_finalized.send(self)
Expand Down
2 changes: 0 additions & 2 deletions pelican/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@
'DAY_ARCHIVE_SAVE_AS': '',
'RELATIVE_URLS': False,
'DEFAULT_LANG': 'en',
'TAG_CLOUD_STEPS': 4,
'TAG_CLOUD_MAX_ITEMS': 100,
'DIRECT_TEMPLATES': ['index', 'tags', 'categories', 'authors', 'archives'],
'EXTRA_TEMPLATES_PATHS': [],
'PAGINATED_DIRECT_TEMPLATES': ['index'],
Expand Down

0 comments on commit 8786732

Please sign in to comment.