I have a custom Liquid tag that (in addition to customizing the look) I want to add to the array of page.tags
. The first couple of lines of the render
function (shown below) is supposed to do that. It works when I do a fresh build of the site. When I do an incremental build, it does not.
It seems I’ve created a hack that doesn’t quite work correctly. Please help me know what I’m missing.
module Jekyll
class Term < Liquid::Tag
def initialize(tag_name, input, tokens)
super
vars = input.split(" ")
@acronym = vars[0]
@category = vars[1]
end
def render(context)
tags = context.environments.first['page']['tags']
tags.append(@acronym) unless tags.include?(@acronym)
begin
definition = context.registers[:site].data['terminology']["#{@category}"]["#{@acronym}"]['definition']
if definition.nil?
"<a style=\"color:red\" href=\"/terminology/#{@category}\##{@acronym}\" title=\"???\" class=\"term\">#{@acronym}</a>"
else
"<a href=\"/terminology/#{@category}\##{@acronym}\" title=\"#{definition}\" class=\"term\">#{@acronym}</a>"
end
rescue NoMethodError
"<span style=\"color:red\">#{@category}/#{@acronym}</span>"
end
end
end
end
Liquid::Template.register_tag('term', Jekyll::Term)