diff --git a/common.go b/common.go index 6b645c2..efc9572 100755 --- a/common.go +++ b/common.go @@ -4,7 +4,9 @@ import ( "crypto/rand" "encoding/base64" "encoding/json" + "fmt" "html/template" + mathrand "math/rand" "net/http" "strings" "time" @@ -37,7 +39,17 @@ type SearchEngine struct { // Helper function to render templates without elapsed time measurement func renderTemplate(w http.ResponseWriter, tmplName string, data map[string]interface{}) { - // Parse the template with common functions (including translate) + // Generate icon paths for SVG and PNG, including a 1/10 chance for an alternate icon + iconPathSVG, iconPathPNG := GetIconPath() + + // Add icon paths to data map so they are available in all templates + if data == nil { + data = make(map[string]interface{}) + } + data["IconPathSVG"] = iconPathSVG + data["IconPathPNG"] = iconPathPNG + + // Parse and execute the template with shared functions tmpl, err := template.New(tmplName).Funcs(funcs).ParseFiles("templates/" + tmplName) if err != nil { printErr("Error parsing template: %v", err) @@ -82,3 +94,16 @@ func addProtocol(domain string) string { } return "https://" + domain } + +// GetIconPath returns both SVG and PNG icon paths, with a 1/10 chance for a randomly generated "alt" icon. +func GetIconPath() (string, string) { + // 1 in 10 chance to select an alt icon + if mathrand.Intn(10) == 0 { + // Generate a random number between 2 and 4 + altIconNumber := 2 + mathrand.Intn(3) // mathrand.Intn(3) generates 0, 1, or 2 + selectedAltIcon := "icon-alt" + fmt.Sprint(altIconNumber) + return "/static/images/" + selectedAltIcon + ".svg", "/static/images/" + selectedAltIcon + ".png" + } + // Default paths + return "/static/images/icon.svg", "/static/images/icon.png" +} diff --git a/main.go b/main.go index 3933fa2..611d583 100755 --- a/main.go +++ b/main.go @@ -116,6 +116,9 @@ func handleSearch(w http.ResponseWriter, r *http.Request) { } } + // Determine the paths for SVG and PNG icons + iconPathSVG, iconPathPNG := GetIconPath() + if query == "" { data := struct { LanguageOptions []LanguageOption @@ -124,6 +127,8 @@ func handleSearch(w http.ResponseWriter, r *http.Request) { Theme string Safe string IsThemeDark bool + IconPathSVG string + IconPathPNG string }{ LanguageOptions: languageOptions, CurrentLang: settings.SiteLanguage, @@ -131,6 +136,8 @@ func handleSearch(w http.ResponseWriter, r *http.Request) { Theme: settings.Theme, Safe: settings.SafeSearch, IsThemeDark: settings.IsThemeDark, + IconPathSVG: iconPathSVG, + IconPathPNG: iconPathPNG, } // Add Translate to the template functions diff --git a/static/images/icon-alt2.png b/static/images/icon-alt2.png new file mode 100644 index 0000000..2207266 Binary files /dev/null and b/static/images/icon-alt2.png differ diff --git a/static/images/icon2.svg b/static/images/icon-alt2.svg similarity index 100% rename from static/images/icon2.svg rename to static/images/icon-alt2.svg diff --git a/static/images/icon-alt3.png b/static/images/icon-alt3.png new file mode 100644 index 0000000..0257dc8 Binary files /dev/null and b/static/images/icon-alt3.png differ diff --git a/static/images/icon-alt3.svg b/static/images/icon-alt3.svg new file mode 100644 index 0000000..1670d6d --- /dev/null +++ b/static/images/icon-alt3.svg @@ -0,0 +1,58 @@ + + \ No newline at end of file diff --git a/static/images/icon-alt4.png b/static/images/icon-alt4.png new file mode 100644 index 0000000..36e25fe Binary files /dev/null and b/static/images/icon-alt4.png differ diff --git a/static/images/icon-alt4.svg b/static/images/icon-alt4.svg new file mode 100644 index 0000000..ce7f994 --- /dev/null +++ b/static/images/icon-alt4.svg @@ -0,0 +1,44 @@ + + \ No newline at end of file diff --git a/static/images/icon.png b/static/images/icon.png new file mode 100644 index 0000000..b94862b Binary files /dev/null and b/static/images/icon.png differ diff --git a/templates/files.html b/templates/files.html index 079899c..c25751d 100755 --- a/templates/files.html +++ b/templates/files.html @@ -9,7 +9,11 @@