Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"remark-toc": "^9.0.0",
"satori": "^0.18.3",
"sharp": "^0.34.5",
"slugify": "^1.6.6",
"tailwindcss": "^4.1.18"
},
"devDependencies": {
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/components/Card.astro
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const { title, description, ...props } = data;
"focus-visible:no-underline focus-visible:underline-offset-0",
]}
>
<Heading style={{ viewTransitionName: slugifyStr(title) }}>
<Heading
style={{ viewTransitionName: slugifyStr(title.replaceAll(".", "-")) }}
>
{title}
</Heading>
</a>
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/PostDetails.astro
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const nextPost =
data-pagefind-body
>
<h1
transition:name={slugifyStr(title)}
transition:name={slugifyStr(title.replaceAll(".", "-"))}
class="inline-block text-2xl font-bold text-accent sm:text-3xl"
>
{title}
Expand Down
20 changes: 19 additions & 1 deletion src/utils/slugify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import kebabcase from "lodash.kebabcase";
import slugify from "slugify";

export const slugifyStr = (str: string) => kebabcase(str);
/**
* Check if string contains non-Latin characters
*/
const hasNonLatin = (str: string): boolean => /[^\x00-\x7F]/.test(str);

/**
* Slugify a string using a hybrid approach:
* - For Latin-only strings: use slugify (eg: "E2E Testing" -> "e2e-testing", "TypeScript 5.0" -> "typescript-5.0")
* - For strings with non-Latin characters: use lodash.kebabcase (preserves non-Latin chars)
*/
export const slugifyStr = (str: string): string => {
if (hasNonLatin(str)) {
// Preserve non-Latin characters (e.g., Burmese, Chinese, etc.)
return kebabcase(str);
}
// Handle Latin strings with better number/acronym handling
return slugify(str, { lower: true });
};

export const slugifyAll = (arr: string[]) => arr.map(str => slugifyStr(str));