Skip to content
Permalink
Browse files

Merge pull request #101 from getnikola/tx3TagCloud

Tx3 tag cloud
  • Loading branch information
Kwpolska committed Aug 21, 2015
2 parents 2a95cc2 + 7f1c48f commit de2a60235f9c8f11f2c92e0504976c3f8f138a34
@@ -0,0 +1,11 @@
Use tx3TagCloud to render our tags in a pretty web:

* https://github.com/Tuxes3/tx3TagCloud

**YOU HAVE TO COPY** the template
`tx3_tag_cloud/templates/mako/tags.tmpl` in your THEME folder to make
it work properly. This templates includes the JS and CSS files needed
to render tx3TagCloud and also removes the tags rendered in the old
way.

Something like: `<your-nikola-site>/themes/<your-theme>/templates/`
No changes.
@@ -0,0 +1,30 @@
ul.tx3-tag-cloud
{

}

ul.tx3-tag-cloud li
{
display: block;
float: left;
list-style: none;
margin-right: 4px;
}

ul.tx3-tag-cloud li a
{
display: block;
text-decoration: none;
color: #c9c9c9;
padding: 3px 10px;
}

ul.tx3-tag-cloud li a:hover
{
color: #000000;
-webkit-transition: color 250ms linear;
-moz-transition: color 250ms linear;
-o-transition: color 250ms linear;
-ms-transition: color 250ms linear;
transition: color 250ms linear;
}
@@ -0,0 +1,70 @@
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Tuxes3 wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return Tuxes3
* ----------------------------------------------------------------------------
*/
(function($)
{
var settings;
$.fn.tx3TagCloud = function(options)
{

//
// DEFAULT SETTINGS
//
settings = $.extend({
multiplier : 1
}, options);
main(this);

}

function main(element)
{
// adding style attr
element.addClass("tx3-tag-cloud");
addListElementFontSize(element);
}

/**
* calculates the font size on each li element
* according to their data-weight attribut
*/
function addListElementFontSize(element)
{
var hDataWeight = -9007199254740992;
var lDataWeight = 9007199254740992;
$.each(element.find("li"), function(){
cDataWeight = getDataWeight(this);
if (cDataWeight == undefined)
{
logWarning("No \"data-weight\" attribut defined on <li> element");
}
else
{
hDataWeight = cDataWeight > hDataWeight ? cDataWeight : hDataWeight;
lDataWeight = cDataWeight < lDataWeight ? cDataWeight : lDataWeight;
}
});
$.each(element.find("li"), function(){
var dataWeight = getDataWeight(this);
var percent = Math.abs((dataWeight - lDataWeight)/(lDataWeight - hDataWeight));
$(this).css('font-size', (1 + (percent * settings['multiplier'])) + "em");
});

}

function getDataWeight(element)
{
return parseInt($(element).attr("data-weight"));
}

function logWarning(message)
{
console.log("[WARNING] " + Date.now() + " : " + message);
}

}(jQuery));
@@ -0,0 +1,21 @@
function create_li_tags() {
$.getJSON("/assets/js/tx3_tag_cloud.json", function(data){
var items = [];
$.each(data, function(key, val){
var count = val[0]
var url = val[1]
var posts = val[2]
items.push("<li data-weight='" + count + "'><a href='" + url + "'>" + key + "</a></li>");
});

$("<ul/>", {
"id": "tagcloud",
html: items.join("")
}).appendTo("div.row");

$("#tagcloud").tx3TagCloud({
multiplier: 5 // default multiplier is "1"
});
});
}
create_li_tags();
@@ -0,0 +1,44 @@
## -*- coding: utf-8 -*-
<%inherit file="base.tmpl"/>

<%block name="extra_head">
${parent.extra_head()}
<link href="/assets/css/tx3-tag-cloud.css" rel="stylesheet" type="text/css">
<style>
li {
line-height: 70px !important;
}
</style>
</%block>

<%block name="content">
<h1>${title}</h1>
% if cat_items:
% if items:
<h2>${messages("Categories")}</h2>
% endif
% for text, full_name, path, link, indent_levels, indent_change_before, indent_change_after in cat_hierarchy:
% for i in range(indent_change_before):
<ul class="unstyled">
% endfor
<li><a class="reference badge" href="${link}">${text}</a>
% if indent_change_after <= 0:
</li>
% endif
% for i in range(-indent_change_after):
</ul>
% if i + 1 < len(indent_levels):
</li>
% endif
% endfor
% endfor
% if items:
<h2>${messages("Tags")}</h2>
% endif
%endif
</%block>

<%block name="extra_js">
<script type="text/javascript" src="/assets/js/jquery.tx3-tag-cloud.js"></script>
<script type="text/javascript" src="/assets/js/tx3-tag-cloud.js"></script>
</%block>
@@ -0,0 +1,12 @@
[Core]
Name = tx3TagCloud
Module = tx3_tag_cloud

[Nikola]
MinVersion = 7.6.3

[Documentation]
Author = Manuel Kaufmann
Version = 0.1
Website = http://plugins.getnikola.com/#tx3_tag_cloud
Description = Show tags in a pretty way using tx3TagCloud (https://github.com/Tuxes3/tx3TagCloud)
@@ -0,0 +1,91 @@
# -*- coding: utf-8 -*-

# Copyright © 2015 Manuel Kaufmann

# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the
# Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial portions of
# the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from __future__ import unicode_literals

import os
import json

from nikola import utils
from nikola.plugin_categories import Task


class Tx3TagCloud(Task):

"""Render the tags to be used by tx3TagCloud plugin."""

name = "tx3_tag_cloud"

def set_site(self, site):
"""Set Nikola site."""
return super(Tx3TagCloud, self).set_site(site)

def gen_tasks(self):
"""Render the tag pages and feeds."""
kw = {
"output_folder": self.site.config['OUTPUT_FOLDER'],
'tag_path': self.site.config['TAG_PATH'],
"tag_pages_are_indexes": self.site.config['TAG_PAGES_ARE_INDEXES'],
'category_path': self.site.config['CATEGORY_PATH'],
'category_prefix': self.site.config['CATEGORY_PREFIX'],
"taglist_minimum_post_count": self.site.config['TAGLIST_MINIMUM_POSTS'],
"pretty_urls": self.site.config['PRETTY_URLS'],
"strip_indexes": self.site.config['STRIP_INDEXES'],
}
self.site.scan_posts()

# Copy all the assets to the right places
asset_folder = os.path.join(os.path.dirname(__file__), "files")
for task in utils.copy_tree(asset_folder, kw["output_folder"]):
task["basename"] = str(self.name)
yield task

# Tag cloud json file
tag_cloud_data = {}
for tag, posts in self.site.posts_per_tag.items():
if tag in self.site.config['HIDDEN_TAGS'] or len(posts) < kw['taglist_minimum_post_count']:
continue
tag_cloud_data[tag] = [len(posts), self.site.link(
'tag', tag, self.site.config['DEFAULT_LANG'])]
output_name = os.path.join(kw['output_folder'],
'assets', 'js', 'tx3_tag_cloud.json')

def write_tag_data(data):
"""Write tag data into JSON file, for use in tag clouds."""
utils.makedirs(os.path.dirname(output_name))
with open(output_name, 'w+') as fd:
json.dump(data, fd)

task = {
'basename': str(self.name),
'name': str(output_name)
}

task['uptodate'] = [utils.config_changed(tag_cloud_data, 'nikola.plugins.task.tags:tagdata')]
task['targets'] = [output_name]
task['actions'] = [(write_tag_data, [tag_cloud_data])]
task['clean'] = True
yield task

0 comments on commit de2a602

Please sign in to comment.
You can’t perform that action at this time.