aboutsummaryrefslogtreecommitdiff
path: root/docs/index.html
blob: ba9941e6c2cdab2835d634d0f69ec11be282fa78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Lustre</title>

    <script type="module">
      document.head.appendChild(
        Object.assign(document.createElement("base"), {
          href: import.meta.env.BASE_URL,
        })
      );
    </script>

    <style>
      @font-face {
        font-family: "NTDapper";
        font-style: normal;
        font-weight: 400;
        src: url("/fonts/NTDapper-regular.woff2") format("woff2");
      }
      @font-face {
        font-family: "NTDapper";
        font-style: normal;
        font-weight: 500;
        src: url("/fonts/NTDapper-medium.woff2") format("woff2");
      }
      @font-face {
        font-family: "NTDapper";
        font-style: normal;
        font-weight: 700;
        src: url("/fonts/NTDapper-bold.woff2") format("woff2");
      }
      @font-face {
        font-family: "NTDapper";
        font-style: normal;
        font-weight: 900;
        src: url("/fonts/NTDapper-black.woff2") format("woff2");
      }

      @tailwind base;
      @tailwind components;
      @tailwind utilities;
    </style>
    <script type="module">
      import { main, OnRouteChange } from "./src/app.gleam";

      document.addEventListener("DOMContentLoaded", () => {
        const url = new URL(window.location.href);
        const dispatch = main({ path: url.pathname, hash: url.hash });

        // We want to trap click events on anchor elements so we can do our own
        // client side routing.
        document.addEventListener("click", (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;
              if (url.pathname !== window.location.pathname) e.preventDefault();

              window.requestAnimationFrame(() =>
                window.history.pushState({}, "", url.href)
              );

              return void dispatch(
                new OnRouteChange({ path: url.pathname, hash: url.hash })
              );
            }

            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", () => {
          const url = new URL(window.location.href);

          dispatch(new OnRouteChange({ path: url.pathname, hash: url.hash }));
        });
      });
    </script>
  </head>
  <body></body>
</html>