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 c22543e commit 4c50e0c
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 33 deletions.
6 changes: 3 additions & 3 deletions internal/v3/ui/components/author_templ.go

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

2 changes: 1 addition & 1 deletion internal/v3/ui/components/head_templ.go

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

35 changes: 35 additions & 0 deletions internal/v3/ui/components/module.templ
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
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 Down Expand Up @@ -33,6 +57,17 @@ templ ModuleView(module *gen.Module) {
{ module.CurrentRelease.Version }
</td>
</tr>
<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>
}
107 changes: 94 additions & 13 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.

3 changes: 3 additions & 0 deletions internal/v3/ui/components/page.templ
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ templ Page(title string, content templ.Component) {
</ul>
</details>
</li>
<li>
<a href="/statistics">Stats</a>
</li>
</ul>
</nav>
</header>
Expand Down
2 changes: 1 addition & 1 deletion internal/v3/ui/components/page_templ.go

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

2 changes: 1 addition & 1 deletion internal/v3/ui/components/search.templ
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ templ SearchView() {

templ ModuleToTableRow(module *gen.Module) {
<tr>
<td><a href={ templ.URL(fmt.Sprintf("/modules/%s", module.Name)) }>{ module.Name }</a></td>
<td><a href={ templ.URL(fmt.Sprintf("/modules/%s", module.Slug)) }>{ module.Name }</a></td>
<td><a href={ templ.URL(fmt.Sprintf("/authors/%s", module.Owner.Slug)) }>{ module.Owner.Username }</a></td>
<td>{ module.CurrentRelease.Version }</td>
</tr>
Expand Down
8 changes: 4 additions & 4 deletions internal/v3/ui/components/search_templ.go

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

14 changes: 7 additions & 7 deletions internal/v3/ui/components/statistics_templ.go

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

6 changes: 3 additions & 3 deletions internal/v3/ui/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func AuthorHandler(w http.ResponseWriter, r *http.Request) {
}

func ModuleHandler(w http.ResponseWriter, r *http.Request) {
moduleName := chi.URLParam(r, "module")
moduleSlug := chi.URLParam(r, "module")
modules, err := backend.ConfiguredBackend.GetAllModules()
if err != nil {
w.WriteHeader(500)
Expand All @@ -68,8 +68,8 @@ func ModuleHandler(w http.ResponseWriter, r *http.Request) {
}

for _, module := range modules {
if module.Name == moduleName {
templ.Handler(components.Page(module.Name, components.ModuleView(module))).ServeHTTP(w, r)
if module.Slug == moduleSlug {
templ.Handler(components.Page(module.Slug, components.ModuleView(module))).ServeHTTP(w, r)
return
}
}
Expand Down

0 comments on commit 4c50e0c

Please sign in to comment.