29 lines
513 B
Go
29 lines
513 B
Go
package utils
|
|
|
|
import (
|
|
"github.com/goccy/go-json"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func ViteAsset(src string) string {
|
|
file, err := os.ReadFile("dist/.vite/manifest.json")
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
var viteManifestData map[string]map[string]interface{}
|
|
|
|
if err := json.Unmarshal(file, &viteManifestData); err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
src = strings.TrimPrefix(src, "/")
|
|
|
|
if _, ok := viteManifestData[src]; ok {
|
|
return "/" + viteManifestData[src]["file"].(string)
|
|
} else {
|
|
return ""
|
|
}
|
|
}
|