Skip to content

Commit 1d64167

Browse files
committed
add permalink
1 parent b4c50fe commit 1d64167

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

apps/svelte.dev/src/routes/packages/Category.svelte

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
}
1010
1111
let { title, description, packages }: Props = $props();
12+
const slug = $derived(`${title.toLowerCase().replace(/ /g, '-')}`);
1213
1314
const INITIAL_ITEMS = 3;
1415
</script>
1516

1617
<section class="category">
1718
<header>
18-
<h2>{title}</h2>
19+
<h2 id={slug}>
20+
<span>{title}</span>
21+
<a href="#{slug}" class="permalink" aria-label="permalink">aa</a>
22+
</h2>
1923

2024
{#if description}
2125
<p>{@html description}</p>
@@ -59,9 +63,11 @@
5963
6064
header {
6165
margin: 0 0 2rem 0;
66+
position: relative;
6267
6368
h2 {
6469
margin: 0 0 1rem 0;
70+
position: relative;
6571
}
6672
6773
p {
@@ -145,4 +151,37 @@
145151
height: 16rem;
146152
min-width: 0; /* Prevents grid items from overflowing */
147153
}
154+
155+
/* permalink */
156+
[id] {
157+
scroll-margin-top: calc(var(--sk-nav-height)) !important;
158+
}
159+
160+
a.permalink {
161+
position: absolute !important;
162+
display: block;
163+
background: var(--sk-fg-1);
164+
color: var(--sk-fg-1) !important;
165+
mask: url(icons/hash) 50% 50% no-repeat;
166+
mask-size: 2.4rem 2.4rem;
167+
width: 2.6rem;
168+
height: 2.2rem;
169+
top: calc(50% - 1rem);
170+
171+
@media (max-width: 767px) {
172+
right: 0;
173+
scale: 0.8;
174+
}
175+
176+
@media (min-width: 768px) {
177+
left: -3rem;
178+
opacity: 0;
179+
transition: opacity 0.2s;
180+
181+
h2:hover &,
182+
&:focus {
183+
opacity: 1;
184+
}
185+
}
186+
}
148187
</style>

0 commit comments

Comments
 (0)