feat: copy button
All checks were successful
/ deploy (push) Successful in 46s

This commit is contained in:
ange 2024-12-12 14:28:45 +00:00
parent b9d7553420
commit 4b530d332c
Signed by: ange
GPG Key ID: 9E0C4157BB7BEB1D
5 changed files with 65 additions and 19 deletions

View File

@ -10,4 +10,7 @@ services:
path: src/ path: src/
- action: sync+restart - action: sync+restart
path: html/ path: html/
target: /html target: html
- action: sync
path: static/
target: static

View File

@ -4,6 +4,21 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Ange DUHAYON</title> <title>Ange DUHAYON</title>
<link rel="stylesheet" href="style.css"/> <link rel="stylesheet" href="style.css"/>
<script>
function copyElem(id, r='') {
navigator.clipboard.writeText(
document.getElementById(id).innerText.replaceAll(r, ''),
);
}
function copyFile(id) {
fetch(document.getElementById(id).childNodes[0].href).then(f => {
f.text().then(t => {
navigator.clipboard.writeText(t);
})
})
}
</script>
</head> </head>
<body> <body>
<div id="header"> <div id="header">
@ -36,13 +51,41 @@
<div id="main"> <div id="main">
<table> <table>
<tr id="matrix"><td>Matrix (Element)</td><td><a href="//app.element.io/#/user/@ange:gmoker.com">@ange:gmoker.com</a></td></tr> <tr>
<tr id="discord"><td>Discord</td><td>@elrilio</td></tr> <td>Matrix (Element)</td>
<tr id="phone"><td>Phone (France)</td><td><a href="tel:+33582951623">+33 5 82 95 16 23</a></td></tr> <td id="matrix"><a href="//app.element.io/#/user/@ange:gmoker.com">@ange:gmoker.com</a></td>
<tr id="email"><td>Email</td><td><a href="mailto:ange@yw5n.com">ange@yw5n.com</a></td></tr> <td><button onclick="copyElem('matrix')">Copy</button></td>
<tr id="wa"><td>WhatsApp</td><td><a href="//wa.me/6285333559453">+62 853-3355-9453</a></td></tr> </tr>
<tr id="pgp"><td>PGP</td><td><a href="/static/pgp.asc">pgp.asc</a></td></tr> <tr>
<tr id="ssh"><td>SSH</td><td><a href="/static/ssh">ssh</a></td></tr> <td>Discord</td>
<td id="discord">@elrilio</td>
<td><button onclick="copyElem('discord')">Copy</button></td>
</tr>
<tr>
<td>Phone (France)</td>
<td id="phone"><a href="tel:+33582951623">+33 5 82 95 16 23</a></td>
<td><button onclick="copyElem('phone', / /g)">Copy</button></td>
</tr>
<tr>
<td>Email</td>
<td id="email"><a href="mailto:ange@yw5n.com">ange@yw5n.com</a></td>
<td><button onclick="copyElem('email')">Copy</button></td>
</tr>
<tr>
<td>WhatsApp</td>
<td id="wa"><a href="//wa.me/6285333559453">+62 853-3355-9453</a></td>
<td><button onclick="copyElem('wa', /[ |-]/g)">Copy</button></td>
</tr>
<tr>
<td>PGP</td>
<td id="pgp"><a href="/static/pgp.asc">pgp.asc</a></td>
<td><button onclick="copyFile('pgp')">Copy</button></td>
</tr>
<tr>
<td>SSH</td>
<td id="ssh"><a href="/static/ssh">ssh</a></td>
<td><button onclick="copyFile('ssh')">Copy</button></td>
</tr>
</table> </table>
</div> </div>

View File

@ -6,7 +6,7 @@ import (
) )
func main() { func main() {
http.HandleFunc("/", Route) http.HandleFunc("/", route)
err := http.ListenAndServe(":3000", nil) err := http.ListenAndServe(":3000", nil)
if err != nil { if err != nil {

View File

@ -15,17 +15,17 @@ var routes = []struct {
regex *regexp.Regexp regex *regexp.Regexp
handler http.HandlerFunc handler http.HandlerFunc
}{ }{
{[]string{"GET"}, URL(""), Index}, {[]string{"GET"}, url(""), index},
{[]string{"GET"}, URL("/style\\.css"), Style}, {[]string{"GET"}, url("/style\\.css"), style},
{[]string{"GET"}, URL("/static/.+"), Static}, {[]string{"GET"}, url("/static/.+"), static},
{[]string{"GET"}, URL("/[^/]+"), HTML}, {[]string{"GET"}, url("/[^/]+"), html},
} }
func URL(s string) *regexp.Regexp { func url(s string) *regexp.Regexp {
return regexp.MustCompile("^" + s + "/?$") return regexp.MustCompile("^" + s + "/?$")
} }
func Route(w http.ResponseWriter, r *http.Request) { func route(w http.ResponseWriter, r *http.Request) {
for _, rt := range routes { for _, rt := range routes {
matches := rt.regex.FindStringSubmatch(r.URL.Path) matches := rt.regex.FindStringSubmatch(r.URL.Path)
if len(matches) > 0 { if len(matches) > 0 {

View File

@ -5,18 +5,18 @@ import (
"path/filepath" "path/filepath"
) )
func Index(w http.ResponseWriter, r *http.Request) { func index(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filepath.Join("html", "index.html")) http.ServeFile(w, r, filepath.Join("html", "index.html"))
} }
func Style(w http.ResponseWriter, r *http.Request) { func style(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "/html/style.css") http.ServeFile(w, r, "/html/style.css")
} }
func Static(w http.ResponseWriter, r *http.Request) { func static(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, r.URL.Path) http.ServeFile(w, r, r.URL.Path)
} }
func HTML(w http.ResponseWriter, r *http.Request) { func html(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filepath.Join("html", r.URL.Path + ".html")) http.ServeFile(w, r, filepath.Join("html", r.URL.Path + ".html"))
} }