Skip to content

Commit

Permalink
fix: handle special characters in tag URLs
Browse files Browse the repository at this point in the history
When the tag contains special characters like '#', the generated URL
becomes invalid due to the presence of these characters. This commit
fixes the issue by encoding the tag using `encodeURIComponent` before
constructing the URL.

Changes:
- Use `encodeURIComponent` to encode the tag to ensure special characters are properly handled.
- Update the href attribute in the <a> tag to use the encoded tag.

Now, tags with special characters (e.g., 'C#') will generate valid URLs.
  • Loading branch information
Seventeezz committed Aug 7, 2024
1 parent 865adae commit 49113db
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/components/Tag.astro
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
export interface Props {
tag: string
}
const { tag } = Astro.props
---

<a href={`/tags/${tag.toLowerCase()}`} aria-label={tag}>
<span
class='bg-indigo-600 font-semibold text-white dark:bg-indigo-900 dark:text-white shadow text-sm w-fit px-2 py-1 md:px-5 md:py-2 rounded-full'
>
{tag ?? 'Blog Tag'}
</span>
</a>
---
export interface Props {
tag: string
}
const { tag } = Astro.props
---

<a href={`/tags/${encodeURIComponent(tag.toLowerCase())}`} aria-label={tag}>
<span
class='bg-indigo-600 font-semibold text-white dark:bg-indigo-900 dark:text-white shadow text-sm w-fit px-2 py-1 md:px-5 md:py-2 rounded-full'
>
{tag ?? 'Blog Tag'}
</span>
</a>

0 comments on commit 49113db

Please sign in to comment.