Skip to content

Instantly share code, notes, and snippets.

@captn3m0
Created February 1, 2024 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save captn3m0/e429c4a982a94935a91804831f44faaa to your computer and use it in GitHub Desktop.
Save captn3m0/e429c4a982a94935a91804831f44faaa to your computer and use it in GitHub Desktop.
A HSL to Hex Jekyll Filter
require 'color'
module Jekyll
module HSLToHexFilter
def hsl_to_hex(input)
# Extract HSL components from the input string
hsl_match = input.match(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/)
hue, saturation, lightness = hsl_match.captures.map(&:to_f)
# Create HSL object
hsl_color = Color::HSL.new(hue, saturation, lightness)
# Convert HSL to HEX
hex_color = hsl_color.to_rgb.hex
hex_color
end
end
end
Liquid::Template.register_filter(Jekyll::HSLToHexFilter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment