started main site design
This commit is contained in:
parent
02110982ae
commit
f8d0c0760d
39
main.go
39
main.go
|
@ -16,6 +16,7 @@ import (
|
|||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
var errlog *log.Logger
|
||||
var db *sql.DB = nil
|
||||
var mediaPath *string = nil
|
||||
var templatesPath *string = nil
|
||||
|
@ -91,7 +92,7 @@ func insertComic(c * Comic) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func index(w http.ResponseWriter, r * http.Request) {
|
||||
func indexView(w http.ResponseWriter, r * http.Request) {
|
||||
var err error
|
||||
|
||||
path := strings.TrimPrefix(r.URL.Path, "/")
|
||||
|
@ -101,25 +102,28 @@ func index(w http.ResponseWriter, r * http.Request) {
|
|||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
errlog.Println(err)
|
||||
return500(w,r)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
c := Comic{
|
||||
Title: "Test Comic",
|
||||
}
|
||||
context := struct {
|
||||
Comic *Comic
|
||||
Previous int
|
||||
Next int
|
||||
Title string
|
||||
}{
|
||||
Comic: nil,
|
||||
Previous: -1,
|
||||
Next: -1,
|
||||
Comic: &c,
|
||||
Previous: 0,
|
||||
Next: 0,
|
||||
Title: "Black Ram Comics",
|
||||
}
|
||||
|
||||
i := 0
|
||||
c := Comic{}
|
||||
if len(path) > 0{
|
||||
i, err = strconv.Atoi(path)
|
||||
if err != nil {
|
||||
|
@ -145,14 +149,29 @@ func index(w http.ResponseWriter, r * http.Request) {
|
|||
|
||||
_, err = getComic(i+1)
|
||||
if err == nil {
|
||||
context.Previous = i + 1
|
||||
context.Next = i + 1
|
||||
}
|
||||
|
||||
t, err := template.ParseFiles(filepath.Join(*templatesPath, "comic.html"))
|
||||
if err != nil {
|
||||
errlog.Println(err)
|
||||
return
|
||||
}
|
||||
err = t.Execute(w, &context)
|
||||
|
||||
tmp := new(strings.Builder)
|
||||
err = t.Execute(tmp, &context)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = w.Write([]byte(tmp.String()))
|
||||
}
|
||||
|
||||
func latestView(w http.ResponseWriter, r * http.Request) {
|
||||
returnPlainText(w, "latest")
|
||||
}
|
||||
|
||||
func randomView(w http.ResponseWriter, r * http.Request) {
|
||||
returnPlainText(w, "random")
|
||||
}
|
||||
|
||||
// Taken from: https://gist.github.com/hoitomt/c0663af8c9443f2a8294
|
||||
|
@ -204,6 +223,8 @@ func return500(w http.ResponseWriter, r * http.Request) {
|
|||
|
||||
func main() {
|
||||
var err error
|
||||
|
||||
errlog = log.New(log.Writer(), "[ERROR] ", log.Flags())
|
||||
|
||||
parser := argparse.NewParser("comics", "Webserver for comics distribution websites")
|
||||
|
||||
|
@ -236,7 +257,9 @@ func main() {
|
|||
}
|
||||
|
||||
// views
|
||||
http.HandleFunc("/", index)
|
||||
http.HandleFunc("/", indexView)
|
||||
http.HandleFunc("/latest", latestView)
|
||||
http.HandleFunc("/random", randomView)
|
||||
|
||||
// errors
|
||||
http.HandleFunc("/404", return404)
|
||||
|
|
|
@ -1,9 +1,31 @@
|
|||
{{ define "nextprev" }}
|
||||
<div class="nextprev">
|
||||
<ul>
|
||||
<li><a href="/first"><<</a></li>
|
||||
<li><a href="/{{ .Previous }}">prev</a></li>
|
||||
<li><a href="/random">random</a></li>
|
||||
<li><a href="/{{ .Next }}" style="margin-left: auto;">next</a></li>
|
||||
<li><a href="/latest">>></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ define "comic" }}
|
||||
<div class="comic">
|
||||
<h2><a href="/{{ .Comic.ID }}">{{ .Comic.Title }}</a></h2>
|
||||
{{ template "nextprev" .}}
|
||||
{{ template "nextprev" .}}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="icon" type="/image/png" href="/static/img/favicon.png"/>
|
||||
<link rel="stylesheet" href="/static/css/comic.css">
|
||||
<link rel="stylesheet" href="/static/css/base.css">
|
||||
<link rel="stylesheet" href="/static/css/bar.css">
|
||||
<link rel="stylesheet" href="/static/css/top.css">
|
||||
<title>{{ .Title }}</title>
|
||||
</head>
|
||||
|
@ -11,22 +33,23 @@
|
|||
<div class="top">
|
||||
|
||||
<div class="title">
|
||||
<a href="/index.html">
|
||||
<a href="/">
|
||||
<h1>{{ .Title }}</h1>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="bar">
|
||||
<ul>
|
||||
<li><a href="/first">first</a></li>
|
||||
<li><a href="/random">random</a></li>
|
||||
<li><a href="/latest">latest</a></li>
|
||||
<li><a href="/about">about</a></li>
|
||||
<li><a href="/all">all</a></li>
|
||||
<li><a href="/blog">blog</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="content">
|
||||
</div>
|
||||
{{ template "comic" . }}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
.bar {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
color: #282828;
|
||||
background-color: #ebdbb2;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.bar ul{
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
font-weight: bold;
|
||||
}
|
||||
.bar li {
|
||||
font-size: 2em;
|
||||
display: inline-block;
|
||||
}
|
||||
.bar li:hover a {
|
||||
background-color: #282828;
|
||||
color: #ebdbb2;
|
||||
}
|
||||
.bar li a {
|
||||
display: block;
|
||||
text-align: center;
|
||||
padding: .5em;
|
||||
color: #282828;
|
||||
}
|
||||
.bar li a:link {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.bar li a:visited {
|
||||
text-decoration: none;
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
html, body {
|
||||
margin:auto;
|
||||
width: 60em;
|
||||
width: 65%;
|
||||
background: #282828;
|
||||
font-family: "JetBrainsMono", monospace;
|
||||
scroll-behavior: smooth;
|
||||
|
@ -92,11 +92,13 @@ pre {
|
|||
word-wrap: break-word;
|
||||
}
|
||||
a {
|
||||
color: #2484c1;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
a:link {
|
||||
text-decoration: none;
|
||||
}
|
||||
a:visited {
|
||||
text-decoration: none;
|
||||
}
|
||||
img {
|
||||
display: block;
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
.nextprev {
|
||||
width: 100%;
|
||||
text-transform: uppercase;
|
||||
color: #ebdbb2;
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
.nextprev ul {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
font-weight: bold;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
.nextprev li {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.nextprev li a:link {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.nextprev li a:visited {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.nextprev li a {
|
||||
display: block;
|
||||
text-align: center;
|
||||
padding: .5em;
|
||||
color: #ebdbb2;
|
||||
}
|
||||
|
||||
.nextprev li:hover a {
|
||||
background-color: #ebdbb2;
|
||||
color: #282828;
|
||||
}
|
||||
|
||||
.comic {
|
||||
text-align: center;
|
||||
overflow-wrap: break-word;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.comic h2 a {
|
||||
background-color: #282828;
|
||||
color: #ebdbb2;
|
||||
font-size: 2em;
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
.top {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
|
||||
transform: translateY(5%);
|
||||
text-transform: uppercase;
|
||||
margin-top: 2em;
|
||||
margin-bottom: 4em;
|
||||
}
|
||||
|
||||
.top .logo img {
|
||||
|
@ -13,7 +13,6 @@
|
|||
|
||||
.top .title {
|
||||
font-size: 2em;
|
||||
padding-bottom: .5em;
|
||||
text-align: center;
|
||||
}
|
||||
.top .title h1 {
|
||||
|
@ -23,7 +22,7 @@
|
|||
font-weight: bolder;
|
||||
}
|
||||
.top .title h1:hover {
|
||||
background-color: #282828;
|
||||
background-color: #282828;
|
||||
color: #ebdbb2;
|
||||
}
|
||||
|
||||
|
@ -33,40 +32,4 @@
|
|||
|
||||
.top .title a:visited {
|
||||
text-decoration: none;
|
||||
}
|
||||
.top .bar {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
color: #282828;
|
||||
background-color: #ebdbb2;
|
||||
}
|
||||
.top .bar ul{
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
font-weight: bold;
|
||||
}
|
||||
.top .bar li {
|
||||
font-size: 2em;
|
||||
display: inline-block;
|
||||
}
|
||||
.top .bar li:hover a {
|
||||
background-color: #282828;
|
||||
color: #ebdbb2;
|
||||
}
|
||||
.top .bar li a {
|
||||
display: block;
|
||||
text-align: center;
|
||||
padding: .5em;
|
||||
color: #282828;
|
||||
}
|
||||
.top .bar li a:link {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.top .bar li a:visited {
|
||||
text-decoration: none;
|
||||
}
|
Loading…
Reference in New Issue