Template
1
0
Fork 0

Added post copy button + hyperscript

This commit is contained in:
Atridad Lahiji 2024-02-12 09:12:21 -07:00
parent 80e94aee69
commit 35304c1f81
No known key found for this signature in database
7 changed files with 33 additions and 2 deletions

12
api/post.copy.go Normal file
View file

@ -0,0 +1,12 @@
package api
import (
"net/http"
"github.com/labstack/echo/v4"
)
func PostCopy(c echo.Context) error {
return c.String(http.StatusOK, `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`)
}

2
go.mod
View file

@ -1,6 +1,6 @@
module goth.stack
go 1.22.0
go 1.22
require github.com/alecthomas/chroma/v2 v2.12.0

View file

@ -72,6 +72,7 @@ func main() {
// API Routes:
apiGroup := e.Group("/api")
apiGroup.GET("/ping", api.Ping)
apiGroup.GET("/post/copy", api.PostCopy)
apiGroup.GET("/sse", func(c echo.Context) error {
return api.SSE(c, pubSub)

View file

@ -32,12 +32,27 @@
{{end}}
</div>
{{end}}
<div id="svgContainer" style="display: none;">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-check-circle"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><path d="m9 11 3 3L22 4"/></svg>
</div>
<button id="copyButton" hx-get="/api/post/copy" hx-swap="innerHTML" hx-trigger="click delay:3s" _='on click put #svgContainer.innerHTML into me.innerHTML then call navigator.clipboard.writeText(window.location.href)'>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>
</button>
<a href="/blog" class="btn btn-primary btn-outline">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-undo-2"><path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5v0a5.5 5.5 0 0 1-5.5 5.5H11"/></svg>
Back
</a>
</div>
<hr />
{{template "main" .}}
</article>
</main>
{{template "foot" .}}
</body>
</html>
{{end}}

View file

@ -14,4 +14,6 @@ GOTH // Post
{{end}}
{{define "foot"}}
<script src="/public/js/htmx.base.js"></script>
<script src="/public/js/hyperscript.js"></script>
{{end}}

File diff suppressed because one or more lines are too long

1
public/js/hyperscript.js vendored Normal file

File diff suppressed because one or more lines are too long