Skip to content

Commit

Permalink
Revert "fix: implement more healthly way to access iconsjson string (#17
Browse files Browse the repository at this point in the history
)"

This reverts commit 2d31066.
  • Loading branch information
LelouchFR authored May 11, 2024
1 parent 2d31066 commit ff87c7f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
7 changes: 0 additions & 7 deletions api/icons.go

This file was deleted.

5 changes: 4 additions & 1 deletion api/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
var icons map[string]string = make(map[string]string)
var iconNameList []string
var themedIcons []string



var shortNames = map[string]string{
"js": "javascript",
"ts": "typescript",
Expand Down Expand Up @@ -229,7 +232,7 @@ func init() {
}

func Handler(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(strings.NewReader(IconsJSON))
decoder := json.NewDecoder(strings.NewReader(iconsJSON))
if err := decoder.Decode(&icons); err != nil {
panic(err)
}
Expand Down
17 changes: 13 additions & 4 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,59 @@ import (
)

func main() {
// Read directory contents
iconsDir, err := os.ReadDir("./assets")
if err != nil {
panic(err)
}

// Initialize map for icons
icons := make(map[string]string)

// Iterate through directory contents
for _, fileInfo := range iconsDir {
if !fileInfo.IsDir() {
// Read file contents
data, err := os.ReadFile("./assets/" + fileInfo.Name())
if err != nil {
panic(err)
}

// Add file content to map
name := strings.TrimSuffix(strings.ToLower(fileInfo.Name()), ".svg")
icons[name] = string(data)
}
}

// Convert icons to JSON
iconsJSON, err := json.Marshal(icons)
if err != nil {
panic(err)
}

indexFile, err := os.ReadFile("./api/icons.go")
// Read content of api/index.go
indexFile, err := os.ReadFile("./api/index.go")
if err != nil {
panic(err)
}

// Convert content to string
indexContent := string(indexFile)

// Split the content by newlines
lines := strings.Split(indexContent, "\n")

// Insert the iconsJSON into line 18
lines[6] = fmt.Sprintf("\n\tvar iconsJSON string = `%s`\n", iconsJSON)
lines[17] = fmt.Sprintf("\n\tvar iconsJSON = `%s`\n", iconsJSON)

// Join the lines back into a single string
modifiedContent := strings.Join(lines, "\n")

// Write the modified content back to the file
err = os.WriteFile("./api/icons.go", []byte(modifiedContent), 0644)
err = os.WriteFile("./api/index.go", []byte(modifiedContent), 0644)
if err != nil {
panic(err)
}

fmt.Println("Modified content saved to api/icons.go")
fmt.Println("Modified content saved to api/index.go")
}

0 comments on commit ff87c7f

Please sign in to comment.