refactored diy hrt in proper struct

This commit is contained in:
Hazel Noack 2025-07-15 11:41:36 +02:00
parent 231ceea80a
commit 1e7bbc6e16
4 changed files with 23 additions and 16 deletions

View File

@ -0,0 +1,7 @@
package diyhrt
type DiyHrtConfig struct {
ApiKey string
StoreFilter StoreFilter
ListingFilter ListingFilter
}

View File

@ -34,9 +34,6 @@ type TemplateConfig struct {
SearchFormAction string
SearchInputName string
StoreFilter diyhrt.StoreFilter
ListingFilter diyhrt.ListingFilter
Listings []diyhrt.Listing
Stores []diyhrt.Store
@ -48,6 +45,7 @@ type TemplateConfig struct {
type Config struct {
Server ServerConfig
Template TemplateConfig
DiyHrt diyhrt.DiyHrtConfig
}
func NewConfig() Config {
@ -55,6 +53,16 @@ func NewConfig() Config {
Server: ServerConfig{
Port: 5500,
},
DiyHrt: diyhrt.DiyHrtConfig{
ApiKey: os.Getenv("API_KEY"),
StoreFilter: diyhrt.StoreFilter{
Limit: 0,
IncludeIds: []int{7},
},
ListingFilter: diyhrt.ListingFilter{
FromStores: []int{7},
},
},
Template: TemplateConfig{
HeaderPhrases: []string{
"GirlJuice.Inject();",
@ -74,15 +82,6 @@ func NewConfig() Config {
ActiveCard: DiyHrtListings,
StoreFilter: diyhrt.StoreFilter{
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"},
},
@ -90,15 +89,15 @@ func NewConfig() Config {
}
}
func (rc *TemplateConfig) LoadDiyHrt(listings []diyhrt.Listing) {
func (c *Config) LoadDiyHrt(listings []diyhrt.Listing) {
existingStores := make(map[int]diyhrt.Store)
for _, listing := range listings {
existingStores[listing.Store.Id] = listing.Store
}
rc.Listings = rc.ListingFilter.Filter(listings)
rc.Stores = rc.StoreFilter.Filter(slices.Collect(maps.Values(existingStores)))
c.Template.Listings = c.DiyHrt.ListingFilter.Filter(listings)
c.Template.Stores = c.DiyHrt.StoreFilter.Filter(slices.Collect(maps.Values(existingStores)))
}
func (rc *Config) ScanForConfigFile(profile string) error {

View File

@ -25,7 +25,7 @@ func FetchDiyHrt() error {
if err != nil {
return err
}
CurrentConfig.Template.LoadDiyHrt(l)
CurrentConfig.LoadDiyHrt(l)
return nil
}

1
tmp/build-errors.log Normal file
View File

@ -0,0 +1 @@
exit status 1