I have a couple of elements in my Jekyll site that do not lend themselves to excerpts very well, in particular not when used in RSS feeds. Since they are created by Liquid tags (implemented in custom plugins), I figured it should be easy to do. Something like this would seem prudent:
module Jekyll
class MyTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
end
def render(context)
if <in excerpt>
""
else
"this should not be in an excerpt"
end
end
end
end
Liquid::Template.register_tag('mytag', Jekyll::MyTag)
I don't see how to check whether the tag is rendered for an excerpt, though. Dumping the contentx of context.environments
, context.scopes
and context.registers
did not reveal anything useful.
How can I do this?
I do not have a solution on the level of Jekyll or Liquid. There is a rather trivial workaround, though: hide the offending elements using CSS.
Say you have something like this:
<div class="excerpt">
{{ post.excerpt }}
</div>
Then use CSS to hide elements:
div.excerpt {
.footnote,.footnotes,.marginnote {
display: none;
}
}
The classes depend on which Markdown engine, plugins and themes you use, obviously.