From f8d0c0760d9b12cf91558b1a97e9099b8eae5c41 Mon Sep 17 00:00:00 2001 From: TheLastBilly Date: Thu, 18 May 2023 23:26:18 -0400 Subject: [PATCH] started main site design --- main.go | 39 ++++++++++++++++++++------ templates/comic.html | 35 +++++++++++++++++++---- templates/static/css/bar.css | 37 ++++++++++++++++++++++++ templates/static/css/base.css | 10 ++++--- templates/static/css/comic.css | 51 ++++++++++++++++++++++++++++++++++ templates/static/css/top.css | 43 ++-------------------------- 6 files changed, 157 insertions(+), 58 deletions(-) create mode 100644 templates/static/css/bar.css create mode 100644 templates/static/css/comic.css diff --git a/main.go b/main.go index 0d6ba8c..8ba3c28 100644 --- a/main.go +++ b/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) diff --git a/templates/comic.html b/templates/comic.html index f3c685d..2ca45ce 100644 --- a/templates/comic.html +++ b/templates/comic.html @@ -1,9 +1,31 @@ +{{ define "nextprev" }} +
+ +
+{{ end }} + +{{ define "comic" }} +
+

{{ .Comic.Title }}

+{{ template "nextprev" .}} +{{ template "nextprev" .}} +
+{{ end }} + + + {{ .Title }} @@ -11,22 +33,23 @@
- +
-
+ {{ template "comic" . }} + diff --git a/templates/static/css/bar.css b/templates/static/css/bar.css new file mode 100644 index 0000000..202f4ba --- /dev/null +++ b/templates/static/css/bar.css @@ -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; +} \ No newline at end of file diff --git a/templates/static/css/base.css b/templates/static/css/base.css index cf384e0..9dfece0 100644 --- a/templates/static/css/base.css +++ b/templates/static/css/base.css @@ -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; diff --git a/templates/static/css/comic.css b/templates/static/css/comic.css new file mode 100644 index 0000000..73044aa --- /dev/null +++ b/templates/static/css/comic.css @@ -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; +} diff --git a/templates/static/css/top.css b/templates/static/css/top.css index 7b7ed13..cf54e9e 100644 --- a/templates/static/css/top.css +++ b/templates/static/css/top.css @@ -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; } \ No newline at end of file