diff options
| author | Ahmed <git@gumx.cc> | 2026-06-01 22:19:27 +0300 |
|---|---|---|
| committer | Ahmed <git@gumx.cc> | 2026-06-01 22:19:27 +0300 |
| commit | ae72b8f9976a1c0cca66ff4cb31eadf311c677e7 (patch) | |
| tree | 532e48d085bd0ea48265f2bd262df8856dd8340f /includes/slugify.sh | |
init: moved to own site
Diffstat (limited to 'includes/slugify.sh')
| -rw-r--r-- | includes/slugify.sh | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/includes/slugify.sh b/includes/slugify.sh new file mode 100644 index 0000000..1a4adec --- /dev/null +++ b/includes/slugify.sh @@ -0,0 +1,74 @@ +#!/bin/sh +# Generate URL slugs from Unicode input +# This script is licensed under the MIT License + +# I copied many of the characters in this script from another project, +# but I cannot remember which. However, for a more professional solution +# check: +# - https://github.com/mattgathu/slugify +# - https://github.com/un33k/python-slugify +# I only wrote this because I wanted to use it in my website builder script +# ~ Ahmed + +# slugify.sh +# $* input string +# stdout slug + +printf '%s\n' "$*" | + sed \ + -e 's/[ _]/_/g' \ + -e 's/[-+/&,:;]/-/g' \ + -e 's/[.]/./g' \ + -e 's/[~]/~/g' \ + -e 's/[0°₀]/0/g' \ + -e 's/[1¹₁]/1/g' \ + -e 's/[2²₂]/2/g' \ + -e 's/[3³₃]/3/g' \ + -e 's/[4⁴₄]/4/g' \ + -e 's/[5⁵₅]/5/g' \ + -e 's/[6⁶₆]/6/g' \ + -e 's/[7⁷₇]/7/g' \ + -e 's/[8⁸₈]/8/g' \ + -e 's/[9⁹₉]/9/g' \ + -e 's/[AaªáÁàÀăĂâÂǎǍǻǺãÃαΑάΆءأاى]/a/g' \ + -e 's/[åÅع]/aa/g' \ + -e 's/[äÄæÆ]/ae/g' \ + -e 's/[ǽǼ]/ae/g' \ + -e 's/[@]/at/g' \ + -e 's/[Bbب]/b/g' \ + -e 's/[Cc©ĉĈċĊçÇ]/c/g' \ + -e 's/[χΧ]/ch/g' \ + -e 's/[DdđĐδΔدض]/d/g' \ + -e 's/[ðÐ]/dj/g' \ + -e 's/[EeéÉèÈĕĔêÊëËėĖεΕέΈئ]/e/g' \ + -e 's/[FfƒφΦف]/f/g' \ + -e 's/[GgĝĜġĠγΓج]/g/g' \ + -e 's/[غ]/gh/g' \ + -e 's/[HhĥĤħĦحهة]/h/g' \ + -e 's/[IiíÍìÌĭĬîÎǐǏïÏĩĨįĮηΗήΉιΙίΊϊΪϒύΎϋΫΰ]/i/g' \ + -e 's/[ijIJ]/ij/g' \ + -e 's/[JjĵĴ]/j/g' \ + -e 's/[KkκΚقك]/k/g' \ + -e 's/[خ]/kh/g' \ + -e 's/[LlĺĹľĽŀĿλΛل]/l/g' \ + -e 's/[MmμΜم]/m/g' \ + -e 's/[NnñÑʼnνΝن]/n/g' \ + -e 's/[OoºóÓòÒŏŎôÔǒǑőŐõÕǿǾōŌơƠοΟόΌωΩώو]/o/g' \ + -e 's/[öÖøØœŒ]/oe/g' \ + -e 's/[PpπΠ]/p/g' \ + -e 's/[ψΨ]/ps/g' \ + -e 's/[Qq]/q/g' \ + -e 's/[RrŕŔŗŖρΡر]/r/g' \ + -e 's/[SsŝŜșȘſσςΣسص]/s/g' \ + -e 's/[ش]/sh/g' \ + -e 's/[ßẞ]/ss/g' \ + -e 's/[TtţŢțȚŧŦτΤتط]/t/g' \ + -e 's/[þÞθϑΘثذظ]/th/g' \ + -e 's/[UuúÚùÙŭŬûÛǔǓüÜǘǗǜǛǚǙǖǕűŰũŨųŲưƯυΥ]/u/g' \ + -e 's/[VvβϐΒ]/v/g' \ + -e 's/[WwŵŴ]/w/g' \ + -e 's/[XxξΞ]/x/g' \ + -e 's/[YyýÝŷŶÿŸي]/y/g' \ + -e 's/[ZzζΖز]/z/g' \ + -e 's/[^a-z0-9_.~-]/_/g' | + tr -s -- '_-' |
