Skip to content

Commit

Permalink
Adds generator to reformat [%card] into annotated card urls.
Browse files Browse the repository at this point in the history
resolves #7.
  • Loading branch information
jbnicolai committed May 2, 2014
1 parent a4a5b68 commit 94aa4d5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions web/_plugins/cardLinkGenerator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Jekyll

class CardLinkGenerator < Generator

def card_link(name, text = '')
if text.nil? || !defined?(text) || (text == '') then
text = name.split("-").map(&:capitalize).join(" ")
end
"<a href=\"#{name}\" title=\"The Xebia Essentials [#{name}] Card\">#{text}</a>"
end

def generate(site)
site.pages.each do |page|
related = Set.new page.data['related']
page.content.scan(/\[%([^]]*)\](?:\(([^)]*)\))?/).each do |match|
related.add(match[0])
page.content = page.content.sub(/\[%([^]]*)\](?:\(([^)]*)\))?/, card_link(match[0], match[1]))

This comment has been minimized.

Copy link
@jbnicolai

jbnicolai May 2, 2014

Author

Not very happy about searching for the same regex twice. Performance seems fine, but suggestions are welcome.

end
page.data['related'] = related.to_a
end
end
end

end

0 comments on commit 94aa4d5

Please sign in to comment.