added config options for website targets

This commit is contained in:
Hazel Noack 2025-07-15 17:42:43 +02:00
parent e5c7dc6f44
commit fbbd78ce72
3 changed files with 23 additions and 7 deletions

View File

@ -43,7 +43,6 @@ air dev
## TODO ## TODO
- configure target of website cards
- implementing proper command line args - implementing proper command line args
- clear cache - clear cache
- implement fetching in intervals - implement fetching in intervals

View File

@ -18,8 +18,9 @@
{{ if eq .ActiveCard "stores" }} {{ if eq .ActiveCard "stores" }}
<div class="cards" id="stores"> <div class="cards" id="stores">
{{ $T := .DiyHrtTarget }}
{{range $Store := .Stores }} {{range $Store := .Stores }}
<a target="_blank" href="{{ $Store.Url }}" class="card"> <a target="{{ $T }}" href="{{ $Store.Url }}" class="card">
<h3>{{ $Store.Name }}</h3> <h3>{{ $Store.Name }}</h3>
</a> </a>
{{- end }} {{- end }}
@ -28,8 +29,9 @@
{{ if eq .ActiveCard "listings" }} {{ if eq .ActiveCard "listings" }}
<div class="cards" id="listings"> <div class="cards" id="listings">
{{ $T := .DiyHrtTarget }}
{{range $Listing := .Listings }} {{range $Listing := .Listings }}
<a target="_blank" href="{{ $Listing.Url }}" class="card {{ if $Listing.InStock }}in-stock{{ end }}"> <a target="{{ $T }}" href="{{ $Listing.Url }}" class="card {{ if $Listing.InStock }}in-stock{{ end }}">
<h3>{{ $Listing.ProductName }}</h3> <h3>{{ $Listing.ProductName }}</h3>
<p>{{ $Listing.StoreName }} - {{ $Listing.Price }} {{ $Listing.PriceCurrency }}</p> <p>{{ $Listing.StoreName }} - {{ $Listing.Price }} {{ $Listing.PriceCurrency }}</p>
</a> </a>
@ -39,8 +41,9 @@
{{ if eq .ActiveCard "websites" }} {{ if eq .ActiveCard "websites" }}
<div class="cards" id="websites"> <div class="cards" id="websites">
{{ $T := .WebsiteTarget }}
{{range $Website := .Websites }} {{range $Website := .Websites }}
<a href="{{ $Website.Url }}" class="card"> <a href="{{ $Website.Url }}" class="card" target="{{ $T }}">
<h3>{{ $Website.Name }}</h3> <h3>{{ $Website.Name }}</h3>
<img class="card-image" src="{{ $Website.ImageUrl }}" alt="{{ $Website.Name }} picture"> <img class="card-image" src="{{ $Website.ImageUrl }}" alt="{{ $Website.Name }} picture">
</a> </a>

View File

@ -20,6 +20,15 @@ const (
Websites ActiveCard = "websites" Websites ActiveCard = "websites"
) )
type AnchorTarget string
const (
OpenInNewTab AnchorTarget = "_blank"
OpenInCurrentTab AnchorTarget = "_self"
OpenInParent AnchorTarget = "_parent"
OpenInTopWindow AnchorTarget = "_top"
)
type ServerConfig struct { type ServerConfig struct {
Port int Port int
} }
@ -35,10 +44,12 @@ type TemplateConfig struct {
Listings []diyhrt.Listing Listings []diyhrt.Listing
Stores []diyhrt.Store Stores []diyhrt.Store
DiyHrtTarget AnchorTarget
ActiveCard ActiveCard ActiveCard ActiveCard
Websites []Website Websites []Website
WebsiteTarget AnchorTarget
} }
type Config struct { type Config struct {
@ -81,9 +92,12 @@ func NewConfig() Config {
ActiveCard: DiyHrtListings, ActiveCard: DiyHrtListings,
DiyHrtTarget: OpenInCurrentTab,
Websites: []Website{ Websites: []Website{
{Url: "https://gitea.elara.ws/Hazel/transfem-startpage", Name: "Transfem Startpage", ImageUrl: "https://gitea.elara.ws/assets/img/logo.svg"}, {Url: "https://gitea.elara.ws/Hazel/transfem-startpage", Name: "Transfem Startpage", ImageUrl: "https://gitea.elara.ws/assets/img/logo.svg"},
}, },
WebsiteTarget: OpenInCurrentTab,
}, },
} }
} }