From 2b617b20a371a333b71ac7afec534c2d29e96534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20=C3=91=C3=A1=C3=B1ez=20Ortiz?= Date: Mon, 19 Aug 2024 00:52:59 -0500 Subject: [PATCH] refactor: replace github-slugger with lodash.kebabcase (#357) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, `github-slugger` omitted emojis when generating slugs, transforming tags like "🌱-my-tag" into "-my-tag". This change replaces `github-slugger` with `lodash.kebabcase` to ensure that emojis are preserved in the generated slugs, improving the accuracy and consistency of tag representations. --- package-lock.json | 23 ++++++++++++++++++++++- package.json | 3 ++- src/utils/slugify.ts | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6fa413d..06ca067 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@resvg/resvg-js": "^2.6.2", "astro": "^4.13.0", "fuse.js": "^7.0.0", - "github-slugger": "^2.0.0", + "lodash.kebabcase": "^4.1.1", "remark-collapse": "^0.1.2", "remark-toc": "^9.0.0", "satori": "^0.10.14", @@ -26,6 +26,7 @@ "@astrojs/tailwind": "^5.1.0", "@tailwindcss/typography": "^0.5.13", "@types/github-slugger": "^1.3.0", + "@types/lodash.kebabcase": "^4.1.9", "@types/react": "^18.3.3", "@typescript-eslint/parser": "^6.19.0", "astro-eslint-parser": "^0.16.2", @@ -2053,6 +2054,21 @@ "@types/unist": "*" } }, + "node_modules/@types/lodash": { + "version": "4.17.7", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.7.tgz", + "integrity": "sha512-8wTvZawATi/lsmNu10/j2hk1KEP0IvjubqPE3cu1Xz7xfXXt5oCq3SNUz4fMIP4XGF9Ky+Ue2tBA3hcS7LSBlA==", + "dev": true + }, + "node_modules/@types/lodash.kebabcase": { + "version": "4.1.9", + "resolved": "https://registry.npmjs.org/@types/lodash.kebabcase/-/lodash.kebabcase-4.1.9.tgz", + "integrity": "sha512-kPrrmcVOhSsjAVRovN0lRfrbuidfg0wYsrQa5IYuoQO1fpHHGSme66oyiYA/5eQPVl8Z95OA3HG0+d2SvYC85w==", + "dev": true, + "dependencies": { + "@types/lodash": "*" + } + }, "node_modules/@types/mdast": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.3.tgz", @@ -5806,6 +5822,11 @@ "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==", "dev": true }, + "node_modules/lodash.kebabcase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz", + "integrity": "sha512-N8XRTIMMqqDgSy4VLKPnJ/+hpGZN+PHQiJnSenYqPaVV/NCqEogTnAdZLQiGKhxX+JCs8waWq2t1XHWKOmlY8g==" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", diff --git a/package.json b/package.json index 2b0bb82..0567bbf 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "@resvg/resvg-js": "^2.6.2", "astro": "^4.13.0", "fuse.js": "^7.0.0", - "github-slugger": "^2.0.0", + "lodash.kebabcase": "^4.1.1", "remark-collapse": "^0.1.2", "remark-toc": "^9.0.0", "satori": "^0.10.14", @@ -32,6 +32,7 @@ "@astrojs/tailwind": "^5.1.0", "@tailwindcss/typography": "^0.5.13", "@types/github-slugger": "^1.3.0", + "@types/lodash.kebabcase": "^4.1.9", "@types/react": "^18.3.3", "@typescript-eslint/parser": "^6.19.0", "astro-eslint-parser": "^0.16.2", diff --git a/src/utils/slugify.ts b/src/utils/slugify.ts index 007adae..f052b02 100644 --- a/src/utils/slugify.ts +++ b/src/utils/slugify.ts @@ -1,5 +1,5 @@ -import { slug as slugger } from "github-slugger"; +import kebabcase from "lodash.kebabcase"; -export const slugifyStr = (str: string) => slugger(str); +export const slugifyStr = (str: string) => kebabcase(str); export const slugifyAll = (arr: string[]) => arr.map(str => slugifyStr(str));