Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
dadav committed Jul 19, 2024
1 parent 4c50e0c commit abab390
Show file tree
Hide file tree
Showing 7 changed files with 361 additions and 102 deletions.
1 change: 1 addition & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
56 changes: 20 additions & 36 deletions internal/v3/ui/components/module.templ
Original file line number Diff line number Diff line change
@@ -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) {
<h3>{ module.Name }</h3>
<table>
Expand All @@ -51,23 +27,31 @@ templ ModuleView(module *gen.Module) {
</tr>
<tr>
<td>
Version
</td>
<td>
{ module.CurrentRelease.Version }
</td>
</tr>
<tr>
<td>
Dependencies
Versions
</td>
<td>
for _, dep := range deps(module.CurrentRelease.Metadata) {
<a href={ templ.URL(fmt.Sprintf("/modules/%s", normalize(dep.Name))) }>{ dep.Name } { dep.VersionRequirement }</a>
<br/>
<a href={ templ.URL(fmt.Sprintf("/modules/%s/%s", module.Slug, module.CurrentRelease.Version)) }>{ module.CurrentRelease.Version } (latest)</a>
for _, release := range module.Releases {
if module.CurrentRelease.Version != release.Version {
<br/>
<a href={ templ.URL(fmt.Sprintf("/modules/%s/%s", module.Slug, release.Version)) }>{ release.Version }</a>
}
}
</td>
</tr>
if len(deps(module.CurrentRelease.Metadata)) > 0 {
<tr>
<td>
Dependencies
</td>
<td>
for _, dep := range deps(module.CurrentRelease.Metadata) {
<a href={ templ.URL(fmt.Sprintf("/modules/%s", normalize(dep.Name))) }>{ dep.Name } { dep.VersionRequirement }</a>
<br/>
}
</td>
</tr>
}
</tbody>
</table>
}
161 changes: 95 additions & 66 deletions internal/v3/ui/components/module_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions internal/v3/ui/components/release.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package components

import (
"fmt"
gen "github.com/dadav/gorge/pkg/gen/v3/openapi"
)

templ ReleaseView(release *gen.Release) {
<h3>{ release.Module.Name }</h3>
<table>
<tbody>
<tr>
<td>
Name
</td>
<td>
{ release.Module.Name }
</td>
</tr>
<tr>
<td>
Author
</td>
<td>
<a href={ templ.URL(fmt.Sprintf("/authors/%s", release.Module.Owner.Slug)) }>{ release.Module.Owner.Username }</a>
</td>
</tr>
<tr>
<td>
Version
</td>
<td>
{ release.Version }
</td>
</tr>
<tr>
<td>
Dependencies
</td>
<td>
for _, dep := range deps(release.Metadata) {
<a href={ templ.URL(fmt.Sprintf("/modules/%s", normalize(dep.Name))) }>{ dep.Name } { dep.VersionRequirement }</a>
<br/>
}
</td>
</tr>
</tbody>
</table>
}
Loading

0 comments on commit abab390

Please sign in to comment.