Skip to content

Commit 8862af7

Browse files
committed
Add link to jump from session to schedule.
1 parent f3bacc8 commit 8862af7

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-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: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,84 @@ 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 targetElement = document.getElementById(currentAnchor);
38+
39+
const targetByName = targetElement || document.querySelector(`[name="${currentAnchor}"]`);
40+
41+
let targetH2;
42+
43+
if (targetByName && targetByName.tagName === 'H2') {
44+
targetH2 = targetByName;
45+
} else if (targetByName) {
46+
const h2InTarget = targetByName.querySelector('h2');
47+
if (h2InTarget) {
48+
targetH2 = h2InTarget;
49+
}
50+
} else {
51+
const allH2s = document.querySelectorAll('h2');
52+
for (const h2 of allH2s) {
53+
if (h2.id === currentAnchor || h2.getAttribute('name') === currentAnchor) {
54+
targetH2 = h2;
55+
break;
56+
}
57+
}
58+
}
59+
60+
if (targetH2) {
61+
const parentElement = targetH2.parentElement;
62+
63+
if (parentElement) {
64+
const originalBorder = parentElement.style.border;
65+
const originalBorderRadius = parentElement.style.borderRadius;
66+
67+
let blinkCount = 0;
68+
const maxBlinks = 5;
69+
const blinkDuration = 500; // milliseconds
70+
71+
function toggleBorder() {
72+
if (blinkCount >= maxBlinks * 2) {
73+
parentElement.style.border = originalBorder;
74+
parentElement.style.back = originalBorder;
75+
return;
76+
}
77+
78+
if (blinkCount % 2 === 0) {
79+
parentElement.style.border = '1px solid #ff9900';
80+
parentElement.style.background = 'white';
81+
} else {
82+
parentElement.style.border = originalBorder;
83+
parentElement.style.background = originalBorder;
84+
}
85+
86+
blinkCount++;
87+
setTimeout(toggleBorder, blinkDuration);
88+
}
89+
90+
toggleBorder();
91+
92+
setTimeout(function() {
93+
const scrollOffset = 200;
94+
const elementPosition = parentElement.getBoundingClientRect().top;
95+
const offsetPosition = elementPosition + window.pageYOffset - scrollOffset;
96+
97+
window.scrollTo({
98+
top: offsetPosition,
99+
behavior: 'smooth'
100+
});
101+
}, 500);
102+
}
103+
}
104+
}
105+
106+
checkForAnchorAndHighlight();
107+
108+
window.addEventListener('hashchange', checkForAnchorAndHighlight);
109+
});
110+
</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 on the schedule.</Button>
105+
103106

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

0 commit comments

Comments
 (0)