Skip to content

Commit

Permalink
improve templates, redirect after upload
Browse files Browse the repository at this point in the history
  • Loading branch information
robbymilo committed Dec 6, 2022
1 parent 390a102 commit e112618
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 39 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {

}

http.Redirect(w, r, path, http.StatusSeeOther)
fmt.Fprintf(w, "Upload successful")

}
Expand Down
51 changes: 47 additions & 4 deletions templates/example.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
{{define "title"}}A templated page{{end}}
{{ define "title" }}
{{ .current }}
{{ end }}

{{define "body"}}
<h1>Hello from a templated page</h1>
{{end}}
{{ define "upload" }}
<div>
<form enctype="multipart/form-data" action="/upload" autocomplete="off" method="post">
<div>
<input type="text" id="path" name="path" placeholder="Folder to upload file(s)" value="{{ .current }}">
<label for="path">Folder to upload files(s)</label>
</div>
<input type="file" id="filenae" name="filename" multiple>
<div>
<input type="submit" value="Upload">
</div>
</form>
</div>
{{ end }}

{{ define "breadcrumb" }}
<div>
<span>
<a href="/"><svg width="16" height="16" viewBox="0 0 16 16"><path d="M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5z"></path></svg></a>
<span>/</span>
</span>
{{ $paths := .paths }}
{{ $len := len .paths }}
{{ $r := "" }}
{{- range $i, $e := .paths -}}
{{ $r = print $r "/" $e.Name }}
<a href="{{ $r }}/">{{ $e.Name }}</a>
<span> / </span>
{{- end -}}
</div>
{{ end }}

{{ define "body" }}
{{ range .dirs }}
<div>
<a href="/{{ .Value }}">{{ .Name }}</a>
</div>
{{ end }}
{{ range .files }}
<div>
<a href="/{{ .Value }}">{{ .Name }}</a>
</div>
{{ end }}
{{ end }}
41 changes: 6 additions & 35 deletions templates/layout.html
Original file line number Diff line number Diff line change
@@ -1,46 +1,17 @@
{{define "layout"}}
{{ define "layout" }}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{{template "title"}}</title>
<title>{{ template "title" }}</title>
<link rel="stylesheet" href="/assets/style.css">
</head>
<body>
<div>
<form enctype="multipart/form-data" action="/upload" autocomplete="off" method="post">
<input type="text" id="path" name="path" placeholder="Folder to uploader file(s) to" value="{{ .current }}">
<input type="file" id="filenae" name="filename" multiple>
{{/* <input type="hidden" name="path" value="{{ .current }}"> */}}
<input type="submit" value="Upload">
</form>
</div>
{{ template "upload" . }}
<hr>
<div>
<span>
<a href="/">Home</a>
<span>/</span>
</span>
{{ $paths := .paths }}
{{ $len := len .paths }}
{{ $r := "" }}
{{- range $i, $e := .paths -}}
{{ $r = print $r "/" $e.Name }}
<a href="{{ $r }}/">{{ $e.Name }}</a>
<span> / </span>
{{- end -}}
</div>
{{ template "breadcrumb" . }}
<hr>
{{ range .dirs }}
<div>
Dir: <a href="/{{ .Value }}">{{ .Name }}</a>
</div>
{{ end }}
{{ range .files }}
<div>
File: <a href="/{{ .Value }}">{{ .Name }}</a>
</div>
{{ end }}
{{ template "body" . }}
</body>
</html>
{{end}}
{{ end }}

0 comments on commit e112618

Please sign in to comment.