feat: add 404 page

This commit is contained in:
Yanislav Igonin 2021-09-05 15:35:20 +03:00
parent ca65436fb6
commit 25f6ba7e93
4 changed files with 54 additions and 4 deletions

View File

@ -25,9 +25,7 @@ func GetThread(c *gin.Context) {
threadIDString := c.Param("threadID") threadIDString := c.Param("threadID")
threadID, err := strconv.Atoi(threadIDString) threadID, err := strconv.Atoi(threadIDString)
if err != nil { if err != nil {
// TODO: рендерить шаблон 404 c.HTML(http.StatusOK, "404.html", nil)
log.Println("error:", err)
c.JSON(http.StatusOK, gin.H{"error": true})
return return
} }
thread, err := Repositories.Posts.GetThreadByPostID(threadID) thread, err := Repositories.Posts.GetThreadByPostID(threadID)
@ -38,7 +36,7 @@ func GetThread(c *gin.Context) {
return return
} }
if thread == nil { if thread == nil {
// TODO: рендерить шаблон 404 c.HTML(http.StatusOK, "404.html", nil)
return return
} }
c.HTML(http.StatusOK, "thread.html", thread) c.HTML(http.StatusOK, "thread.html", thread)

9
static/error-image.css Normal file
View File

@ -0,0 +1,9 @@
.error-image {
max-width: 50%;
max-height: 50%;
transition: 0.2s;
}
.error-image:hover {
max-width: 60%;
max-height: 60%;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

43
templates/404.html Normal file
View File

@ -0,0 +1,43 @@
<html lang="en">
<head>
{{ template "static" }}
<link
href="/static/error-image.css"
rel="stylesheet"
>
<title>Micrach</title>
<!-- Primary Meta Tags -->
<meta charset="UTF-8"/>
<meta name="title" content="Micrach">
<meta name="description" content="Single board imageboard.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://micrach.igonin.dev/">
<meta property="og:title" content="Micrach">
<meta property="og:description" content="Single board imageboard.">
<meta property="og:image" content="https://memepedia.ru/wp-content/uploads/2018/03/ebanyy-rot-etogo-kazino.png">
<!-- Twitter -->
<meta property="twitter:card" content="https://memepedia.ru/wp-content/uploads/2018/03/ebanyy-rot-etogo-kazino.png">
<meta property="twitter:url" content="https://micrach.igonin.dev/">
<meta property="twitter:title" content="Micrach">
<meta property="twitter:description" content="Single board imageboard.">
<meta property="twitter:image" content="https://memepedia.ru/wp-content/uploads/2018/03/ebanyy-rot-etogo-kazino.png">
</head>
<body>
<div class="h-100 d-flex justify-content-center align-items-center flex-column">
<h1>404</h1>
<h1>PAGE NOT FOUND</h1>
<img
class="error-image"
src="/static/images/errors/404.png"
alt="All broken"
>
</div>
</body>
</html>