1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,114 @@ |
0 |
+# Tag Cloud for Octopress, modified by pf_miles, for use with utf-8 encoded blogs(all regexp added 'u' option). |
|
1 |
+# modified by alswl, tag_cloud -> category_cloud |
|
2 |
+# ======================= |
|
3 |
+# |
|
4 |
+# Description: |
|
5 |
+# ------------ |
|
6 |
+# Easy output tag cloud and category list. |
|
7 |
+# |
|
8 |
+# Syntax: |
|
9 |
+# ------- |
|
10 |
+# {% tag_cloud [counter:true] %} |
|
11 |
+# {% category_list [counter:true] %} |
|
12 |
+# |
|
13 |
+# Example: |
|
14 |
+# -------- |
|
15 |
+# In some template files, you can add the following markups. |
|
16 |
+# |
|
17 |
+# ### source/_includes/custom/asides/tag_cloud.html ### |
|
18 |
+# |
|
19 |
+# <section> |
|
20 |
+# <h1>Tag Cloud</h1> |
|
21 |
+# <span id="tag-cloud">{% tag_cloud %}</span> |
|
22 |
+# </section> |
|
23 |
+# |
|
24 |
+# ### source/_includes/custom/asides/category_list.html ### |
|
25 |
+# |
|
26 |
+# <section> |
|
27 |
+# <h1>Categories</h1> |
|
28 |
+# <ul id="category-list">{% category_list counter:true %}</ul> |
|
29 |
+# </section> |
|
30 |
+# |
|
31 |
+# Notes: |
|
32 |
+# ------ |
|
33 |
+# Be sure to insert above template files into `default_asides` array in `_config.yml`. |
|
34 |
+# And also you can define styles for 'tag-cloud' or 'category-list' in a `.scss` file. |
|
35 |
+# (ex: `sass/custom/_styles.scss`) |
|
36 |
+# |
|
37 |
+# Licence: |
|
38 |
+# -------- |
|
39 |
+# Distributed under the [MIT License][MIT]. |
|
40 |
+# |
|
41 |
+# [MIT]: http://www.opensource.org/licenses/mit-license.php |
|
42 |
+# |
|
43 |
+module Jekyll |
|
44 |
+ |
|
45 |
+ class CategoryCloud < Liquid::Tag |
|
46 |
+ |
|
47 |
+ def initialize(tag_name, markup, tokens) |
|
48 |
+ @opts = {} |
|
49 |
+ if markup.strip =~ /\s*counter:(\w+)/iu |
|
50 |
+ @opts['counter'] = ($1 == 'true') |
|
51 |
+ markup = markup.strip.sub(/counter:\w+/iu,'') |
|
52 |
+ end |
|
53 |
+ super |
|
54 |
+ end |
|
55 |
+ |
|
56 |
+ def render(context) |
|
57 |
+ lists = {} |
|
58 |
+ max, min = 1, 1 |
|
59 |
+ config = context.registers[:site].config |
|
60 |
+ category_dir = config['root'] + config['category_dir'] + '/' |
|
61 |
+ categories = context.registers[:site].categories |
|
62 |
+ categories.keys.sort_by{ |str| str.downcase }.each do |category| |
|
63 |
+ count = categories[category].count |
|
64 |
+ lists[category] = count |
|
65 |
+ max = count if count > max |
|
66 |
+ end |
|
67 |
+ |
|
68 |
+ html = '' |
|
69 |
+ lists.each do | category, counter | |
|
70 |
+ url = category_dir + category.gsub(/_|\P{Word}/u, '-').gsub(/-{2,}/u, '-').downcase |
|
71 |
+ style = "font-size: #{100 + (60 * Float(counter)/max)}%" |
|
72 |
+ html << "<a href='#{url}' style='#{style}'>#{category}" |
|
73 |
+ if @opts['counter'] |
|
74 |
+ html << "(#{categories[category].count})" |
|
75 |
+ end |
|
76 |
+ html << "</a> " |
|
77 |
+ end |
|
78 |
+ html |
|
79 |
+ end |
|
80 |
+ end |
|
81 |
+ |
|
82 |
+ class CategoryList < Liquid::Tag |
|
83 |
+ |
|
84 |
+ def initialize(tag_name, markup, tokens) |
|
85 |
+ @opts = {} |
|
86 |
+ if markup.strip =~ /\s*counter:(\w+)/iu |
|
87 |
+ @opts['counter'] = ($1 == 'true') |
|
88 |
+ markup = markup.strip.sub(/counter:\w+/iu,'') |
|
89 |
+ end |
|
90 |
+ super |
|
91 |
+ end |
|
92 |
+ |
|
93 |
+ def render(context) |
|
94 |
+ html = "" |
|
95 |
+ config = context.registers[:site].config |
|
96 |
+ category_dir = config['root'] + config['category_dir'] + '/' |
|
97 |
+ categories = context.registers[:site].categories |
|
98 |
+ categories.keys.sort_by{ |str| str.downcase }.each do |category| |
|
99 |
+ url = category_dir + category.gsub(/_|\P{Word}/u, '-').gsub(/-{2,}/u, '-').downcase |
|
100 |
+ html << "<li><a href='#{url}'>#{category}" |
|
101 |
+ if @opts['counter'] |
|
102 |
+ html << " (#{categories[category].count})" |
|
103 |
+ end |
|
104 |
+ html << "</a></li>" |
|
105 |
+ end |
|
106 |
+ html |
|
107 |
+ end |
|
108 |
+ end |
|
109 |
+ |
|
110 |
+end |
|
111 |
+ |
|
112 |
+Liquid::Template.register_tag('category_cloud', Jekyll::CategoryCloud) |
|
113 |
+Liquid::Template.register_tag('category_list', Jekyll::CategoryList) |
0 | 7 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,42 @@ |
0 |
+# include the MD5 gem, this should be part of a standard ruby install |
|
1 |
+require 'digest/md5' |
|
2 |
+ |
|
3 |
+module Jekyll |
|
4 |
+ |
|
5 |
+ class Gravatar < Liquid::Tag |
|
6 |
+ |
|
7 |
+ def initialize(tag_name, size, token) |
|
8 |
+ super |
|
9 |
+ @size = size.strip |
|
10 |
+ end |
|
11 |
+ |
|
12 |
+ def render(context) |
|
13 |
+ # get the site config variables |
|
14 |
+ site_config = context.registers[:site].config |
|
15 |
+ |
|
16 |
+ # get the email address from the site config |
|
17 |
+ email_address = site_config['gravatar_email'] |
|
18 |
+ # change the email address to all lowercase |
|
19 |
+ email_address = email_address.downcase |
|
20 |
+ |
|
21 |
+ # create an md5 hash from the email address |
|
22 |
+ gravatar_hash = Digest::MD5.hexdigest(email_address) |
|
23 |
+ |
|
24 |
+ # compile the full Gravatar URL |
|
25 |
+ image_src = "http://www.gravatar.com/avatar/#{gravatar_hash}" |
|
26 |
+ |
|
27 |
+ # append size query to URL if provided in tag |
|
28 |
+ unless @size.empty? |
|
29 |
+ image_src = image_src+"?s=#{@size}" |
|
30 |
+ end |
|
31 |
+ |
|
32 |
+ # output the full Gravatar URL |
|
33 |
+ image_src |
|
34 |
+ end |
|
35 |
+ |
|
36 |
+ end |
|
37 |
+ |
|
38 |
+end |
|
39 |
+ |
|
40 |
+# register the "gravatar_image" tag |
|
41 |
+Liquid::Template.register_tag('gravatar_image', Jekyll::Gravatar) |
|
0 | 42 |
\ No newline at end of file |