Nokogiri for Jekyll
Plugins
Add jekyll-nokogiri to your _config.yml plugins list.
Then you can write hook
plugins to modify document and
page HTML. post_convert for documents a
# _plugins/nokogiri.rb
# For some reason the hook is plural but the payload is a single
# document.
Jekyll::Hooks.register :documents, :post_convert do |document|
# Parse the HTML
document.to_html.tap do |html|
# Find all images within document content
html.css('img').each do |img|
# Set the img-fluid class for all of them
img['class'] = 'img-fluid'
end
end
end
Filters
Add jekyll-nokogiri-filters to your _config.yml plugins list.
add_attribute
Manipulates HTML5 strings by applying a CSS filter and adding/replacing an attribute with a value.
{{ content | add_attribute: "p:first-child", "class", "lead" }}