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"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var errlog *log.Logger
|
||||||
var db *sql.DB = nil
|
var db *sql.DB = nil
|
||||||
var mediaPath *string = nil
|
var mediaPath *string = nil
|
||||||
var templatesPath *string = nil
|
var templatesPath *string = nil
|
||||||
|
@ -91,7 +92,7 @@ func insertComic(c * Comic) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func index(w http.ResponseWriter, r * http.Request) {
|
func indexView(w http.ResponseWriter, r * http.Request) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
path := strings.TrimPrefix(r.URL.Path, "/")
|
path := strings.TrimPrefix(r.URL.Path, "/")
|
||||||
|
@ -101,25 +102,28 @@ func index(w http.ResponseWriter, r * http.Request) {
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
errlog.Println(err)
|
||||||
return500(w,r)
|
return500(w,r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
c := Comic{
|
||||||
|
Title: "Test Comic",
|
||||||
|
}
|
||||||
context := struct {
|
context := struct {
|
||||||
Comic *Comic
|
Comic *Comic
|
||||||
Previous int
|
Previous int
|
||||||
Next int
|
Next int
|
||||||
Title string
|
Title string
|
||||||
}{
|
}{
|
||||||
Comic: nil,
|
Comic: &c,
|
||||||
Previous: -1,
|
Previous: 0,
|
||||||
Next: -1,
|
Next: 0,
|
||||||
Title: "Black Ram Comics",
|
Title: "Black Ram Comics",
|
||||||
}
|
}
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
c := Comic{}
|
|
||||||
if len(path) > 0{
|
if len(path) > 0{
|
||||||
i, err = strconv.Atoi(path)
|
i, err = strconv.Atoi(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -145,14 +149,29 @@ func index(w http.ResponseWriter, r * http.Request) {
|
||||||
|
|
||||||
_, err = getComic(i+1)
|
_, err = getComic(i+1)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
context.Previous = i + 1
|
context.Next = i + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := template.ParseFiles(filepath.Join(*templatesPath, "comic.html"))
|
t, err := template.ParseFiles(filepath.Join(*templatesPath, "comic.html"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
errlog.Println(err)
|
||||||
return
|
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
|
// Taken from: https://gist.github.com/hoitomt/c0663af8c9443f2a8294
|
||||||
|
@ -205,6 +224,8 @@ func return500(w http.ResponseWriter, r * http.Request) {
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
errlog = log.New(log.Writer(), "[ERROR] ", log.Flags())
|
||||||
|
|
||||||
parser := argparse.NewParser("comics", "Webserver for comics distribution websites")
|
parser := argparse.NewParser("comics", "Webserver for comics distribution websites")
|
||||||
|
|
||||||
dbPath := parser.String("d", "db-path", &argparse.Options{
|
dbPath := parser.String("d", "db-path", &argparse.Options{
|
||||||
|
@ -236,7 +257,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// views
|
// views
|
||||||
http.HandleFunc("/", index)
|
http.HandleFunc("/", indexView)
|
||||||
|
http.HandleFunc("/latest", latestView)
|
||||||
|
http.HandleFunc("/random", randomView)
|
||||||
|
|
||||||
// errors
|
// errors
|
||||||
http.HandleFunc("/404", return404)
|
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>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<link rel="icon" type="/image/png" href="/static/img/favicon.png"/>
|
<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/base.css">
|
||||||
|
<link rel="stylesheet" href="/static/css/bar.css">
|
||||||
<link rel="stylesheet" href="/static/css/top.css">
|
<link rel="stylesheet" href="/static/css/top.css">
|
||||||
<title>{{ .Title }}</title>
|
<title>{{ .Title }}</title>
|
||||||
</head>
|
</head>
|
||||||
|
@ -11,21 +33,22 @@
|
||||||
<div class="top">
|
<div class="top">
|
||||||
|
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<a href="/index.html">
|
<a href="/">
|
||||||
<h1>{{ .Title }}</h1>
|
<h1>{{ .Title }}</h1>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bar">
|
<div class="bar">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/first">first</a></li>
|
<li><a href="/about">about</a></li>
|
||||||
<li><a href="/random">random</a></li>
|
<li><a href="/all">all</a></li>
|
||||||
<li><a href="/latest">latest</a></li>
|
<li><a href="/blog">blog</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
{{ template "comic" . }}
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
37
templates/static/css/bar.css
Normal file
37
templates/static/css/bar.css
Normal file
|
@ -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 {
|
html, body {
|
||||||
margin:auto;
|
margin:auto;
|
||||||
width: 60em;
|
width: 65%;
|
||||||
background: #282828;
|
background: #282828;
|
||||||
font-family: "JetBrainsMono", monospace;
|
font-family: "JetBrainsMono", monospace;
|
||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
|
@ -92,11 +92,13 @@ pre {
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
a {
|
a {
|
||||||
color: #2484c1;
|
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
a:hover {
|
a:link {
|
||||||
text-decoration: underline;
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
a:visited {
|
||||||
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
img {
|
img {
|
||||||
display: block;
|
display: block;
|
||||||
|
|
51
templates/static/css/comic.css
Normal file
51
templates/static/css/comic.css
Normal file
|
@ -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 {
|
.top {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100vh;
|
|
||||||
|
|
||||||
transform: translateY(5%);
|
transform: translateY(5%);
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
|
margin-top: 2em;
|
||||||
|
margin-bottom: 4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.top .logo img {
|
.top .logo img {
|
||||||
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
.top .title {
|
.top .title {
|
||||||
font-size: 2em;
|
font-size: 2em;
|
||||||
padding-bottom: .5em;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.top .title h1 {
|
.top .title h1 {
|
||||||
|
@ -34,39 +33,3 @@
|
||||||
.top .title a:visited {
|
.top .title a:visited {
|
||||||
text-decoration: none;
|
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
Block a user