Skip to content

Commit d3b2b56

Browse files
committed
fix: bundle css files at build time
1 parent 875d4f9 commit d3b2b56

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

assets/embed.go

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ package assets
44

55
import (
66
"embed"
7-
"fmt"
8-
"os"
9-
"path/filepath"
10-
"runtime"
11-
"sort"
7+
"slices"
128
"strings"
139
)
1410

@@ -44,31 +40,31 @@ var (
4440
VCLESISynth string
4541
)
4642

43+
//go:embed all:css
44+
var cssFiles embed.FS
45+
4746
var CombinedCSS []byte
4847

4948
func init() {
50-
// Get the directory of the current source file to ensure css files are found
51-
_, currentFile, _, ok := runtime.Caller(0)
52-
if !ok {
53-
panic("failed to get current file path")
54-
}
55-
currentDir := filepath.Dir(currentFile)
56-
cssDir := filepath.Join(currentDir, "css")
57-
58-
// Generate the combined css file
59-
matches, err := filepath.Glob(filepath.Join(cssDir, "*.css"))
49+
files, err := cssFiles.ReadDir("css")
6050
if err != nil {
6151
panic(err)
6252
}
63-
sort.Strings(matches)
53+
names := make([]string, len(files))
54+
for i, f := range files {
55+
names[i] = f.Name()
56+
}
57+
slices.Sort(names)
6458

65-
var parts []string
66-
for _, path := range matches {
67-
data, err := os.ReadFile(path)
59+
// Read and join all files
60+
var sb strings.Builder
61+
for _, name := range names {
62+
data, err := cssFiles.ReadFile("css/" + name)
6863
if err != nil {
69-
panic(fmt.Sprintf("failed to read %s: %v", path, err))
64+
panic(err)
7065
}
71-
parts = append(parts, string(data))
66+
sb.Write(data)
67+
sb.WriteByte('\n')
7268
}
73-
CombinedCSS = []byte(strings.Join(parts, "\n"))
69+
CombinedCSS = []byte(sb.String())
7470
}

0 commit comments

Comments
 (0)