initial commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package www
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"helix-proxy/internal/config"
|
||||
)
|
||||
|
||||
// LoadPage returns HTML for name (e.g. "index.html", "404.html").
|
||||
// A file in WWW_DIR with the same name overrides the embedded default.
|
||||
// Placeholders use the form {{KEY}} and are replaced from vars.
|
||||
func LoadPage(name string, vars map[string]string) []byte {
|
||||
wwwDir := config.Resolve("www")
|
||||
customPath := filepath.Join(wwwDir, name)
|
||||
|
||||
data, err := os.ReadFile(customPath)
|
||||
if err != nil {
|
||||
data, err = defaults.ReadFile(name)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if len(vars) == 0 {
|
||||
return data
|
||||
}
|
||||
s := string(data)
|
||||
for k, v := range vars {
|
||||
s = strings.ReplaceAll(s, "{{"+k+"}}", v)
|
||||
}
|
||||
return []byte(s)
|
||||
}
|
||||
Reference in New Issue
Block a user