public
Last active

Jekyll plugin that allows posting links to Debian BTS.

  • Download Gist
debbugs.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
# A Liquid tag for Jekyll sites that allows posting links to Debian BTS.
# by: Andrew Shadura
#
# Example usage: {% bts 123456 %} //adds a link to a bug #123456
#
# Or, you can just use debian/changelog format, like closes: #123456
# Launchpad bugs are also supported.
 
require 'cgi'
require './plugins/post_filters'
 
module Jekyll
class DebbugsTag < Liquid::Tag
def initialize(tag_name, text, token)
super
@text = text
end
 
def render(context)
if parts = @text.match(/[#]?([\d]*)/)
bug = parts[1].strip
html_output_for bug
else
""
end
end
 
def html_output_for(bug)
"<a href='http://bugs.debian.org/#{bug}'>##{bug}</a>"
end
 
end
 
class ContentFilters < PostFilter
def doit(input)
input = input.gsub(/([Cc]loses: +)(#?)([0-9]+)((, +)(#?)([0-9]+))?/) do
r = "#{$1}<a href=\"http://bugs.debian.org/#{$3}\">#{$2}#{$3}</a>"
i = 4
while ($~[i])
pre = $~[i + 1]
hash = $~[i + 2]
bug = $~[i + 3]
r += "#{pre}<a href=\"http://bugs.debian.org/#{bug}\">#{hash}#{bug}</a>"
i += 4
end
 
r
end
input.gsub(/(LP: +)(#?)([0-9]+)/, "\\1<a href=\"https://bugs.launchpad.net/bugs/\\3\">\\2\\3</a>")
end
 
def pre_render(post)
post.content = doit(post.content)
end
end
end
 
Liquid::Template.register_tag('bts', Jekyll::DebbugsTag)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.