Nokogiri for Jekyll
Find a file
2025-05-07 17:28:02 -03:00
lib Nokogiri for Jekyll 2024-03-11 12:18:23 -03:00
Gemfile Nokogiri for Jekyll 2024-03-11 12:18:23 -03:00
jekyll-nokogiri.gemspec fix: gemspec 2025-05-07 17:28:02 -03:00
LICENSE Nokogiri for Jekyll 2024-03-11 12:18:23 -03:00
README.md Nokogiri for Jekyll 2024-03-11 12:18:23 -03:00

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" }}