diff --git a/cmd/serve.go b/cmd/serve.go index d173799..0c2f186 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -155,6 +155,7 @@ You can also enable the caching functionality to speed things up.`, r.HandleFunc("/", ui.IndexHandler) r.HandleFunc("/search", ui.SearchHandler) r.HandleFunc("/modules/{module}", ui.ModuleHandler) + r.HandleFunc("/modules/{module}/{version}", ui.ReleaseHandler) r.HandleFunc("/authors/{author}", ui.AuthorHandler) r.HandleFunc("/statistics", ui.StatisticsHandler(x)) r.Handle("/assets/*", ui.HandleAssets()) diff --git a/internal/v3/ui/components/module.templ b/internal/v3/ui/components/module.templ index b5cb3d5..5b117e1 100644 --- a/internal/v3/ui/components/module.templ +++ b/internal/v3/ui/components/module.templ @@ -1,34 +1,10 @@ package components import ( - "encoding/json" "fmt" - model "github.com/dadav/gorge/internal/model" gen "github.com/dadav/gorge/pkg/gen/v3/openapi" - "strings" ) -func deps(metadata map[string]interface{}) []model.ModuleDependency { - var result model.ReleaseMetadata - - jsonStr, err := json.Marshal(metadata) - if err != nil { - return nil - } - - err = json.Unmarshal(jsonStr, &result) - - if err != nil { - return nil - } - - return result.Dependencies -} - -func normalize(name string) string { - return strings.Replace(name, "/", "-", 1) -} - templ ModuleView(module *gen.Module) {

{ module.Name }

@@ -51,23 +27,31 @@ templ ModuleView(module *gen.Module) { - - - - + if len(deps(module.CurrentRelease.Metadata)) > 0 { + + + + + }
- Version - - { module.CurrentRelease.Version } -
- Dependencies + Versions - for _, dep := range deps(module.CurrentRelease.Metadata) { - { dep.Name } { dep.VersionRequirement } -
+ { module.CurrentRelease.Version } (latest) + for _, release := range module.Releases { + if module.CurrentRelease.Version != release.Version { +
+ { release.Version } + } }
+ Dependencies + + for _, dep := range deps(module.CurrentRelease.Metadata) { + { dep.Name } { dep.VersionRequirement } +
+ } +
} diff --git a/internal/v3/ui/components/module_templ.go b/internal/v3/ui/components/module_templ.go index 9daeca7..c089c61 100644 --- a/internal/v3/ui/components/module_templ.go +++ b/internal/v3/ui/components/module_templ.go @@ -9,34 +9,10 @@ import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" import ( - "encoding/json" "fmt" - model "github.com/dadav/gorge/internal/model" gen "github.com/dadav/gorge/pkg/gen/v3/openapi" - "strings" ) -func deps(metadata map[string]interface{}) []model.ModuleDependency { - var result model.ReleaseMetadata - - jsonStr, err := json.Marshal(metadata) - if err != nil { - return nil - } - - err = json.Unmarshal(jsonStr, &result) - - if err != nil { - return nil - } - - return result.Dependencies -} - -func normalize(name string) string { - return strings.Replace(name, "/", "-", 1) -} - func ModuleView(module *gen.Module) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context @@ -62,7 +38,7 @@ func ModuleView(module *gen.Module) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(module.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 33, Col: 18} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 9, Col: 18} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -75,7 +51,7 @@ func ModuleView(module *gen.Module) templ.Component { var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(module.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 41, Col: 18} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 17, Col: 18} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -97,71 +73,124 @@ func ModuleView(module *gen.Module) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(module.Owner.Username) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 49, Col: 97} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 25, Col: 97} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Version") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Versions") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Dependencies") + var templ_7745c5c3_Var7 string + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(module.CurrentRelease.Version) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 33, Col: 133} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - for _, dep := range deps(module.CurrentRelease.Metadata) { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var8 string - templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(dep.Name) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 66, Col: 87} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" (latest) ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, release := range module.Releases { + if module.CurrentRelease.Version != release.Version { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var9 string + templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(release.Version) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 37, Col: 107} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(deps(module.CurrentRelease.Metadata)) > 0 { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Dependencies") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var9 string - templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(dep.VersionRequirement) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 66, Col: 114} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err + for _, dep := range deps(module.CurrentRelease.Metadata) { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var11 string + templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(dep.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 49, Col: 88} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var12 string + templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(dep.VersionRequirement) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/module.templ`, Line: 49, Col: 115} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/v3/ui/components/release.templ b/internal/v3/ui/components/release.templ new file mode 100644 index 0000000..c21154c --- /dev/null +++ b/internal/v3/ui/components/release.templ @@ -0,0 +1,49 @@ +package components + +import ( + "fmt" + gen "github.com/dadav/gorge/pkg/gen/v3/openapi" +) + +templ ReleaseView(release *gen.Release) { +

{ release.Module.Name }

+ + + + + + + + + + + + + + + + + + + +
+ Name + + { release.Module.Name } +
+ Author + + { release.Module.Owner.Username } +
+ Version + + { release.Version } +
+ Dependencies + + for _, dep := range deps(release.Metadata) { + { dep.Name } { dep.VersionRequirement } +
+ } +
+} diff --git a/internal/v3/ui/components/release_templ.go b/internal/v3/ui/components/release_templ.go new file mode 100644 index 0000000..a823a1a --- /dev/null +++ b/internal/v3/ui/components/release_templ.go @@ -0,0 +1,146 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.747 +package components + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import ( + "fmt" + gen "github.com/dadav/gorge/pkg/gen/v3/openapi" +) + +func ReleaseView(release *gen.Release) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var2 string + templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(release.Module.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/release.templ`, Line: 9, Col: 26} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Name") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(release.Module.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/release.templ`, Line: 17, Col: 26} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Author") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(release.Module.Owner.Username) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/release.templ`, Line: 25, Col: 113} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Version") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var6 string + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(release.Version) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/release.templ`, Line: 33, Col: 22} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Dependencies") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, dep := range deps(release.Metadata) { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var8 string + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(dep.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/release.templ`, Line: 42, Col: 87} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var9 string + templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(dep.VersionRequirement) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/v3/ui/components/release.templ`, Line: 42, Col: 114} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} diff --git a/internal/v3/ui/components/utils.go b/internal/v3/ui/components/utils.go new file mode 100644 index 0000000..b5aeb03 --- /dev/null +++ b/internal/v3/ui/components/utils.go @@ -0,0 +1,28 @@ +package components + +import ( + "encoding/json" + "strings" + + model "github.com/dadav/gorge/internal/model" +) + +func deps(metadata map[string]interface{}) []model.ModuleDependency { + var result model.ReleaseMetadata + + jsonStr, err := json.Marshal(metadata) + if err != nil { + return nil + } + + err = json.Unmarshal(jsonStr, &result) + if err != nil { + return nil + } + + return result.Dependencies +} + +func normalize(name string) string { + return strings.Replace(name, "/", "-", 1) +} diff --git a/internal/v3/ui/handlers.go b/internal/v3/ui/handlers.go index 732ab82..bd95d97 100644 --- a/internal/v3/ui/handlers.go +++ b/internal/v3/ui/handlers.go @@ -58,6 +58,28 @@ func AuthorHandler(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) } +func ReleaseHandler(w http.ResponseWriter, r *http.Request) { + moduleSlug := chi.URLParam(r, "module") + version := chi.URLParam(r, "version") + releases, err := backend.ConfiguredBackend.GetAllReleases() + if err != nil { + w.WriteHeader(500) + log.Log.Error(err) + return + } + + for _, release := range releases { + if release.Module.Slug == moduleSlug && release.Version == version { + if release.Version == version { + templ.Handler(components.Page(release.Slug, components.ReleaseView(release))).ServeHTTP(w, r) + return + } + } + } + + http.NotFound(w, r) +} + func ModuleHandler(w http.ResponseWriter, r *http.Request) { moduleSlug := chi.URLParam(r, "module") modules, err := backend.ConfiguredBackend.GetAllModules()