Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated slugify function #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion basejump_core--2.0.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,16 @@ CREATE TRIGGER basejump_protect_account_fields
FOR EACH ROW
EXECUTE FUNCTION basejump.protect_account_fields();

-- add unaccent extension to replace any non-latin characters https://www.postgresql.org/docs/9.6/unaccent.html
CREATE EXTENSION IF NOT EXISTS unaccent;

-- convert any character in the slug that's not a letter, number, or dash to a dash on insert/update for accounts
CREATE OR REPLACE FUNCTION basejump.slugify_account_slug()
RETURNS TRIGGER AS
$$
BEGIN
if NEW.slug is not null then
NEW.slug = lower(regexp_replace(NEW.slug, '[^a-zA-Z0-9-]+', '-', 'g'));
NEW.slug = trim(BOTH '-' FROM regexp_replace(lower(public.unaccent(trim(NEW.slug))), '[^a-z0-9\\-_]+', '-', 'gi'));
end if;

RETURN NEW;
Expand Down