Use templ

This commit is contained in:
ekzyis 2024-06-02 22:20:30 -05:00
parent 94a9782030
commit dd1880c613
5 changed files with 29 additions and 16 deletions

2
server/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# ignore files generated by `templ generate`
*_templ.go

20
server/contentMeta.templ Normal file
View File

@ -0,0 +1,20 @@
package main
import "github.com/ekzyis/snappy"
import "fmt"
templ contentMeta (item *sn.Item) {
<span class="px-1">|</span>
<span>
<a
class="underline"
href={ templ.URL(fmt.Sprintf("https://stacker.news/items/%d", item.Id)) }
target="_blank"
rel="noopener noreferrer me"
>
{ fmt.Sprintf("%d comments", item.NComments) }
</a>
</span>
<span class="px-1">|</span>
<span>{ fmt.Sprintf("%d sats", item.Sats) }</span>
}

View File

@ -2,4 +2,7 @@ module git.ekzy.is/ekzyis/ekzyis
go 1.21.9
require github.com/ekzyis/snappy v0.4.3-0.20240602063639-f18721853255 // indirect
require (
github.com/a-h/templ v0.2.707 // indirect
github.com/ekzyis/snappy v0.4.3-0.20240602063639-f18721853255 // indirect
)

View File

@ -1,3 +1,5 @@
github.com/a-h/templ v0.2.707 h1:T1Gkd2ugbRglZ9rYw/VBchWOSZVKmetDbBkm4YubM7U=
github.com/a-h/templ v0.2.707/go.mod h1:5cqsugkq9IerRNucNsI4DEamdHPsoGMQy99DzydLhM8=
github.com/ekzyis/snappy v0.4.2 h1:5Tw13OIm+w4jTmO3O4c7HzyoiAhbxKl1WzqSoi6x8GQ=
github.com/ekzyis/snappy v0.4.2/go.mod h1:BxJwdGlCwUw0Q5pQzBr59weAIS6pkVdivBBaZkkWTSo=
github.com/ekzyis/snappy v0.4.3-0.20240602063639-f18721853255 h1:3wTBDjHMmeskbCXmedyvDS7i1ZBZj0G8ZH/EJiKOgZA=

View File

@ -60,19 +60,5 @@ func HandleContentMeta(w http.ResponseWriter, r *http.Request) {
return
}
fmt.Fprintf(w,
""+
"<span class=\"px-1\">|</span>"+
"<span>"+
"<a"+
" class=\"underline\""+
" href=\"https://stacker.news/items/%d\""+
" target=\"_blank\""+
" rel=\"noopener noreferrer me\">"+
"%d comments"+
"</a>"+
"</span>"+
"<span class=\"px-1\">|</span>"+
"<span>%d sats</span>",
id, item.NComments, item.Sats)
contentMeta(item).Render(r.Context(), w)
}