From 4bd60c6c1db1399de002239190a4ec76ad220c5d Mon Sep 17 00:00:00 2001 From: Gabriel Simmer Date: Sun, 24 Feb 2019 01:02:03 -0800 Subject: [PATCH] Add basic styling to listing page, fix previous directory link. --- assets/web/listing.html | 8 ++++---- assets/web/static/styles.css | 32 ++++++++++++++++++++++++++++++++ files/files.go | 4 +--- router/router.go | 4 ++-- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/assets/web/listing.html b/assets/web/listing.html index 531a363..9b0a8ea 100644 --- a/assets/web/listing.html +++ b/assets/web/listing.html @@ -10,16 +10,16 @@
-

{{$path}}

+

{{$prefix}}/{{$path}}

- ..
+

..

{{range $file := .Files}} {{ if $file.IsDir }} - {{$file.Name}}
+

{{$file.Name}}/

{{ end }} {{ if not $file.IsDir }} - {{$file.Name}}
+

{{$file.Name}}

{{end}} {{end}}
diff --git a/assets/web/static/styles.css b/assets/web/static/styles.css index e69de29..44f81d2 100644 --- a/assets/web/static/styles.css +++ b/assets/web/static/styles.css @@ -0,0 +1,32 @@ +body { + font-family: Open Sans, Arial, sans-serif; + color: #454545; + font-size: 16px; + margin: 2em auto; + max-width: 800px; + padding: 1em; + line-height: 1.4; + text-align: justify; + background-color: #fefefe; +} + +.directory, .file { + margin: 0; + border: 1px solid #454545; + margin-top: -1px; + padding: 0.5em; + -webkit-transition: background-color 0.5s linear; + -moz-transition: background-color 0.5s linear; + -ms-transition: background-color 0.5s linear; + -o-transition: background-color 0.5s linear; + transition: background-color 0.5s linear; +} + +.directory:hover, .file:hover { + background-color: lightgray; + -webkit-transition: background-color 0.5s linear; + -moz-transition: background-color 0.5s linear; + -ms-transition: background-color 0.5s linear; + -o-transition: background-color 0.5s linear; + transition: background-color 0.5s linear; +} diff --git a/files/files.go b/files/files.go index f7a91e1..366b074 100644 --- a/files/files.go +++ b/files/files.go @@ -2,7 +2,6 @@ package files import ( "encoding/json" - "fmt" "github.com/gmemstr/nas/common" "github.com/gorilla/mux" "html/template" @@ -75,7 +74,7 @@ func Listing(tier string) common.Handler { Prefix: prefix, SinglePrefix: singleprefix, } - fmt.Println(prefix) + t, err := template.ParseFiles("assets/web/listing.html") if err != nil { panic(err) @@ -93,7 +92,6 @@ func ViewFile(tier string) common.Handler { return func(rc *common.RouterContext, w http.ResponseWriter, r *http.Request) *common.HTTPError { vars := mux.Vars(r) id := vars["file"] - fmt.Println(id) d, err := ioutil.ReadFile("assets/config/config.json") if err != nil { diff --git a/router/router.go b/router/router.go index 72c646b..c7de1ec 100644 --- a/router/router.go +++ b/router/router.go @@ -49,7 +49,7 @@ func Init() *mux.Router { rootHandler(), )).Methods("GET") - r.Handle("/files", Handle( + r.Handle("/files/", Handle( files.Listing("hot"), )).Methods("GET") r.Handle(`/files/{file:[a-zA-Z0-9=\-\/.]+}`, Handle( @@ -59,7 +59,7 @@ func Init() *mux.Router { files.ViewFile("hot"), )).Methods("GET") - r.Handle("/archive", Handle( + r.Handle("/archive/", Handle( files.Listing("cold"), )).Methods("GET") r.Handle(`/archive/{file:[a-zA-Z0-9=\-\/.]+}`, Handle(