Skip to content

Commit c28b9f9

Browse files
Juzexeneurosnap
authored andcommitted
Add copy button to Pastes
1 parent a34af95 commit c28b9f9

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/apps/pastes/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type PostPageData struct {
5353
Username string
5454
BlogName string
5555
Contents template.HTML
56+
Text string
5657
PublishAtISO string
5758
PublishAt string
5859
ExpiresAt string
@@ -219,6 +220,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
219220
Username: username,
220221
BlogName: blogName,
221222
Contents: template.HTML(parsedText),
223+
Text: post.Text,
222224
ExpiresAt: expiresAt,
223225
Unlisted: unlisted,
224226
}
@@ -235,6 +237,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
235237
Username: username,
236238
BlogName: blogName,
237239
Contents: "oops! we can't seem to find this post.",
240+
Text: "oops! we can't seem to find this post.",
238241
ExpiresAt: "",
239242
}
240243
}

pkg/apps/pastes/html/post.page.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
<p class="font-bold m-0">expires: {{.ExpiresAt}}</p>
3838
</header>
3939
<main>
40+
<script>
41+
function copyText() {
42+
const text = `{{.Text}}`
43+
navigator.clipboard.writeText(text)
44+
}
45+
</script>
46+
<button onclick="copyText()" class="btn mt inline-block">Copy Paste</button>
4047
<article>
4148
{{.Contents}}
4249
</article>

0 commit comments

Comments
 (0)