reporting-docs/_plugins/alert_generator.rb

40 строки
1.4 KiB
Ruby
Исходник Обычный вид История

2018-02-05 20:04:37 +03:00
module Reading
class Generator < Jekyll::Generator
def generate(site)
2018-12-11 18:41:00 +03:00
@site = site
@converter = site.find_converter_instance(Jekyll::Converters::Markdown)
2018-02-05 20:04:37 +03:00
site.pages.each do |p|
2018-12-11 18:41:00 +03:00
createAlert("tip", p.content)
createAlert("note", p.content)
createAlert("important", p.content)
createAlert("caution", p.content)
createAlert("warning", p.content)
end
2018-02-05 20:04:37 +03:00
end
2018-12-11 18:41:00 +03:00
def createAlert(alertType, content)
sub_string = content.scan(/(>#{alertType})((.|\n[\w\*\[!^<>|#])*)/)
if sub_string.count == 0
##puts "no " + alertType + "s"
else
sub_string.each do |s|
# puts("s - #{s} ; s1 - #{s[1]}; replaced - #{s[1].gsub(/(^>)/, "")}")
block ="<blockquote class='#{alertType}'>" + @converter.convert(s[1].gsub(/(^>)/x, "")) + "</blockquote>"
slugsInBlock = block.scan(/.*?(%7[Bb]%(?:%20){0,}slug(?:%20){1,}([0-9a-zA-Z_\-\(\)\*\.\/\,\%\'\?\:]+)(?:%20){0,}%{2}7[Dd])/)
2018-12-11 18:41:00 +03:00
if slugsInBlock.count > 0
slugsInBlock.each do |slug|
targetPage = @site.pages.find {|p| p.data['slug'] == slug[1]}
if targetPage
link = @site.baseurl + targetPage.url.sub('.html', '')
block.sub!(slug[0], link)
end
end
end
content.sub!(s[0]+s[1], block)
end
end
end
end
2018-02-05 20:04:37 +03:00
end