Created
February 1, 2024 07:04
-
-
Save captn3m0/e429c4a982a94935a91804831f44faaa to your computer and use it in GitHub Desktop.
A HSL to Hex Jekyll Filter
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
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