Browse Source

Integrated new search bar design for view mode toggle

main
Artemis 2 years ago
parent
commit
985f63954e
No known key found for this signature in database GPG Key ID: B13153D92467FCC1
  1. 2
      go.mod
  2. 11
      handlers.go
  3. 7
      templates/markdown.html
  4. 7
      templates/show.html

2
go.mod

@ -4,6 +4,8 @@ require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/go-redis/redis v6.15.2+incompatible
github.com/gorilla/mux v1.7.3
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/onsi/ginkgo v1.10.3 // indirect
github.com/onsi/gomega v1.7.1 // indirect
github.com/prometheus/client_golang v1.2.1

11
handlers.go

@ -23,9 +23,14 @@ type Handlers struct {
// Content is the response data structure
type Content struct {
Error string
Value string
Error string
Value string
// Those following string fields are the paste in its different view modes (raw, view, markdown, etc.)
// on a URL-prefix-basis, e.g. View may contain `/s/<code>`, raw would contain `/r/<code>`,
// and md would contain `/md/<code>`
View string
Raw string
Md string
OriginalCommand PasteSubmitCommand
}
@ -204,6 +209,7 @@ func (h Handlers) handleShowPaste(w http.ResponseWriter, req *http.Request) {
ErrIf(h.Templates.ExecuteTemplate(w, "show", &Content{
Value: res,
Raw: "/r/" + key,
Md: "/md/" + key,
}))
}
@ -240,6 +246,7 @@ func (h Handlers) HandleShowMarkdown(w http.ResponseWriter, req *http.Request) {
ErrIf(h.Templates.ExecuteTemplate(w, "markdown", &Content{
Value: res,
Raw: "/r/" + key,
View: "/s/" + key,
}))
}

7
templates/markdown.html

@ -8,10 +8,13 @@
<body>
<header class="bg-gray-200 flex flex-wrap justify-between items-center p-2">
{{template "nav"}}
<fieldset class="shadow-xl rounded bg-white text-black">
<fieldset class="shadow-xl bg-white text-black">
<a
href="{{.View}}"
class="p-2 bg-blue-400 hover:bg-blue-800 text-white rounded-l"
>Source view</a><a
href="{{.Raw}}"
class="p-2 bg-blue-400 hover:bg-blue-800 text-white rounded">View raw</a>
class="p-2 bg-blue-400 hover:bg-blue-800 text-white rounded-r">Raw view</a>
</fieldset>
</header>

7
templates/show.html

@ -9,10 +9,13 @@
<body class="bg-theme">
<header class="bg-gray-200 flex flex-wrap justify-between items-center p-2">
{{template "nav"}}
<fieldset class="shadow-xl rounded bg-white text-black">
<fieldset class="shadow-xl bg-white text-black">
<a
href="{{.Md}}"
class="p-2 bg-blue-400 hover:bg-blue-800 text-white rounded-l"
>Markdown view</a><a
href="{{.Raw}}"
class="p-2 bg-blue-400 hover:bg-blue-800 text-white rounded">View raw</a>
class="p-2 bg-blue-400 hover:bg-blue-800 text-white rounded-r">Raw view</a>
</fieldset>
</header>

Loading…
Cancel
Save