Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jekyll plugin that replaces pictures in Markdown documents by responsive images using jekyll-responsive-mage
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
@axeleroy

This comment has been minimized.

Copy link
Owner Author

axeleroy commented May 29, 2020

This Jekyll plugin replaces every Markdown pictures in
Markdown documents by responsive images by jekyll-responsive-image's template.

For example:

![Philadelphia's Magic Gardens. This place was so cool!](/assets/images/philly-magic-gardens.jpg "Philadelphia's Magic Gardens")

will be replaced by

{% responsive_image path: assets/images/philly-magic-gardens.jpg alt: "Philadelphia's Magic Gardens. This place was so cool!" title: "Philadelphia's Magic Gardens" %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.