feat: added active cards

This commit is contained in:
Hazel Noack 2025-07-14 16:36:48 +02:00
parent 4347f9632c
commit 774fa4efb1
3 changed files with 36 additions and 8 deletions

View File

@ -15,7 +15,8 @@
</div>
<input id="search-input" name="{{ .SearchInputName }}" type="text" class="grid-item" class="search" placeholder="{{ .SearchPlaceholder }}" autocomplete="off" />
{{ if eq .ActiveCard "stores" }}
<div class="cards" id="stores">
{{range $Store := .Stores }}
<a target="_blank" href="{{ $Store.Url }}" class="card">
@ -23,7 +24,9 @@
</a>
{{- end }}
</div>
{{ end }}
{{ if eq .ActiveCard "listings" }}
<div class="cards" id="listings">
{{range $Listing := .Listings }}
<a target="_blank" href="{{ $Listing.Url }}" class="card {{ if $Listing.InStock }}in-stock{{ end }}">
@ -32,6 +35,7 @@
</a>
{{- end }}
</div>
{{ end }}
</form>
<script>

View File

@ -13,6 +13,14 @@ import (
"github.com/pelletier/go-toml"
)
type ActiveCard string
const (
DiyHrtStores ActiveCard = "stores"
DiyHrtListings ActiveCard = "listings"
Websites ActiveCard = "websites"
)
type ServerConfig struct {
Port int
}
@ -26,19 +34,23 @@ type TemplateConfig struct {
SearchFormAction string
SearchInputName string
StoreFilter diyhrt.StoreFilter
StoreFilter diyhrt.StoreFilter
ListingFilter diyhrt.ListingFilter
Listings []diyhrt.Listing
Stores []diyhrt.Store
ActiveCard ActiveCard
Websites []Website
}
type Config struct{
Server ServerConfig
type Config struct {
Server ServerConfig
Template TemplateConfig
}
func NewConfig() Config{
func NewConfig() Config {
return Config{
Server: ServerConfig{
Port: 5500,
@ -60,14 +72,20 @@ func NewConfig() Config{
SearchFormAction: "https://duckduckgo.com/",
SearchInputName: "q",
ActiveCard: DiyHrtListings,
StoreFilter: diyhrt.StoreFilter{
Limit: 0,
Limit: 0,
IncludeIds: []int{7},
},
ListingFilter: diyhrt.ListingFilter{
FromStores: []int{7},
},
Websites: []Website{
{Url: "https://gitea.elara.ws/Hazel/transfem-startpage", Name: "Transfem Startpage", ImageUrl: "https://gitea.elara.ws/assets/img/logo.svg"},
},
},
}
}
@ -83,7 +101,6 @@ func (rc *TemplateConfig) LoadDiyHrt(listings []diyhrt.Listing) {
rc.Stores = rc.StoreFilter.Filter(slices.Collect(maps.Values(existingStores)))
}
func (rc *Config) ScanForConfigFile(profile string) error {
profileFile := profile + ".toml"
@ -118,5 +135,5 @@ func (rc *Config) LoadConfigFile(file string) error {
return err
}
return toml.Unmarshal(content, rc)
return toml.Unmarshal(content, rc)
}

View File

@ -0,0 +1,7 @@
package rendering
type Website struct {
Url string
Name string
ImageUrl string
}