Added post copy button + hyperscript
This commit is contained in:
parent
80e94aee69
commit
35304c1f81
7 changed files with 33 additions and 2 deletions
12
api/post.copy.go
Normal file
12
api/post.copy.go
Normal 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
2
go.mod
|
@ -1,6 +1,6 @@
|
||||||
module goth.stack
|
module goth.stack
|
||||||
|
|
||||||
go 1.22.0
|
go 1.22
|
||||||
|
|
||||||
require github.com/alecthomas/chroma/v2 v2.12.0
|
require github.com/alecthomas/chroma/v2 v2.12.0
|
||||||
|
|
||||||
|
|
1
main.go
1
main.go
|
@ -72,6 +72,7 @@ func main() {
|
||||||
// API Routes:
|
// API Routes:
|
||||||
apiGroup := e.Group("/api")
|
apiGroup := e.Group("/api")
|
||||||
apiGroup.GET("/ping", api.Ping)
|
apiGroup.GET("/ping", api.Ping)
|
||||||
|
apiGroup.GET("/post/copy", api.PostCopy)
|
||||||
|
|
||||||
apiGroup.GET("/sse", func(c echo.Context) error {
|
apiGroup.GET("/sse", func(c echo.Context) error {
|
||||||
return api.SSE(c, pubSub)
|
return api.SSE(c, pubSub)
|
||||||
|
|
|
@ -32,12 +32,27 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{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>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
{{template "main" .}}
|
{{template "main" .}}
|
||||||
|
|
||||||
</article>
|
</article>
|
||||||
</main>
|
</main>
|
||||||
|
{{template "foot" .}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
{{end}}
|
{{end}}
|
|
@ -14,4 +14,6 @@ GOTH // Post
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "foot"}}
|
{{define "foot"}}
|
||||||
|
<script src="/public/js/htmx.base.js"></script>
|
||||||
|
<script src="/public/js/hyperscript.js"></script>
|
||||||
{{end}}
|
{{end}}
|
2
public/css/styles.css
vendored
2
public/css/styles.css
vendored
File diff suppressed because one or more lines are too long
1
public/js/hyperscript.js
vendored
Normal file
1
public/js/hyperscript.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue