Skip to content

Instantly share code, notes, and snippets.

@jpsilvashy
Forked from biesnecker/config.rb
Created May 17, 2013 21:00
Show Gist options
  • Save jpsilvashy/5601926 to your computer and use it in GitHub Desktop.
Save jpsilvashy/5601926 to your computer and use it in GitHub Desktop.
# add this to your config.rb
ready do
wikitargets = Hash.new
wikiwords = Hash.new
sitemap.resources.select {|p| p.ext == ".html" }.each do |p|
unless p.data['wikitag'].nil?
wikitargets[p.data['wikitag']] = p.url
end
File.open(p.source_file).each_line do |line|
re = /\<\%\=\W?wiki\(.*?,\W?[\'\"](.*?)[\'\"]\)\W?\%\>/
line.scan(re).map(&:first).each do |match|
if wikiwords[match].nil?
wikiwords[match] = 1
else
wikiwords[match] += 1
end
end
end
end
Middleman::Application.set(:wikitargets, wikitargets)
Middleman::Application.set(:wikiwords, wikiwords)
end
helpers do
def wiki(text, tag)
wikitargets = Middleman::Application.defaults[:wikitargets]
if wikitargets[tag].nil?
text
else
target = wikitargets[tag]
"<a href=\"#{target}\">#{text}</a>"
end
end
end
<%
targets = Middleman::Application.defaults[:wikitargets]
words = Middleman::Application.defaults[:wikiwords]
words_sorted = words
.sort_by { |word, count| count }
.select {|w| targets.assoc(w[0]).nil? }
.reverse!
%>
<h4>Unlinked Words</h4>
<table class="table table-bordered">
<% words_sorted.each do |word| %>
<tr>
<td><%= word[0] %></td><td><%= word[1] %></td>
</tr>
<% end %>
</table>
<h4>Available Targets</h4>
<ul>
<% targets.each do |key, value| %>
<li><%= key %><br /><small><%= value %></small></li>
<% end %>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment