Compare commits

...

3 Commits

Author SHA1 Message Date
Cory LaViska
efb36b2e93 fix comment 2025-06-02 15:42:43 -04:00
Cory LaViska
0fdf6edae8 fix scroll on reload 2025-06-02 15:40:26 -04:00
Konnor Rogers
2b37c54d7c fix code blocks (#1009) 2025-06-02 10:23:47 -04:00
2 changed files with 44 additions and 1 deletions

View File

@@ -125,7 +125,7 @@ export default async function (eleventyConfig) {
eleventyConfig.addPlugin(currentLink());
// Add code examples for `<code class="example">` blocks
eleventyConfig.addPlugin(codeExamplesPlugin);
eleventyConfig.addPlugin(codeExamplesPlugin());
// Highlight code blocks with Prism
eleventyConfig.addPlugin(highlightCodePlugin());
@@ -136,6 +136,10 @@ export default async function (eleventyConfig) {
// Various text replacements
eleventyConfig.addPlugin(
replaceTextPlugin([
{
replace: /\[version\]/gs,
replaceWith: packageData.version,
},
// Replace [issue:1234] with a link to the issue on GitHub
{
replace: /\[pr:([0-9]+)\]/gs,

View File

@@ -1,3 +1,19 @@
import { allDefined } from '/dist/webawesome.js';
/**
* Determines how the page was loaded. Possible return values include "reload", "navigate", "back_forward", "prerender",
* and "unknown".
*/
function getNavigationType() {
if (performance.getEntriesByType) {
const navEntries = performance.getEntriesByType('navigation');
if (navEntries.length > 0) {
return navEntries[0].type;
}
}
return 'unknown';
}
// Smooth links
document.addEventListener('click', event => {
const link = event.target.closest('a');
@@ -31,3 +47,26 @@ function updateScrollClass() {
window.addEventListener('scroll', updateScrollClass);
window.addEventListener('turbo:render', updateScrollClass);
updateScrollClass();
// Restore scroll position after components are defined
allDefined().then(() => {
const navigationType = getNavigationType();
const key = `wa-scroll-y-[${location.pathname}]`;
const scrollY = sessionStorage.getItem(key);
// Only restore when reloading, otherwise clear it
if (navigationType === 'reload' && scrollY) {
window.scrollTo(0, scrollY);
} else {
sessionStorage.removeItem(key);
}
// After restoring, keep tabs on the page's scroll position for next reload
window.addEventListener(
'scroll',
() => {
sessionStorage.setItem(key, window.scrollY);
},
{ passive: true },
);
});