|
| 1 | +--- |
| 2 | +import Head from "@components/Head/index.astro"; |
| 3 | +import BaseLayout from "../layouts/BaseLayout.astro"; |
| 4 | +import { getCurrentLocale } from "../i18n/utils.ts"; |
| 5 | +const currentLocale = getCurrentLocale(Astro.url.pathname); |
| 6 | +--- |
| 7 | + |
| 8 | +<Head title="404: Page Not Found" locale={currentLocale} /> |
| 9 | + |
| 10 | +<BaseLayout title="404: Page Not Found"> |
| 11 | + <section class="flex flex-col items-start gap-8 py-8 px-2 prose max-w-none"> |
| 12 | + <p> |
| 13 | + Sorry, we couldn't find your exact page |
| 14 | + <code id="display-path"></code>. |
| 15 | + |
| 16 | + <div class="flex flex-col gap-4"> |
| 17 | + <a id="search-link" href="/search/" class="btn"> |
| 18 | + Search here for <code id="display-search-term"></code> |
| 19 | + </a> |
| 20 | + or |
| 21 | + <a href="/" class="btn secondary">go home</a> |
| 22 | + </div> |
| 23 | + </p> |
| 24 | + </section> |
| 25 | + <script is:inline> |
| 26 | + (function update404PageDetails() { |
| 27 | + function getLastPathSegment(path) { |
| 28 | + return path.split("/").filter(Boolean).pop() ?? ""; |
| 29 | + } |
| 30 | + |
| 31 | + // 1. Get the last meaningful segment from the URL path, excluding hash part |
| 32 | + // 2. Use that in the link href to the search |
| 33 | + // 3. Also display it and the failed path |
| 34 | + |
| 35 | + //(This .pathname already strips away any hash part) |
| 36 | + const realPath = window.location.pathname; |
| 37 | + const term = getLastPathSegment(realPath); |
| 38 | + |
| 39 | + const displayPathEl = document.getElementById("display-path"); |
| 40 | + const searchLinkEl = document.getElementById("search-link"); |
| 41 | + const displaySearchTermEl = document.getElementById("display-search-term"); |
| 42 | + |
| 43 | + if (displayPathEl) { |
| 44 | + displayPathEl.textContent = realPath; |
| 45 | + } |
| 46 | + if (displaySearchTermEl) { |
| 47 | + displaySearchTermEl.textContent = term; |
| 48 | + } |
| 49 | + if (searchLinkEl) { |
| 50 | + searchLinkEl.href = `/search/?term=${encodeURIComponent(term)}`; |
| 51 | + } |
| 52 | + })(); |
| 53 | + </script> |
| 54 | +</BaseLayout> |
0 commit comments