Skip to content

Commit 01227f1

Browse files
committed
404: add custom page with scoped path handling
404s are served at unknown, often nested URLs, where relative asset paths can resolve against missing paths instead of site root. This keeps 404 assets and navigation resolving from the homepage context without changing URL behavior on normal pages. The default banner is omitted on 404 so the error state and recovery action are immediately clear.
1 parent 70f6cc9 commit 01227f1

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

assets/sass/main.scss

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,36 @@ footer nav ul li a {
123123
margin: auto 0px;
124124
}
125125
}
126+
.not-found {
127+
text-align: center;
128+
margin: 3rem auto;
129+
}
130+
131+
.not-found-logo {
132+
width: 200px;
133+
margin: 0 auto 1.5rem;
134+
display: block;
135+
}
136+
137+
.not-found h1 {
138+
margin: 0 0 1rem;
139+
font-size: 3rem;
140+
font-weight: 700;
141+
}
142+
143+
.not-found p {
144+
margin: 0 0 1rem;
145+
}
146+
147+
body.page-404 {
148+
min-height: 90vh;
149+
display: flex;
150+
flex-direction: column;
151+
}
152+
153+
body.page-404 .not-found {
154+
flex: 1;
155+
display: flex;
156+
flex-direction: column;
157+
justify-content: center;
158+
}

layouts/404.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{ define "main" }}
2+
<div class="not-found">
3+
<img class="not-found-logo" src="{{ relURL "images/gitgitgadget-logo.png" }}" alt="GitGitGadget logo" width="200">
4+
<h1>404 Not Found</h1>
5+
<p>The page you are looking for doesn't exist</p>
6+
<p><a href="{{ relURL "/" }}">Return home</a></p>
7+
</div>
8+
{{ partial "footer.html" . }}
9+
{{ end }}

layouts/_default/baseof.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
<title>{{ .Title }}</title>
77
{{- $canonical := .Permalink | replaceRE "\\.html$" "" -}}
88
<link rel="canonical" href="{{ $canonical }}">
9-
<link rel="icon" href="{{ relURL "favicon.ico" }}">
9+
{{- if eq .Kind "404" }}
10+
<script>
11+
document.write('<base href="{{ .Site.Home.Permalink }}">');
12+
</script>
13+
{{- end }}
1014
{{- $style := resources.Get "sass/main.scss" | resources.ExecuteAsTemplate "main.scss" . | css.Sass }}
15+
<link rel="icon" href="{{ relURL "favicon.ico" }}">
1116
<link rel="stylesheet" href="{{ $style.RelPermalink }}">
1217
{{- partial "breadcrumbs.html" . -}}
1318
</head>
14-
<body>
19+
<body{{ if eq .Kind "404" }} class="page-404"{{ end }}>
20+
{{- if ne .Kind "404" }}
1521
{{ partial "banner.html" . -}}
22+
{{- end }}
1623

1724
{{ block "main" . }}
1825
{{ .Content }}
11 KB
Loading

0 commit comments

Comments
 (0)