Compare commits
No commits in common. "a4ec4966d247b5c2a14bb6ce35bb774984d6d86a" and "cb2895c498dfcc781b9a2c32286a59031da43c47" have entirely different histories.
a4ec4966d2
...
cb2895c498
15
.air.toml
15
.air.toml
@ -1,15 +0,0 @@
|
||||
# .air.toml
|
||||
root = "."
|
||||
tmp_dir = "tmp"
|
||||
|
||||
[build]
|
||||
bin = "/tmp/new_tab"
|
||||
cmd = "go build -o /tmp/new_tab main.go"
|
||||
include = ["*.go", "*.html", "*.css"]
|
||||
exclude = ["tmp", "vendor"]
|
||||
|
||||
[color]
|
||||
main = "yellow"
|
||||
watcher = "cyan"
|
||||
build = "green"
|
||||
log = "white"
|
11
README.md
11
README.md
@ -1,12 +1,3 @@
|
||||
# trans new tab page
|
||||
|
||||
https://diyhrt.market/api/
|
||||
|
||||
## development
|
||||
|
||||
1. Install [air](https://github.com/air-verse/air)
|
||||
2. Run air
|
||||
|
||||
```sh
|
||||
air
|
||||
```
|
||||
https://diyhrt.market/api/
|
@ -4,7 +4,8 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{{ .PageTitle }}</title>
|
||||
<link rel="stylesheet" type="text/css" href="assets/style.css">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="assets/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<form class="search-grid" action="{{ .SearchFormAction }}">
|
||||
@ -13,15 +14,13 @@
|
||||
<h2 class="phrases"></h2>
|
||||
<img als="girl_juice" src="assets/girl_juice.png" />
|
||||
</div>
|
||||
<input name="{{ .SearchInputName }}" type="text" class="grid-item" class="search" placeholder="{{ .SearchPlaceholder }}" />
|
||||
|
||||
<div class="store-cards">
|
||||
{{range $Store := .Stores }}
|
||||
<a target="_blank" href="{{ $Store.Url }}" class="card">
|
||||
<h3>{{ $Store.Name }}</h3>
|
||||
</a>
|
||||
{{- end }}
|
||||
</div>
|
||||
<input
|
||||
name="{{ .SearchInputName }}"
|
||||
type="text"
|
||||
class="grid-item"
|
||||
class="search"
|
||||
placeholder="{{ .SearchPlaceholder }}"
|
||||
/>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
|
9
go.mod
9
go.mod
@ -2,16 +2,15 @@ module gitea.elara.ws/Hazel/transfem-startpage
|
||||
|
||||
go 1.24.2
|
||||
|
||||
require github.com/labstack/echo/v4 v4.13.4
|
||||
|
||||
require (
|
||||
github.com/labstack/echo/v4 v4.13.4 // indirect
|
||||
github.com/labstack/gommon v0.4.2 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||
golang.org/x/crypto v0.39.0 // indirect
|
||||
golang.org/x/net v0.41.0 // indirect
|
||||
golang.org/x/crypto v0.38.0 // indirect
|
||||
golang.org/x/net v0.40.0 // indirect
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/text v0.26.0 // indirect
|
||||
golang.org/x/text v0.25.0 // indirect
|
||||
)
|
||||
|
20
go.sum
20
go.sum
@ -1,5 +1,3 @@
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA=
|
||||
github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ=
|
||||
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
||||
@ -8,22 +6,16 @@ github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHP
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
|
||||
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
|
||||
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
|
||||
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
|
||||
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
|
||||
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
|
||||
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
|
||||
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
|
||||
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
|
||||
|
@ -2,7 +2,8 @@ package diyhrt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
@ -13,7 +14,7 @@ const endpoint = "https://diyhrt.market/api/listings"
|
||||
func GetListings() ([]Listing, error) {
|
||||
apiKey := os.Getenv("API_KEY")
|
||||
if apiKey == "" {
|
||||
return nil, errors.New("API_KEY environment variable not set")
|
||||
return nil, fmt.Errorf("API_KEY environment variable not set")
|
||||
}
|
||||
|
||||
// Create HTTP client
|
||||
@ -22,25 +23,26 @@ func GetListings() ([]Listing, error) {
|
||||
// Create request
|
||||
req, err := http.NewRequest("GET", endpoint+"?api_token="+apiKey, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("creating request failed: %w", err)
|
||||
}
|
||||
|
||||
// Send request
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("request failed: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Check status code
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, errors.New("unexpected status code")
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return nil, fmt.Errorf("unexpected status code %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
// Decode response
|
||||
var listings []Listing
|
||||
if err := json.NewDecoder(resp.Body).Decode(&listings); err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("decoding failed: %w", err)
|
||||
}
|
||||
|
||||
return listings, nil
|
||||
|
@ -1,42 +0,0 @@
|
||||
package diyhrt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
)
|
||||
|
||||
type StoreFilter struct{
|
||||
Limit int
|
||||
|
||||
IncludeIds []int
|
||||
ExcludeIds []int
|
||||
}
|
||||
|
||||
|
||||
func (f StoreFilter) Filter (stores []Store) []Store {
|
||||
result := make([]Store, 0)
|
||||
|
||||
for _, s := range stores {
|
||||
if f.Limit > 0 && len(result) >= f.Limit {
|
||||
break
|
||||
}
|
||||
|
||||
if len(f.IncludeIds) > 0 {
|
||||
if slices.Contains(f.IncludeIds, s.Id) {
|
||||
result = append(result, s)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
if slices.Contains(f.ExcludeIds, s.Id) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
result = append(result, s)
|
||||
}
|
||||
|
||||
fmt.Println(len(result))
|
||||
return result
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package rendering
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt"
|
||||
)
|
||||
|
||||
@ -13,8 +15,6 @@ type RenderingConfig struct {
|
||||
SearchFormAction string
|
||||
SearchInputName string
|
||||
|
||||
StoreFilter diyhrt.StoreFilter
|
||||
|
||||
Listings []diyhrt.Listing
|
||||
Stores []diyhrt.Store
|
||||
}
|
||||
@ -36,10 +36,6 @@ func DefaultRenderingConfig() RenderingConfig {
|
||||
SearchPlaceholder: "Search on DuckDuckGo",
|
||||
SearchFormAction: "https://duckduckgo.com/",
|
||||
SearchInputName: "q",
|
||||
|
||||
StoreFilter: diyhrt.StoreFilter{
|
||||
Limit: 4,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,6 +44,7 @@ func (rc *RenderingConfig) LoadDiyHrt(listings []diyhrt.Listing) {
|
||||
stores := make([]diyhrt.Store, 0)
|
||||
|
||||
for _, listing := range listings {
|
||||
fmt.Println(listing)
|
||||
if _, ok := existingStores[listing.Store.Id]; ok {
|
||||
continue
|
||||
}
|
||||
@ -56,5 +53,5 @@ func (rc *RenderingConfig) LoadDiyHrt(listings []diyhrt.Listing) {
|
||||
}
|
||||
|
||||
rc.Listings = listings
|
||||
rc.Stores = rc.StoreFilter.Filter(stores)
|
||||
rc.Stores = stores
|
||||
}
|
||||
|
1
main.go
1
main.go
@ -45,6 +45,7 @@ func main() {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println(CurrentRenderingConfig.Stores)
|
||||
|
||||
e := echo.New()
|
||||
e.Static("/assets", "frontend/assets")
|
||||
|
@ -1 +0,0 @@
|
||||
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
|
Loading…
x
Reference in New Issue
Block a user