Skip to content

Commit 7e4c360

Browse files
nikoshellegeakmanclytaemnestra
authored
Add link to jump from session to schedule. (#1239)
Link on session page ![image](https://github.com/user-attachments/assets/a4902e9a-7f63-47c2-a0a3-abf1e534903e) Jump and highlight the session ![image](https://github.com/user-attachments/assets/cfcb816b-fbbf-452f-9c34-dc5c7e27d6bc) --------- Co-authored-by: Ege Akman <[email protected]> Co-authored-by: Mia Bajić <[email protected]>
1 parent 683da09 commit 7e4c360

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

src/components/schedule/session.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
import Speakers from "./speakers.astro";
33
import { slugify } from "@utils/content";
4+
import Headline from "@ui/Headline.astro";
45
56
export interface props {
67
style: any;
@@ -69,7 +70,7 @@ const hasFooter = true;
6970
</div>
7071
-->
7172

72-
<h2>{session.title}</h2>
73+
<h2 id=`session-${session.slug}`>{session.title}</h2>
7374

7475
{
7576
hasFooter && (

src/pages/schedule.astro

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,64 @@ const days = await getCollection("days");
2727
))
2828
}
2929
</Layout>
30+
<script>
31+
window.addEventListener('load', function() {
32+
function checkForAnchorAndHighlight() {
33+
const currentAnchor = window.location.hash.substring(1);
34+
35+
if (!currentAnchor) return;
36+
37+
const allMatching = document.querySelectorAll(`h2#${currentAnchor}`);
38+
const targetH2 = allMatching[allMatching.length - 1];
39+
40+
if (targetH2) {
41+
const parentElement: any = targetH2.parentElement;
42+
43+
if (parentElement) {
44+
const originalBorder = parentElement.style.border;
45+
const originalBackground = parentElement.style.background;
46+
47+
let blinkCount = 0;
48+
const maxBlinks = 5;
49+
const blinkDuration = 500; // milliseconds
50+
51+
function toggleBorder() {
52+
if (blinkCount >= maxBlinks * 2) {
53+
parentElement.style.border = originalBorder;
54+
parentElement.style.background = originalBackground;
55+
return;
56+
}
57+
58+
if (blinkCount % 2 === 0) {
59+
parentElement.style.border = '1px solid #ff9900';
60+
parentElement.style.background = 'white';
61+
} else {
62+
parentElement.style.border = originalBorder;
63+
parentElement.style.background = originalBackground;
64+
}
65+
66+
blinkCount++;
67+
setTimeout(toggleBorder, blinkDuration);
68+
}
69+
70+
toggleBorder();
71+
72+
setTimeout(function() {
73+
const scrollOffset = 200;
74+
const elementPosition = parentElement.getBoundingClientRect().top;
75+
const offsetPosition = elementPosition + window.pageYOffset - scrollOffset;
76+
77+
window.scrollTo({
78+
top: offsetPosition,
79+
behavior: 'smooth'
80+
});
81+
}, 500);
82+
}
83+
}
84+
}
85+
86+
checkForAnchorAndHighlight();
87+
88+
window.addEventListener('hashchange', checkForAnchorAndHighlight);
89+
});
90+
</script>

src/pages/session/[slug].astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { YouTube } from "@astro-community/astro-embed-youtube";
88
import { Picture } from "astro:assets";
99
import Markdown from "@ui/Markdown.astro";
1010
import Section from "@ui/Section.astro";
11+
import Button from "@ui/Button.astro";
1112
1213
export async function getStaticPaths() {
1314
const sessions = await getCollection("sessions");
@@ -100,6 +101,8 @@ const nextSessionsOrdered = sameRoomNextSession
100101
<dt class="font-bold">Duration:</dt>
101102
<dd>{entry.data.duration} minutes</dd>
102103
</dl>
104+
<Button class="mb-10" url=`/schedule/#session-${entry.id}`>View in the schedule</Button>
105+
103106

104107
<Prose full>
105108
<h2>Abstract</h2>

0 commit comments

Comments
 (0)