repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
c28b9f9
parent
a34af95
author
Juzexe
date
2025-07-24 09:43:23 -0400 EDT
Add copy button to Pastes
2 files changed,  +10, -0
M pkg/apps/pastes/api.go
+3, -0
 1@@ -53,6 +53,7 @@ type PostPageData struct {
 2 	Username     string
 3 	BlogName     string
 4 	Contents     template.HTML
 5+	Text         string
 6 	PublishAtISO string
 7 	PublishAt    string
 8 	ExpiresAt    string
 9@@ -219,6 +220,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
10 			Username:     username,
11 			BlogName:     blogName,
12 			Contents:     template.HTML(parsedText),
13+			Text:         post.Text,
14 			ExpiresAt:    expiresAt,
15 			Unlisted:     unlisted,
16 		}
17@@ -235,6 +237,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
18 			Username:     username,
19 			BlogName:     blogName,
20 			Contents:     "oops!  we can't seem to find this post.",
21+			Text:         "oops!  we can't seem to find this post.",
22 			ExpiresAt:    "",
23 		}
24 	}
M pkg/apps/pastes/html/post.page.tmpl
+7, -0
 1@@ -37,6 +37,13 @@
 2     <p class="font-bold m-0">expires: {{.ExpiresAt}}</p>
 3 </header>
 4 <main>
 5+<script>
 6+function copyText() {
 7+    const text = `{{.Text}}`
 8+    navigator.clipboard.writeText(text)
 9+}
10+</script>
11+    <button onclick="copyText()" class="btn mt inline-block">Copy Paste</button>
12     <article>
13         {{.Contents}}
14     </article>