Removed the entire save data logic as its unnecessary
All checks were successful
/ publish (push) Successful in 1m40s

This commit is contained in:
Leon Mika 2025-11-23 22:27:45 +11:00
parent d411667a3e
commit 8bd3474c4b
3 changed files with 1 additions and 40 deletions

View file

@ -28,8 +28,7 @@ jobs:
cp -r site/* build/. cp -r site/* build/.
- name: Building Header Image - name: Building Header Image
run: | run: |
go run ./cmd/fetch-header-image -o build/imgs/header.jpg \ go run ./cmd/fetch-header-image -o build/imgs/header.jpg
-out-data build/data/current-pending-images.json
- name: Deploying Site - name: Deploying Site
run: | run: |
netlify deploy --dir build --prod netlify deploy --dir build --prod

View file

@ -15,9 +15,7 @@ import (
func main() { func main() {
headerImages := flag.String("i", "data/pending-header-images.json", "header images json file") headerImages := flag.String("i", "data/pending-header-images.json", "header images json file")
currentPendingImage := flag.String("curr-image-data", "", "current header image URL")
targetFile := flag.String("o", "out.jpg", "target file") targetFile := flag.String("o", "out.jpg", "target file")
odFile := flag.String("out-data", "out-data.json", "target file data")
flag.Parse() flag.Parse()
pis, err := LoadPendingImages(*headerImages) pis, err := LoadPendingImages(*headerImages)
@ -32,17 +30,6 @@ func main() {
} }
log.Printf("found pending image: %s\n", pi.URL) log.Printf("found pending image: %s\n", pi.URL)
if *currentPendingImage != "" {
if cpi, err := LoadPendingImageFromURL(*currentPendingImage); err == nil {
if pi.URL == cpi.URL {
log.Println("current pending image is already the latest")
return
}
} else {
log.Printf("warn: failed to load current pending image: %s\n", err)
}
}
if err := fetchHeaderImageFromURL(*targetFile, pi); err != nil { if err := fetchHeaderImageFromURL(*targetFile, pi); err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -52,10 +39,6 @@ func main() {
if err := json.NewEncoder(&dBfr).Encode(pi); err != nil { if err := json.NewEncoder(&dBfr).Encode(pi); err != nil {
log.Fatal(err) log.Fatal(err)
} }
if err := os.WriteFile(*odFile, dBfr.Bytes(), 0644); err != nil {
log.Fatal(err)
}
} }
func fetchHeaderImageFromURL(outFile string, pi PendingImage) error { func fetchHeaderImageFromURL(outFile string, pi PendingImage) error {

View file

@ -2,8 +2,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"errors"
"net/http"
"os" "os"
"sort" "sort"
"time" "time"
@ -11,31 +9,12 @@ import (
const CropBottom = "bottom" const CropBottom = "bottom"
var ErrNon200Error = errors.New("non 200 status code")
type PendingImage struct { type PendingImage struct {
Date time.Time `json:"date"` Date time.Time `json:"date"`
URL string `json:"url"` URL string `json:"url"`
Crop string `json:"crop"` Crop string `json:"crop"`
} }
func LoadPendingImageFromURL(url string) (pi PendingImage, err error) {
resp, err := http.Get(url)
if err != nil {
return PendingImage{}, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return PendingImage{}, ErrNon200Error
}
if err := json.NewDecoder(resp.Body).Decode(&pi); err != nil {
return PendingImage{}, err
}
return pi, nil
}
type PendingImages struct { type PendingImages struct {
Images []PendingImage `json:"images"` Images []PendingImage `json:"images"`
} }