|
52 | 52 | <body id="root" class="safe-h-screen"> |
53 | 53 | {% include "theme-switch.html" %} |
54 | 54 |
|
55 | | - <div class="flex h-[100%]" id="portal"> |
| 55 | + <div class="flex h-[100%]"> |
56 | 56 | <div class="left-bar pl-3 hidden md:block h-[100%] shadow-md dark:shadow-xl" id="left-bar"> |
57 | 57 | <div class="flex flex-row"> |
58 | 58 | <div class="flex flex-col justify-center"> |
|
63 | 63 | <input data-stork="ref-search" class="text-input flex-grow m-2 pr-2" type="text" placeholder="Search" /> |
64 | 64 | </div> |
65 | 65 | <div data-stork="ref-search-output" class="results"></div> |
66 | | - <nav role="navigation" class="pr-2"> |
| 66 | + <nav role="navigation" id="navbar" class="pr-2"> |
67 | 67 | <ul> |
68 | 68 | {%- block menu -%} |
69 | 69 | {%- set index = get_section(path="_index.md", metadata_only=true) -%} |
|
76 | 76 | </nav> |
77 | 77 | </div> |
78 | 78 |
|
79 | | - <section class="section"> |
| 79 | + <section class="section" id="portal"> |
80 | 80 | <div class="mt-5 mx-5"> |
81 | 81 | <div class="flex flex-col gap-5 border-b-2 border-lightborder dark:border-darkborder pb-2 mb-3"> |
82 | 82 | <div class="flex flex-col-reverse gap-5 md:flex-row justify-between"> |
|
137 | 137 | const doc = parser.parseFromString(await fetched.text(), "text/html"); |
138 | 138 |
|
139 | 139 | const content = doc.getElementById("portal"); |
| 140 | + const navbar = doc.getElementById("navbar"); |
140 | 141 |
|
141 | | - if(pre) preFetched[link] = content; |
142 | | - return content; |
| 142 | + if(pre) preFetched[link] = {content: content, navbar: navbar}; |
| 143 | + return {content: content, navbar: navbar}; |
143 | 144 | } |
144 | 145 |
|
145 | | - const buttonInterceptor = async (ev) => { |
146 | | - if(!ev.target.href) return; |
147 | | - |
148 | | - ev.preventDefault(); |
149 | | - |
| 146 | + const navTo = async(link) => { |
150 | 147 | const portal = document.getElementById("portal"); |
151 | | - const potentialFetch = preFetched[ev.target.href]; |
| 148 | + const navbar = document.getElementById("navbar"); |
| 149 | + |
| 150 | + const potentialFetch = preFetched[link]; |
152 | 151 |
|
153 | 152 | if(potentialFetch) { |
154 | | - portal.replaceChildren(...potentialFetch.children); |
| 153 | + portal.replaceChildren(...potentialFetch.content.children); |
| 154 | + navbar.replaceChildren(...potentialFetch.navbar.children) |
155 | 155 | } else { |
156 | | - const newContents = await fetchLink(ev.target.href); |
| 156 | + const newContents = await fetchLink(link); |
157 | 157 |
|
158 | 158 | if(!newContents) { |
159 | 159 | return; |
160 | 160 | } |
161 | 161 |
|
162 | | - portal.replaceChildren(...newContents.children); |
| 162 | + portal.replaceChildren(...newContents.content.children); |
| 163 | + navbar.replaceChildren(...newContents.navbar.children) |
163 | 164 | } |
164 | 165 |
|
165 | | - delete preFetched[ev.target.href]; |
| 166 | + delete preFetched[link]; |
166 | 167 |
|
167 | | - history.pushState(null, "", ev.target.href); |
| 168 | + history.pushState(true, "", link); |
168 | 169 |
|
169 | 170 | prefetchLinks(); |
170 | 171 | } |
171 | 172 |
|
| 173 | + const buttonInterceptor = async (ev) => { |
| 174 | + if(!ev.target.href) return; |
| 175 | + |
| 176 | + ev.preventDefault(); |
| 177 | + |
| 178 | + navTo(ev.target.href); |
| 179 | + } |
| 180 | + |
172 | 181 | const hoverInterceptor = (ev) => { |
173 | 182 | if(!ev.target.href) return; |
174 | 183 |
|
|
186 | 195 | } |
187 | 196 | } |
188 | 197 |
|
| 198 | + window.addEventListener("popstate", (pop) => { |
| 199 | + navTo(location.href); |
| 200 | + }) |
| 201 | + |
189 | 202 | prefetchLinks(); |
190 | 203 | </script> |
191 | 204 | </body> |
|
0 commit comments