aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2023-09-11 12:23:39 +0100
committerHayleigh Thompson <me@hayleigh.dev>2023-09-11 12:23:39 +0100
commitd38e39c3f4e126e6470b8a2f97133977740efad8 (patch)
tree59eebc6d5914ba5fc4d4cfe34debd3776276f3d0
parent2ca7623d0c3da2885ae40d8a51737f23aa51525d (diff)
downloadlustre-d38e39c3f4e126e6470b8a2f97133977740efad8.tar.gz
lustre-d38e39c3f4e126e6470b8a2f97133977740efad8.zip
:sparkles: Preload blog posts on link hover.
-rw-r--r--docs/index.html23
1 files changed, 22 insertions, 1 deletions
diff --git a/docs/index.html b/docs/index.html
index 0e7b438..82c2697 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -36,7 +36,12 @@
<!-- End Single Page Apps for GitHub Pages -->
<script type="module">
- import { main, Route, OnRouteChange } from "./src/app.gleam";
+ import {
+ main,
+ Route,
+ OnRouteChange,
+ OnRouteHover,
+ } from "./src/app.gleam";
const strip_base = (path) =>
`/${path.slice(import.meta.env.BASE_URL.length)}`;
@@ -79,6 +84,22 @@
}
});
+ document.addEventListener("mouseover", (e) => {
+ let target = e.target;
+
+ while (target) {
+ if (target === document.body) return;
+ if (target.tagName === "A") {
+ const url = new URL(target.href);
+ if (url.origin !== window.location.origin) return;
+ const route = new Route(strip_base(url.pathname), url.hash);
+ return void dispatch(new OnRouteHover(route));
+ }
+
+ target = target.parentNode;
+ }
+ });
+
// This lets us listen to the back and forward buttons in the browser
// and trigger our app's routing.
window.addEventListener("popstate", () => {