change template

This commit is contained in:
2025-08-27 00:05:04 +02:00
parent 2c109b945e
commit 83b3a23fe4
9 changed files with 66 additions and 25 deletions

View File

@@ -15,7 +15,7 @@ import (
type (
Server struct {
r chi.Router
d data.Service
d data.Data
port uint16
}
)
@@ -26,7 +26,7 @@ var index string
//go:embed templates/description.html
var description string
func New(port uint16, d data.Service) *Server {
func New(port uint16, d data.Data) *Server {
indexTemplate := template.New("index")
indexTemplate.Parse(index)
@@ -46,7 +46,7 @@ func New(port uint16, d data.Service) *Server {
var soft data.Software
var found bool
for _, s := range d.Softwares {
if s.UUID == softID {
if s.Slug == softID {
soft = s
found = true
}

View File

@@ -13,19 +13,46 @@
<a style="margin-left: 1rem;" class="navbar-brand mb-0 h1" href="/">DownloadHub</a>
</nav>
<div class="container" style="margin-top: 1rem; margin-bottom: 1rem;">
<h2>{{.Name}} ({{.Version}})</h2>
<img width="100%" src="{{index .ScreenshotURLs 0}}" />
<h2>{{.Name}} v{{.Version}}</h2>
<hr/>
<div id="carousel" class="carousel slide">
<div class="carousel-inner">
{{ range .ScreenshotURLs }}
<div class="carousel-item">
<img src="{{ . }}" class="d-block w-100">
</div>
{{ end }}
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carousel" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carousel" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<p>{{.Description}}</p>
{{ if .Description }}
<hr />
{{ end }}
<div class="card">
<div class="card-header">
Download
Assets
</div>
<ul class="list-group list-group-flush">
{{range .DownloadLinks}}
<a href="{{.URL}}">
<li class="list-group-item">
{{.OS}} ({{.Arch}})
{{ if .Name }}
{{ if .OS }}
{{ .Name }} - {{ .OS }}/{{ .Arch }}
{{ else }}
{{ .Name }}
{{ end }}
{{ else }}
{{ .OS }}/{{ .Arch }}
{{ end }}
</li>
</a>
{{end}}

View File

@@ -12,19 +12,22 @@
<nav class="navbar navbar-light bg-light">
<span style="margin-left: 1rem;" class="navbar-brand mb-0 h1">DownloadHub</span>
</nav>
<div style="width: 100%; height: 20rem; background-color: #f2f2f2; display: flex; justify-content: center; align-items: center;">
<h1>DownloadHub</h1>
</div>
<div class="container" style="margin-top: 1rem;">
{{range .}}
<div class="row">
<div class="col-3">
<img width="100%" src="{{index .ScreenshotURLs 0}}" />
{{ range . }}
<div class="card" style="width: 18rem;">
{{ if .ScreenshotURLs }}
<img src="{{ index .ScreenshotURLs 0 }}" class="card-img-top">
{{ end }}
<div class="card-body">
<h5 class="card-title">{{ .Name }}</h5>
<p class="card-text">{{ .Description }}</p>
<a href="/d/{{ .Slug }}" class="btn btn-primary">More info</a>
</div>
<div class="col">
<h2><a href="/d/{{.UUID}}">{{.Name}}</a></h2>
<p>{{.Description}}</p>
</div>
<hr style="margin-top: 1rem;" />
</div>
{{end}}
{{ end }}
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js"

View File

@@ -16,12 +16,15 @@ func main() {
flag.Parse()
slog.Info("loading configuration...")
d := data.Load(configFile)
d, err := data.Load(configFile)
if err != nil {
panic(err)
}
slog.Info("configuration loaded!")
slog.Info(fmt.Sprintf("starting server on :%d", port))
s := api.New(uint16(port), d)
err := s.Serve()
err = s.Serve()
if err != nil {
panic(err)
}