|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { NuxtError } from '#app' |
| 3 | +
|
| 4 | +const props = defineProps<{ |
| 5 | + error: NuxtError |
| 6 | +}>() |
| 7 | +
|
| 8 | +const statusCode = computed(() => props.error.statusCode || 500) |
| 9 | +const statusMessage = computed(() => { |
| 10 | + if (props.error.statusMessage) return props.error.statusMessage |
| 11 | + switch (statusCode.value) { |
| 12 | + case 404: return 'Page not found' |
| 13 | + case 500: return 'Internal server error' |
| 14 | + case 503: return 'Service unavailable' |
| 15 | + default: return 'Something went wrong' |
| 16 | + } |
| 17 | +}) |
| 18 | +
|
| 19 | +function handleError() { |
| 20 | + clearError({ redirect: '/' }) |
| 21 | +} |
| 22 | +
|
| 23 | +useHead({ |
| 24 | + title: `${statusCode.value} - ${statusMessage.value}`, |
| 25 | +}) |
| 26 | +</script> |
| 27 | + |
| 28 | +<template> |
| 29 | + <div class="min-h-screen flex flex-col bg-bg text-fg"> |
| 30 | + <header class="sticky top-0 z-50 bg-bg/80 backdrop-blur-md border-b border-border"> |
| 31 | + <nav |
| 32 | + aria-label="Main navigation" |
| 33 | + class="container h-14 flex items-center justify-between" |
| 34 | + > |
| 35 | + <a |
| 36 | + href="/" |
| 37 | + class="header-logo font-mono text-lg font-medium text-fg hover:text-fg transition-colors duration-200 focus-ring rounded" |
| 38 | + > |
| 39 | + <span class="text-fg-subtle">./</span>npmx |
| 40 | + </a> |
| 41 | + |
| 42 | + <ul class="flex items-center gap-6 list-none m-0 p-0"> |
| 43 | + <li class="flex"> |
| 44 | + <a |
| 45 | + href="/search" |
| 46 | + class="link-subtle font-mono text-sm inline-flex items-center" |
| 47 | + > |
| 48 | + search |
| 49 | + </a> |
| 50 | + </li> |
| 51 | + <li class="flex"> |
| 52 | + <a |
| 53 | + href="https://github.com/danielroe/npmx.dev" |
| 54 | + rel="noopener noreferrer" |
| 55 | + class="link-subtle font-mono text-sm inline-flex items-center gap-1.5" |
| 56 | + > |
| 57 | + <span class="i-carbon-logo-github w-4 h-4" /> |
| 58 | + <span class="hidden sm:inline">github</span> |
| 59 | + </a> |
| 60 | + </li> |
| 61 | + </ul> |
| 62 | + </nav> |
| 63 | + </header> |
| 64 | + |
| 65 | + <main class="flex-1 container flex flex-col items-center justify-center py-20 text-center"> |
| 66 | + <p class="font-mono text-8xl sm:text-9xl font-medium text-fg-subtle mb-4"> |
| 67 | + {{ statusCode }} |
| 68 | + </p> |
| 69 | + |
| 70 | + <h1 class="font-mono text-2xl sm:text-3xl font-medium mb-4"> |
| 71 | + {{ statusMessage }} |
| 72 | + </h1> |
| 73 | + |
| 74 | + <p |
| 75 | + v-if="error.message && error.message !== statusMessage" |
| 76 | + class="text-fg-muted text-base max-w-md mb-8" |
| 77 | + > |
| 78 | + {{ error.message }} |
| 79 | + </p> |
| 80 | + |
| 81 | + <button |
| 82 | + type="button" |
| 83 | + class="font-mono text-sm px-6 py-3 bg-fg text-bg rounded-lg transition-all duration-200 hover:bg-fg/90 active:scale-95" |
| 84 | + @click="handleError" |
| 85 | + > |
| 86 | + go home |
| 87 | + </button> |
| 88 | + </main> |
| 89 | + |
| 90 | + <footer class="border-t border-border mt-auto"> |
| 91 | + <div class="container py-8 flex flex-col sm:flex-row items-center justify-between gap-4 text-fg-subtle text-sm"> |
| 92 | + <p class="font-mono m-0"> |
| 93 | + a better npm browser |
| 94 | + </p> |
| 95 | + <div class="flex items-center gap-6"> |
| 96 | + <a |
| 97 | + href="https://github.com/danielroe/npmx.dev" |
| 98 | + rel="noopener noreferrer" |
| 99 | + class="link-subtle font-mono text-xs" |
| 100 | + > |
| 101 | + source |
| 102 | + </a> |
| 103 | + <span class="text-border">|</span> |
| 104 | + <a |
| 105 | + href="https://roe.dev" |
| 106 | + rel="noopener noreferrer" |
| 107 | + class="link-subtle font-mono text-xs" |
| 108 | + > |
| 109 | + @danielroe |
| 110 | + </a> |
| 111 | + </div> |
| 112 | + </div> |
| 113 | + </footer> |
| 114 | + </div> |
| 115 | +</template> |
0 commit comments