Skip to content

Commit

Permalink
add target and rel attributes to external links in app-sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
Inglan committed Jan 3, 2025
1 parent b0f01ad commit 43c88ee
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/lib/components/app-sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,16 @@
(item.url === '/' && page.url.pathname === '')}
>
{#snippet child({ props })}
<a href={item.url} {...props}>{item.title}</a>
<a
href={item.url}
{...props}
target={item.url.startsWith('http') ? '_blank' : undefined}
rel={item.url.startsWith('http')
? 'noopener noreferrer'
: undefined}
>
{item.title}
</a>
{/snippet}
</Sidebar.MenuSubButton>
</Sidebar.MenuSubItem>
Expand All @@ -205,7 +214,13 @@
(groupItem.url === '/' && page.url.pathname === '')}
>
{#snippet child({ props })}
<a href={groupItem.url} class="font-medium" {...props}>
<a
href={groupItem.url}
class="font-medium"
{...props}
target={groupItem.url.startsWith('http') ? '_blank' : undefined}
rel={groupItem.url.startsWith('http') ? 'noopener noreferrer' : undefined}
>
{#if Icon}
<Icon />
{/if}
Expand All @@ -230,15 +245,25 @@
{#if groupItem.items?.length}
<Command.Group heading={groupItem.title}>
{#each groupItem.items as item (item.title)}
<Command.LinkItem href={item.url} onSelect={() => (open = false)}>
<Command.LinkItem
href={item.url}
onSelect={() => (open = false)}
target={item.url.startsWith('http') ? '_blank' : undefined}
rel={item.url.startsWith('http') ? 'noopener noreferrer' : undefined}
>
<span>{item.title}</span>
</Command.LinkItem>
{/each}
</Command.Group>
<Command.Separator />
{:else}
<Command.Group>
<Command.LinkItem href={groupItem.url} onSelect={() => (open = false)}>
<Command.LinkItem
href={groupItem.url}
onSelect={() => (open = false)}
target={groupItem.url.startsWith('http') ? '_blank' : undefined}
rel={groupItem.url.startsWith('http') ? 'noopener noreferrer' : undefined}
>
<span>{groupItem.title}</span>
</Command.LinkItem>
</Command.Group>
Expand Down

0 comments on commit 43c88ee

Please sign in to comment.