diff --git a/go.mod b/go.mod
index 5ab40bc..34c0e2c 100644
--- a/go.mod
+++ b/go.mod
@@ -7,6 +7,8 @@ require (
github.com/spf13/viper v1.18.2
)
+require golang.org/x/net v0.24.0 // indirect
+
require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
diff --git a/go.sum b/go.sum
index e4a48c7..ffc43f3 100644
--- a/go.sum
+++ b/go.sum
@@ -102,6 +102,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
+golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
+golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
diff --git a/src/index.html b/src/index.html
index bbc841e..62b7b5f 100644
--- a/src/index.html
+++ b/src/index.html
@@ -5,7 +5,7 @@
{{ block "meta" . }}{{end}}
diff --git a/src/views/components/navbar.html b/src/views/components/navbar.html
index 320125b..fd373a6 100644
--- a/src/views/components/navbar.html
+++ b/src/views/components/navbar.html
@@ -27,7 +27,7 @@
-
+ {{ viteAsset "/assets/download.png" `alt="user profile image"` }}
diff --git a/utils/template_funcs.go b/utils/template_funcs.go
index a8aa10c..5aef9ec 100644
--- a/utils/template_funcs.go
+++ b/utils/template_funcs.go
@@ -1,13 +1,17 @@
package utils
import (
+ "fmt"
"github.com/goccy/go-json"
+ "html/template"
"log"
+ "mime"
"os"
"strings"
)
-func ViteAsset(src string) string {
+func ViteAsset(src string, attrs ...string) template.HTML {
+
file, err := os.ReadFile("dist/.vite/manifest.json")
if err != nil {
log.Fatalln(err)
@@ -21,9 +25,51 @@ func ViteAsset(src string) string {
src = strings.TrimPrefix(src, "/")
- if _, ok := viteManifestData[src]; ok {
- return "/" + viteManifestData[src]["file"].(string)
- } else {
+ var element string
+
+ info, ok := viteManifestData[src]
+ if !ok {
return ""
}
+
+ filenameSplit := strings.Split(info["file"].(string), ".")
+
+ if len(filenameSplit) < 2 {
+ return ""
+ }
+
+ fileExt := filenameSplit[len(filenameSplit)-1]
+
+ mimeType := mime.TypeByExtension("." + fileExt)
+
+ if strings.HasPrefix(mimeType, "image/") {
+ element = fmt.Sprintf(`
"
+ } else if strings.Contains(mimeType, "text/javascript") {
+
+ element = fmt.Sprintf(`"
+
+ } else if strings.Contains(mimeType, "text/css") {
+
+ element = fmt.Sprintf(`
`, info["file"].(string))
+
+ }
+
+ return template.HTML(element)
+
}