change template
This commit is contained in:
@@ -15,6 +15,7 @@ type (
|
||||
LinkCmd struct {
|
||||
os string
|
||||
arch string
|
||||
name string
|
||||
out string
|
||||
}
|
||||
)
|
||||
@@ -33,6 +34,7 @@ Options:
|
||||
func (p *LinkCmd) SetFlags(f *flag.FlagSet) {
|
||||
f.StringVar(&p.os, "os", "", "set the operating system")
|
||||
f.StringVar(&p.arch, "architecture", "", "set the instruction set")
|
||||
f.StringVar(&p.name, "name", "", "set the name or label of the link")
|
||||
f.StringVar(&p.out, "out", "./config.json", "path to the configuration file")
|
||||
}
|
||||
|
||||
@@ -74,6 +76,7 @@ func (p *LinkCmd) add(link, slug string) subcommands.ExitStatus {
|
||||
soft.DownloadLinks = append(soft.DownloadLinks, data.DownloadLink{
|
||||
OS: p.os,
|
||||
Arch: p.arch,
|
||||
Name: p.name,
|
||||
URL: link,
|
||||
})
|
||||
d.Softwares[i] = soft
|
||||
@@ -114,6 +117,10 @@ func (p *LinkCmd) edit(link, slug string) subcommands.ExitStatus {
|
||||
l.Arch = p.arch
|
||||
}
|
||||
|
||||
if len(p.name) > 0 {
|
||||
l.Name = p.name
|
||||
}
|
||||
|
||||
soft.DownloadLinks[y] = l
|
||||
foundLink = true
|
||||
break
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user