From e67ec5eca4b786e9b8178895de505516df7f60f4 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Fri, 9 Jan 2026 01:54:10 +0100 Subject: [PATCH] Using common slugify. --- common | 2 +- src/tools/slugify-test.js | 32 +++++++++++++++++ src/utils/slugify.js | 76 ++------------------------------------- static | 2 +- 4 files changed, 36 insertions(+), 76 deletions(-) create mode 100644 src/tools/slugify-test.js diff --git a/common b/common index c45852d..ee23dc0 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit c45852d6937abe25e1205af0b9b96d49970901c8 +Subproject commit ee23dc0358677a66b27a20b8d56c4b69782cec9b diff --git a/src/tools/slugify-test.js b/src/tools/slugify-test.js new file mode 100644 index 0000000..48e21b9 --- /dev/null +++ b/src/tools/slugify-test.js @@ -0,0 +1,32 @@ +import slugify from '../utils/slugify.js'; + +function init() { + const cases = [ + 'Brave, New World', + 'Jœrgenbahn Straße', + 'Partêrre', + 'Ápres ski.', + 'very 😀 true 😃', + 'a véééry long piece of text that should not result in a very long slug, even for $100', + 'don\'t you, forget about me', + 'Pneumonoultramicroscopicsilicovolcanoconiosis', + 'this (old) spicemen[sic]', + 'contact@example.com', + '!@#$%', + '', + ' ', + ['this is', '2026-01-01', 'an array', '', ' ', 'test'], + ]; + + cases.forEach((item) => console.log(item, '-->', slugify(item, '-', { limit: 20 }))); + + cases.forEach((item) => console.log(item, '-->', slugify(item, '-', { + lower: true, + accents: false, + punctuation: false, + symbols: 'split', + limit: 50, + }))); +} + +init(); diff --git a/src/utils/slugify.js b/src/utils/slugify.js index 1b28d5e..d266cfb 100755 --- a/src/utils/slugify.js +++ b/src/utils/slugify.js @@ -1,75 +1,3 @@ -const substitutes = { - à: 'a', - á: 'a', - ä: 'a', - å: 'a', - ã: 'a', - æ: 'ae', - ç: 'c', - è: 'e', - é: 'e', - ë: 'e', - ẽ: 'e', - ì: 'i', - í: 'i', - ï: 'i', - ĩ: 'i', - ǹ: 'n', - ń: 'n', - ñ: 'n', - ò: 'o', - ó: 'o', - ö: 'o', - õ: 'o', - ø: 'o', - œ: 'oe', - ß: 'ss', - ù: 'u', - ú: 'u', - ü: 'u', - ũ: 'u', - ỳ: 'y', - ý: 'y', - ÿ: 'y', - ỹ: 'y', -}; +import slugify from '../../common/slugify.cjs'; -export default function slugify(strings, delimiter = '-', { - encode = false, - removeAccents = true, - removePunctuation = false, - limit = 1000, -} = {}) { - if (!strings || (typeof strings !== 'string' && !Array.isArray(strings))) { - return strings; - } - - const slugComponents = [] - .concat(strings) - .filter(Boolean) - .flatMap((string) => string - .trim() - .toLowerCase() - .replace(removePunctuation && /[.,:;'"_-]/g, '') - .match(/[A-Za-zÀ-ÖØ-öø-ÿ0-9]+/g)); - - if (!slugComponents) { - return ''; - } - - const slug = slugComponents.reduce((acc, component, index) => { - const accSlug = `${acc}${index > 0 ? delimiter : ''}${component}`; - - if (accSlug.length < limit) { - if (removeAccents) { - return accSlug.replace(/[à-ÿ]/g, (match) => substitutes[match] || ''); - } - - return accSlug; - } - - return acc; - }, ''); - - return encode ? encodeURI(slug) : slug; -} +export default slugify; diff --git a/static b/static index c3a287b..50a262d 160000 --- a/static +++ b/static @@ -1 +1 @@ -Subproject commit c3a287bfae05a7bb92d028c4036ec418b7efe5c5 +Subproject commit 50a262da611d6435a0bf77662f47d0a9126615f0