Last active
August 19, 2024 17:22
-
-
Save gingerbeardman/447a20fbf15e694ee96e6f30e65cdb2a to your computer and use it in GitHub Desktop.
transform local image paths to use your own CDN server
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
# file: _plugins/cdn_img.rb | |
module Jekyll | |
class CDNImageTransformer < Generator | |
def generate(site) | |
@site = site | |
@cdn_url = "https://cdn.example.com" | |
@site.pages.each { |page| process(page) } | |
@site.posts.docs.each { |post| process(post) } | |
end | |
def process(item) | |
item.content = item.content.gsub(/!\[(.*?)\]\((\/images\/.*?)\)/) do |match| | |
alt_text = $1 | |
image_path = $2 | |
"" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumptions:
images
folderimages
folder structureI use this to serve images from a domain that points to a free OCI (Oracle Cloud Infrastructure) server, whilst my HTML is served by Netlify.