Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/layouts/Main.astro
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,32 @@ import Navigation from '../components/Navigation.astro'
?.querySelector('html')
?.classList.toggle('pf-v6-theme-dark', themePreference === 'dark')
})

const scrollToHash = (hash: string) => {
const targetElement = document.querySelector(hash)
if (targetElement) {
targetElement.scrollIntoView({ behavior: 'smooth' })
}
}

document.addEventListener('DOMContentLoaded', () => {
if (window.location.hash) {
const hash = window.location.hash

// Without this, page would focus on anchor link without scrolling to it
history.replaceState(null, '', ' ')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally open to suggestions here if we hate this.


setTimeout(() => {
scrollToHash(hash)
history.replaceState(null, '', hash)
}, 500)
}
})

// Handle changes that happen after the initial page load
window.addEventListener('hashchange', () => {
if (window.location.hash) {
scrollToHash(window.location.hash)
}
})
</script>
1 change: 1 addition & 0 deletions src/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

.ws-heading {
position: relative;
scroll-margin-top: 3rem;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I'm noticing any difference when removing this line, is it necessary for anything in particular?

Copy link
Member Author

@rebeccaalpert rebeccaalpert May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just adds space above the scroll target!

Without:
Screenshot 2025-05-28 at 9 54 06 AM

With:
Screenshot 2025-05-28 at 9 54 22 AM

}

.ws-heading-anchor {
Expand Down