Created
May 29, 2020 22:10
-
-
Save axeleroy/273e6a6eb0eb68c8dad1f80c4d45303e to your computer and use it in GitHub Desktop.
Jekyll plugin that replaces pictures in Markdown documents by responsive images using jekyll-responsive-mage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Jekyll::Hooks.register :documents, :pre_render do |document, payload| | |
docExt = document.extname.tr('.', '') | |
# only process if we deal with a markdown file | |
if payload['site']['markdown_ext'].include? docExt | |
newContent = document.content.gsub(/!\[(.*)\]\((?:\/?([^\)\:\s]+))(?:\s"(.*)")?\)(?:{:([^}]+)})*/, '{% responsive_image path: \2 alt: "\1" title: "\3" %}') | |
document.content = newContent | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Jekyll plugin replaces every Markdown pictures in Markdown documents by responsive images using jekyll-responsive-image's template.
For example:
will be replaced by