diff --git a/internal/web/templates.go b/internal/web/templates.go new file mode 100644 index 0000000..88bd2cd --- /dev/null +++ b/internal/web/templates.go @@ -0,0 +1,190 @@ +package web + +import ( + "html/template" + "io" +) + +var indexTemplate = template.Must(template.New("index").Parse(` + + + + luxtools-client + + + +

luxtools-client

+ +

Endpoints

+ + + + + + {{- range .Endpoints }} + + + + + + {{- end }} + +
PathMethodsDescription
{{ .Path }}{{ .Methods }}{{ .Description }}
+ +

Info

+
{{ .InfoJSON }}
+ + +`)) + +var settingsTemplate = template.Must(template.New("settings").Parse(` + + + + luxtools-client Settings + + + +

Path Aliases

+

Define aliases like PROJECTS -> /mnt/projects. Use in /open as PROJECTS>my/repo.

+ + + + + + +
AliasPath
+
+ + +
+
+ + + + +`)) + +// RenderIndex renders the main index page. +func RenderIndex(w io.Writer, data any) error { + return indexTemplate.Execute(w, data) +} + +// RenderSettings renders the settings page. +func RenderSettings(w io.Writer) error { + return settingsTemplate.Execute(w, nil) +} diff --git a/main.go b/main.go index b19df6f..07d917c 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ import ( "luxtools-client/internal/installer" "luxtools-client/internal/notify" "luxtools-client/internal/openfolder" + "luxtools-client/internal/web" ) var version = "dev" @@ -38,180 +39,6 @@ func register(mux *http.ServeMux, docs *[]endpointDoc, path, methods, descriptio *docs = append(*docs, endpointDoc{Path: path, Methods: methods, Description: description}) } -var indexTemplate = template.Must(template.New("index").Parse(` - - - - luxtools-client - - - -

luxtools-client

- -

Endpoints

- - - - - - {{- range .Endpoints }} - - - - - - {{- end }} - -
PathMethodsDescription
{{ .Path }}{{ .Methods }}{{ .Description }}
- -

Info

-
{{ .InfoJSON }}
- - -`)) - -var settingsTemplate = template.Must(template.New("settings").Parse(` - - - - luxtools-client Settings - - - -

Path Aliases

-

Define aliases like PROJECTS -> /mnt/projects. Use in /open as PROJECTS>my/repo.

- - - - - - -
AliasPath
-
- - -
-
- - - - -`)) - type allowList []string func (a *allowList) String() string { return strings.Join(*a, ",") } @@ -383,7 +210,7 @@ func main() { } w.Header().Set("Content-Type", "text/html; charset=utf-8") - if err := indexTemplate.Execute(w, data); err != nil { + if err := web.RenderIndex(w, data); err != nil { errLog.Printf("/ index-template error=%v", err) } }) @@ -400,7 +227,7 @@ func main() { } w.Header().Set("Content-Type", "text/html; charset=utf-8") - if err := settingsTemplate.Execute(w, nil); err != nil { + if err := web.RenderSettings(w); err != nil { errLog.Printf("/settings template error=%v", err) } })