11-Facelift
Last updated
<html>
<head>
{{if .Title}}
<title>{{.Title}} - blog</title>
{{else}}
<title>Welcome to blog!</title>
{{end}}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<style>
.container {
max-width: 960px;
}
</style>
</head>
<body>
<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm">
<h5 class="my-0 mr-md-auto font-weight-normal">Blog</h5>
<nav class="my-2 my-md-0 mr-md-3">
<a class="p-2 text-dark" href="/">Home</a>
<a class="p-2 text-dark" href="/explore">Explore</a>
{{if .CurrentUser}}
<a class="p-2 text-dark" href="/user/{{.CurrentUser}}">Profile</a>
{{end}}
</nav>
{{if .CurrentUser}}
<a class="btn btn-outline-primary" href="/logout">Logout</a>
{{else}}
<a class="btn btn-outline-primary" href="/login">Login</a>
{{end}}
</div>
<div class="container">
{{template "content" .}}
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
</body>
</html> <nav aria-label="...">
<ul class="pagination justify-content-center">
{{ if gt .PrevPage 0 }}
<li class="page-item">
<a href="/user/{{.ProfileUser.Username}}?page={{.PrevPage}}">
<span class="page-link" aria-hidden="true">← Newer Posts</span>
</a>
</li>
{{ else }}
<li class="page-item disabled">
<a href="#">
<span class="page-link" aria-hidden="true">← Newer Posts</span>
</a>
</li>
{{ end }}
{{ if gt .NextPage 0 }}
<li class="page-item">
<a href="/user/{{.ProfileUser.Username}}?page={{.NextPage}}">
<span class="page-link" aria-hidden="true">Older Posts →</span>
</a>
</li>
{{ else }}
<li class="page-item disabled">
<a href="#">
<span class="page-link" aria-hidden="true">Older Posts →</span>
</a>
</li>
{{ end }}
</ul>
</nav>package vm
// NotFoundMessage struct
type NotFoundMessage struct {
Flash string
}<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page Not Found</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
line-height: 1.2;
margin: 0;
}
html {
color: #888;
display: table;
font-family: sans-serif;
height: 100%;
text-align: center;
width: 100%;
}
body {
display: table-cell;
vertical-align: middle;
margin: 2em auto;
}
h1 {
color: #555;
font-size: 2em;
font-weight: 400;
}
p {
margin: 0 auto;
width: 280px;
}
@media only screen and (max-width: 280px) {
body, p {
width: 95%;
}
h1 {
font-size: 1.5em;
margin: 0 0 0.3em;
}
}
</style>
</head>
<body>
{{if .Flash}}
<h1>{{.Flash}}</h1>
{{else}}
<h1>Page Not Found</h1>
{{end}}
<p>Sorry, but the page you were trying to view does not exist.</p>
</body>
</html>...
r.NotFoundHandler = http.HandlerFunc(notfoundHandler)
r.HandleFunc("/404", notfoundHandler)
...
func notfoundHandler(w http.ResponseWriter, r *http.Request) {
flash := getFlash(w, r)
message := vm.NotFoundMessage{Flash: flash}
tpl, _ := template.ParseFiles("templates/404.html")
tpl.Execute(w, &message)
}
...