add handler, html templates, Makefile and migrations

This commit is contained in:
Philipp 2021-08-29 16:37:20 +02:00
commit a06e8db2ff
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 276B613AF9DBE9C3
22 changed files with 1001 additions and 0 deletions

44
templates/home.html Normal file
View file

@ -0,0 +1,44 @@
{{define "header"}}
<h1 class="mb-0">Welcome to goddit</h1>
{{end}}
{{define "content"}}
{{range .Posts}}
<div class="card mb-4">
<div class="d-flex">
<div class="py-4 pl-4 text-center flex-shrink-0" style="width: 3rem">
<a href="/threads/{{.ThreadID}}/{{.ID}}/vote?dir=up" class="d-block text-body text-decoration-none">
<svg viewBox="0 0 10 16" width="10" height="16">
<path fill-rule="evenodd" d="M10 10l-1.5 1.5L5 7.75 1.5 11.5 0 10l5-5 5 5z"></path>
</svg>
</a>
<div class="mt-1">{{.Votes}}</div>
<a href="/threads/{{.ThreadID}}/{{.ID}}/vote?dir=down" class="d-block text-body text-decoration-none">
<svg viewBox="0 0 10 16" width="10" height="16">
<path fill-rule="evenodd" d="M5 11L0 6l1.5-1.5L5 8.25 8.5 4.5 10 6l-5 5z"></path>
</svg>
</a>
</div>
<div class="card-body">
<a href="/threads/{{.ThreadID}}" class="small text-secondary">{{.ThreadTitle}}</a>
<a href="/threads/{{.ThreadID}}/{{.ID}}" class="d-block card-title text-body mt-1 h5">
{{.Title}}
</a>
<p class="card-text">{{.Content}}</p>
<a href="/threads/{{.ThreadID}}/{{.ID}}">{{.CommentsCount}} Comments</a>
</div>
</div>
</div>
{{end}}
{{end}}
{{define "sidebar"}}
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">Explore interesting threads</h5>
<p class="card-text">Browse through hundreds of interesting threads with great communities.</p>
<a href="/threads" class="btn btn-primary btn-block">Browse Threads</a>
</div>
</div>
{{end}}

31
templates/layout.html Normal file
View file

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-light container">
<a class="navbar-brand text-primary" href="/">goddit</a>
</nav>
<div class="header bg-light border-bottom border-top py-5">
<div class="container">
{{block "header" .}}{{end}}
</div>
</div>
<div class="container py-5">
<div class="row">
<div class="col-xl-8 order-1 order-xl-0">
{{block "content" .}}{{end}}
</div>
<div class="col-xl-4 order-0 order-xl-1">
{{block "sidebar" .}}{{end}}
</div>
</div>
</div>
</body>
</html>

46
templates/post.html Normal file
View file

@ -0,0 +1,46 @@
{{define "header"}}
<div class="row">
<div class="col-xl-8">
<a href="/threads/{{.Thread.ID}}" class="text-secondary mb-2 mt-2 d-flex align-items-center">
<svg viewBox="0 0 8 16" width="8" height="16" fill="currentColor">
<path fill-rule="evenodd" d="M5.5 3L7 4.5 3.25 8 7 11.5 5.5 13l-5-5 5-5z"></path>
</svg>
<span class="ml-2">Back</span>
</a>
<h1>{{.Post.Title}}</h1>
<p class="m-0">
{{.Post.Content}}
</p>
</div>
</div>
{{end}}
{{define "content"}}
<div class="card mb-4">
<div class="text-right">
<form action="/threads/{{.Thread.ID}}/{{.Post.ID}}" method="POST">
<textarea name="content" class="form-control border-0 border-bottom-1 p-3"
placeholder="What are your thoughts?" rows="4"></textarea>
<div class="border-top p-1">
<button class="btn btn-primary btn-sm">Comment</button>
</div>
</form>
</div>
</div>
<div class="card mb-4 px-4">
{{range .Comments}}
<div class="d-flex my-4">
<div class="text-center flex-shrink-0" style="width: 1.5rem">
<a href="/comments/{{.ID}}/vote?dir=up" class="d-block text-body text-decoration-none">&#x25B2</a>
<div>{{.Votes}}</div>
<a href="/comments/{{.ID}}/vote?dir=down" class="d-block text-body text-decoration-none">&#x25BC</a>
</div>
<div class="pl-4">
<p class="card-text" style="white-space: pre-line;">{{.Content}}</p>
</div>
</div>
{{end}}
</div>
{{end}}

View file

@ -0,0 +1,20 @@
{{define "header"}}
<h5>Create a new post in</h5>
<h1 class="mb-0">{{.Thread.Title}}</h1>
{{end}}
{{define "content"}}
<form action=/threads/{{.Thread.ID}} method="POST">
<div class="form-group">
<label>Title</label>
<input name="title" type="text" class="form-control" placeholder="Give your post a great title">
</div>
<div class="form-group">
<label>Text</label>
<textarea name="content" class="form-control" rows="3"
placeholder="Tell people about your thoughts"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit Post</button>
</form>
{{end}}

45
templates/thread.html Normal file
View file

@ -0,0 +1,45 @@
{{define "header"}}
<h1 class="mb-0">{{.Thread.Title}}</h1>
{{end}}
{{define "content"}}
{{range .Posts}}
<div class="card mb-4">
<div class="d-flex">
<div class="py-4 pl-4 text-center flex-shrink-0" style="width: 3rem">
<a href="/threads/{{$.Thread.ID}}/{{.ID}}/vote?dir=up" class="d-block text-body text-decoration-none">
<svg viewBox="0 0 10 16" width="10" height="16">
<path fill-rule="evenodd" d="M10 10l-1.5 1.5L5 7.75 1.5 11.5 0 10l5-5 5 5z"></path>
</svg>
</a>
<div class="mt-1">{{.Votes}}</div>
<a href="/threads/{{$.Thread.ID}}/{{.ID}}/vote?dir=down" class="d-block text-body text-decoration-none">
<svg viewBox="0 0 10 16" width="10" height="16">
<path fill-rule="evenodd" d="M5 11L0 6l1.5-1.5L5 8.25 8.5 4.5 10 6l-5 5z"></path>
</svg>
</a>
</div>
<div class="card-body">
<h5 class="card-title">{{.Title}}</h5>
<p class="card-text">{{.Content}}</p>
<a href="/threads/{{$.Thread.ID}}/{{.ID}}">{{.CommentsCount}} Comments</a>
</div>
</div>
</div>
{{end}}
{{end}}
{{define "sidebar"}}
<div class="card mb-2">
<div class="card-body">
<h5 class="card-title">About Community</h5>
<p class="card-text">{{.Thread.Description}}</p>
<a href="/threads/{{.Thread.ID}}/new" class="btn btn-primary btn-block">Create Post</a>
</div>
</div>
<div class="text-center">
<form action=/threads/{{.Thread.ID}}/delete method="POST">
<button type="submit" class="text-danger btn-sm btn btn-link">Delete this thread</button>
</form>
</div>
{{end}}

View file

@ -0,0 +1,18 @@
{{define "header"}}
<h1 class="mb-0">Create a new thread</h1>
{{end}}
{{define "content"}}
<form action="/threads" method="POST">
<div class="form-group">
<label>Title</label>
<input name="title" type="text" class="form-control" placeholder="Give your thread a great title">
</div>
<div class="form-group">
<label>Description</label>
<textarea name="description" class="form-control" rows="3"
placeholder="Tell people what your thread is about"></textarea>
</div>
<button type="submit" class="btn btn-primary">Create Thread</button>
</form>
{{end}}

28
templates/threads.html Normal file
View file

@ -0,0 +1,28 @@
<!DOCTYPE html>
{{define "header"}}
<h1 class="mb-0">Explore threads</h1>
{{end}}
{{define "content"}}
{{range .Threads}}
<div class="card mb-4">
<div class="card-body">
<a href="#" class="d-block card-title text-body mt-1 h5">
{{.Title}}
</a>
<p class="card-text">{{.Description}}</p>
<a href="/threads/{{.ID}}" class="btn btn-primary">Browse Thread</a>
</div>
</div>
{{end}}
{{end}}
{{define "sidebar"}}
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">Create a new thread</h5>
<p class="card-text">Start a new community on goddit and share experiences.</p>
<a href="/threads/new" class="btn btn-primary btn-block">Create Thread</a>
</div>
</div>
{{end}}