Skip to content

Port codepen filter tool to python

Kez requested to merge generate-filter into main

The lektor onion lock filter was previously generated with a codepen tool. Pointing users to a codepen isn't a good build process, so it's been ported to python

This is more-or-less a direct port of the javascript. The biggest changes were the addition of type hints (to help in porting) and changing the regular expression logic. Object literals have been kept as barely-typed dicts instead of being turned into classes, variable names have only been changed to prevent them from shadowing builtin functions, etc.

I've tested several different colors with it and compared them to outputs from the codepen tool. Due to the script being nondeterministic, the filters produced by both tools are different but result in colors so similar I can't tell them apart. which leads me to believe the script works.

Once this gets merged, we can actually turn it into a lektor plugin and incorporate it into the build process so that the LEKTOR_ONION_LOCK_FILTER variable can just be set to a hex color and the plugin can convert it.

@rhatto I'd appreciate a review if possible. I understand none of the math in the code, but everything seems to work properly and mypy/flake8 don't complain. Just wanna make sure I'm not missing some giant, obvious bug waiting to happen :P

Edited by Kez

Merge request reports

Loading