Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 133 lines (119 sloc) 3.37 kb
33455297 »
2009-08-28 Refactoring
1 module SiteUtils
2
3 def write_tag_page(dir, tag, count)
4 meta = {}
5 meta[:title] = "Tag: #{tag}"
6 meta[:type] = 'page'
54c9f667 »
2009-09-01 Fixing minor errors in tag and archive pages.
7 meta[:filters_pre] = ['erb']
0f26f3ec »
2009-08-29 Implemented tag feed generation.
8 meta[:feed] = "/tags/#{tag}/"
9 meta[:feed_title] = "Tag '#{tag}'"
33455297 »
2009-08-28 Refactoring
10 meta[:permalink] = tag
11 pl = (count == 1) ? ' is' : 's are'
54c9f667 »
2009-09-01 Fixing minor errors in tag and archive pages.
12 contents = %{
13 <p>#{count} item#{pl} tagged with <em>#{tag}</em>:</p>
14 <ul>
15 <% articles_tagged_with('#{tag}').each do |a| %>
16 <%= render 'dated_article', :article => a %>
17 <% end %>
37edce72 »
2009-08-31 Updated tag pages; Fixed minor JS issues.
18 </ul>
33455297 »
2009-08-28 Refactoring
19 }
20 # Write html page
21 write_item dir/"#{tag}.textile", meta, contents
22 end
23
0f26f3ec »
2009-08-29 Implemented tag feed generation.
24 def write_tag_feed_page(dir, tag, format)
25 f = format.downcase
26 meta = {}
27 meta[:title] = "H3RALD - Tag '#{tag}' (#{format} Feed)"
28 meta[:type] = 'feed'
29 meta[:permalink] = "tags/#{tag}/#{f}"
30 contents = %{<%= #{f}_feed(:articles => articles_tagged_with('#{tag}'))%>}
31 write_item dir/"#{tag}-#{f}.xml", meta, contents
32 end
33
33455297 »
2009-08-28 Refactoring
34 def write_archive_page(dir, name, count)
35 meta = {}
36 meta[:title] = "Archive: #{name}"
37 meta[:type] = 'page'
54c9f667 »
2009-09-01 Fixing minor errors in tag and archive pages.
38 meta[:filters_pre] = ['erb']
33455297 »
2009-08-28 Refactoring
39 meta[:permalink] = name.downcase.gsub /\s/, '-'
40 pl = (count == 1) ? ' was' : 's were'
54c9f667 »
2009-09-01 Fixing minor errors in tag and archive pages.
41 contents = %{
da125edc »
2011-07-30 Regenerated archives.
42 <p>#{count} article#{pl} written in <em>#{name}</em>:</p>
54c9f667 »
2009-09-01 Fixing minor errors in tag and archive pages.
43 <ul>
44 <% articles_by_month.select{|i| i[0] == "#{name}"}[0][1].each do |a|%>
45 <%= render 'dated_article', :article => a %>
46 <% end %>
47 </ul>
33455297 »
2009-08-28 Refactoring
48 }
49 # Write file
50 write_item dir/"#{meta[:permalink]}.textile", meta, contents
51 end
52
53 def write_item(path, meta, contents)
54 path.parent.mkpath
55 (path).open('w+') do |f|
56 f.print "--"
57 f.puts meta.to_yaml
58 f.puts "-----"
59 f.puts contents
60 end
61 end
62
63 end
64
65 module TypoUtils extend SiteUtils
66
67 # Ignored by Nanoc 3
68 def get_filter(db, fid)
69 filter = db[:text_filters].where("id = ?", fid).get(:name).downcase
70 # Multiple filters are not handled (e.g. markdown smartypants)
71 filter = filter.split(' ')[0]
72 # Prepare metadata
73 case filter
74 when 'textile' then
75 return ['redcloth'], 'textile'
76 when 'markdown' then
e762416c »
2013-04-21 Added article on Best Practices for Tech Writers & Editors.
77 return ['redcarpet'], 'markdown'
33455297 »
2009-08-28 Refactoring
78 when 'bbcode' then
79 return ['bbcode'], 'bbcode'
80 else
81 return [], 'txt'
82 end
83 end
84
85 def get_tags(keywords=nil)
86 tags = []
87 if keywords then
88 if keywords.match ',' then
89 tags = keywords.downcase.split(", ")
90 else
91 tags = keywords.downcase.split(" ")
92 end
93 end
94 tags
95 end
96
97 def get_comments(db, aid)
98 dataset = db[:feedback].where("article_id = ? && state LIKE '%ham%'", aid)
99 comments = []
100 dataset.each do |c|
101 comment = {}
102 comment[:id] = c[:id]
103 comment[:author] = c[:author]
104 comment[:body] = c[:body].to_s
105 comment[:url] = c[:url]
106 comment[:date] = c[:published_at]
107 comments << comment
108 end
109 comments
110 end
111
112 def convert_code_blocks(meta, contents)
113 if contents.match /<typo:code/ then
114 # troubles if erb filter is enabled!
115 contents.gsub! /<%/, '&lt;%'
116 contents.gsub! /%>/, '%&gt;'
117 contents.gsub!(/<typo:code lang="([a-zA-Z0-9]+)">/, '<% highlight :\1 do %>')
118 contents.gsub!(/<typo:code>/, '<% highlight :text do %>')
119 contents.gsub!(/<\/typo:code>/, "<% end %>")
120 meta['filters_pre'] = ['erb'].concat meta['filters_pre']
121 end
122 contents
123 end
124
125 def write_page(meta, contents, extension)
126 path = (meta['type'] == 'article') ? Pathname.new(Dir.pwd)/"content/articles/" : Pathname.new(Dir.pwd)/"content/"
127 name = "#{meta['permalink']}.#{extension}"
128 write_item path/name, meta, contents
129 end
130
131 end
132
Something went wrong with that request. Please try again.