From b0f9ea1f49f196416ba12c098cf0b26ab61831a8 Mon Sep 17 00:00:00 2001 From: nxshock Date: Sat, 25 Sep 2021 12:38:27 +0500 Subject: [PATCH] Split site to separate files --- handlers.go | 4 +-- main.go | 8 +----- site.go | 15 ++++++++++ site/favicon.svg | 1 + site/index.htm | 24 ++++++++++++++++ site/style.css | 65 +++++++++++++++++++++++++++++++++++++++++++ templates/genres.html | 1 - 7 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 site.go create mode 100644 site/favicon.svg create mode 100644 site/index.htm create mode 100644 site/style.css delete mode 100644 templates/genres.html diff --git a/handlers.go b/handlers.go index 7f50d6b..2ea3d64 100644 --- a/handlers.go +++ b/handlers.go @@ -7,7 +7,7 @@ import ( func handleGenres(w http.ResponseWriter, r *http.Request) { if r.RequestURI != "/" { - http.Error(w, "not found", http.StatusNotFound) + http.FileServer(http.FS(stripSiteFS)).ServeHTTP(w, r) return } @@ -18,7 +18,7 @@ func handleGenres(w http.ResponseWriter, r *http.Request) { Domain: r.Host, Genres: Genres} - err := templates.Lookup("genres.html").Execute(w, data) + err := templates.Lookup("index.htm").Execute(w, data) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } diff --git a/main.go b/main.go index c90ab6c..0379977 100644 --- a/main.go +++ b/main.go @@ -1,19 +1,13 @@ package main import ( - "embed" "html/template" "log" "net/http" "os" "time" - - _ "embed" ) -//go:embed templates/genres.html -var templateBytes embed.FS - var templates *template.Template func init() { @@ -45,7 +39,7 @@ func init() { func initTepmplates() error { var err error - templates, err = template.ParseFS(templateBytes, "templates/*.html") + templates, err = template.ParseFS(siteFS, "site/*.htm") if err != nil { return err } diff --git a/site.go b/site.go new file mode 100644 index 0000000..c4c8140 --- /dev/null +++ b/site.go @@ -0,0 +1,15 @@ +package main + +import ( + "embed" + "io/fs" +) + +//go:embed site/* +var siteFS embed.FS + +var stripSiteFS fs.FS + +func init() { + stripSiteFS, _ = fs.Sub(siteFS, "site") +} diff --git a/site/favicon.svg b/site/favicon.svg new file mode 100644 index 0000000..5b668a6 --- /dev/null +++ b/site/favicon.svg @@ -0,0 +1 @@ + diff --git a/site/index.htm b/site/index.htm new file mode 100644 index 0000000..a305507 --- /dev/null +++ b/site/index.htm @@ -0,0 +1,24 @@ + + + + + + Список жанров + + + + +
+ + {{.Domain}} +
+
+

Список жанров

+ +
+ + diff --git a/site/style.css b/site/style.css new file mode 100644 index 0000000..26d6e06 --- /dev/null +++ b/site/style.css @@ -0,0 +1,65 @@ +* { + font-family: Verdana; + font-size: 16px; + color: #abb2bf; + margin: .5em; + padding: 0; +} + +html { + margin: 0; + padding: 0; + height: 100% +} + +body { + background-color: #282c34; + display: flex; + justify-content: space-between; + flex-wrap: nowrap; + flex-direction: column; + height: 100%; + margin: 0; + padding: 0; +} + +a { + text-decoration: none; + color: #61afef; +} + +svg, img { + vertical-align: middle; + width: 1em; + height: 1em; +} + +header { + flex-grow: 0; + background-color: #353b45; + border-bottom: 1px solid #3e4451; + padding: .5em; + margin: 0; +} + +h1 { + margin-top: 1em; + font-size: 150%; +} + +ul { + list-style-type: none; +} + +form { + width: calc(100% - 1em); +} + +form>input { + width: calc(100% - 2em); + padding: .5em; +} + +main { + flex-grow: 1; +} diff --git a/templates/genres.html b/templates/genres.html deleted file mode 100644 index 5983284..0000000 --- a/templates/genres.html +++ /dev/null @@ -1 +0,0 @@ -Список жанров
{{.Domain}}

Список жанров