From c94c6de3cd7e739ec58dd6e1e9e8850f9dba7bae Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Wed, 8 Oct 2025 15:23:12 -0700 Subject: [PATCH] index.json --- build/generate-index.go | 32 ++++++--- helios/index.json | 150 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+), 8 deletions(-) create mode 100644 helios/index.json diff --git a/build/generate-index.go b/build/generate-index.go index 85b7a90..72c1e84 100644 --- a/build/generate-index.go +++ b/build/generate-index.go @@ -1,9 +1,11 @@ package main import ( + "encoding/json" "flag" "fmt" "html/template" + "log" "os" "path/filepath" "sort" @@ -17,8 +19,8 @@ type IndexData struct { } type FileEntry struct { - Name string - URL string + Name string `json:"name"` + URL string `json:"url"` } func generateIndex(dir string, rootURL string) error { @@ -33,8 +35,8 @@ func generateIndex(dir string, rootURL string) error { var fileNames []string for _, entry := range entries { name := entry.Name() - // Skip the index.html itself and hidden files - if name != "index.html" && !filepath.HasPrefix(name, ".") { + // Skip the index files themselves and hidden files + if name != "index.html" && name != "index.json" && !filepath.HasPrefix(name, ".") { fileNames = append(fileNames, name) } } @@ -44,7 +46,6 @@ func generateIndex(dir string, rootURL string) error { var files []FileEntry dirName := filepath.Base(dir) for _, name := range fileNames { - // URL encode the filename for the path url := fmt.Sprintf("%s/%s/%s", rootURL, dirName, name) files = append(files, FileEntry{ Name: name, @@ -74,8 +75,24 @@ func generateIndex(dir string, rootURL string) error { if err := tmpl.Execute(f, data); err != nil { return fmt.Errorf("failed to execute template: %w", err) } + log.Println(indexPath) + + // Generate index.json + jsonPath := filepath.Join(dir, "index.json") + jsonFile, err := os.Create(jsonPath) + if err != nil { + return fmt.Errorf("failed to create index.json: %w", err) + } + defer jsonFile.Close() + + encoder := json.NewEncoder(jsonFile) + encoder.SetIndent("", " ") + encoder.SetEscapeHTML(false) + if err := encoder.Encode(files); err != nil { + return fmt.Errorf("failed to encode JSON: %w", err) + } + log.Println(jsonPath) - fmt.Printf("Generated index.html in %s\n", dir) return nil } @@ -93,8 +110,7 @@ func main() { for _, dir := range dirs { if err := generateIndex(dir, *rootURL); err != nil { - fmt.Fprintf(os.Stderr, "Error processing %s: %v\n", dir, err) - os.Exit(1) + log.Fatalf("Error processing %s: %v", dir, err) } } } diff --git a/helios/index.json b/helios/index.json new file mode 100644 index 0000000..4082324 --- /dev/null +++ b/helios/index.json @@ -0,0 +1,150 @@ +[ + { + "name": "2025-10-08 - Helios Annual Report.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Annual Report.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Gradebands.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Gradebands.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Homework.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Homework.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - Camping.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - Camping.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - Homework.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - Homework.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - Library.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - Library.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - Literacy.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - Literacy.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - MAP Assessment.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - MAP Assessment.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - Math Program.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - Math Program.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - Math and Literacy Placement.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - Math and Literacy Placement.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - PE.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - PE.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - SEL.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - SEL.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - Technology.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - Technology.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - Themes and Content.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - Themes and Content.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Hummingbirds - Transition.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Hummingbirds - Transition.pdf" + }, + { + "name": "2025-10-08 - Helios Help - MAP Testing.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - MAP Testing.pdf" + }, + { + "name": "2025-10-08 - Helios Help - SEL.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - SEL.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Themes and Content.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Themes and Content.pdf" + }, + { + "name": "2025-10-08 - Helios Help - Welcome.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Help - Welcome.pdf" + }, + { + "name": "2025-10-08 - Helios Parent Student Handbook 2025-2026.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Parent Student Handbook 2025-2026.pdf" + }, + { + "name": "2025-10-08 - Helios Strategic Plan Progress Report 2025.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Strategic Plan Progress Report 2025.pdf" + }, + { + "name": "2025-10-08 - Helios Touchstones (revised 11-5-2024).pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Helios Touchstones (revised 11-5-2024).pdf" + }, + { + "name": "2025-10-08 - Meet Choice Lunch.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Meet Choice Lunch.pdf" + }, + { + "name": "2025-10-08 - Parent Portal - After School Clubs.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Parent Portal - After School Clubs.pdf" + }, + { + "name": "2025-10-08 - Parent Portal - Aftercare Program.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Parent Portal - Aftercare Program.pdf" + }, + { + "name": "2025-10-08 - Parent Portal - Drop-off & Pick-up.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Parent Portal - Drop-off & Pick-up.pdf" + }, + { + "name": "2025-10-08 - Parent Portal - Testing & Reports.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Parent Portal - Testing & Reports.pdf" + }, + { + "name": "2025-10-08 - Parent Portal - Van Service & Carpool.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Parent Portal - Van Service & Carpool.pdf" + }, + { + "name": "2025-10-08 - Parent Portal- Health Guidelines.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Parent Portal- Health Guidelines.pdf" + }, + { + "name": "2025-10-08 - Veracross - After School Clubs.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Veracross - After School Clubs.pdf" + }, + { + "name": "2025-10-08 - Veracross - Aftercare.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Veracross - Aftercare.pdf" + }, + { + "name": "2025-10-08 - Veracross - Camping.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Veracross - Camping.pdf" + }, + { + "name": "2025-10-08 - Veracross - Drop off & Pick up.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Veracross - Drop off & Pick up.pdf" + }, + { + "name": "2025-10-08 - Veracross - Shuttle Service & Carpool.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Veracross - Shuttle Service & Carpool.pdf" + }, + { + "name": "2025-10-08 - Veracross - Testing & Reports.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Veracross - Testing & Reports.pdf" + }, + { + "name": "2025-10-08 - Veracross - Volunteer Requirements.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Veracross - Volunteer Requirements.pdf" + }, + { + "name": "2025-10-08 - Veracross - WhatsApp Groups.pdf", + "url": "https://ss-6r6jq.ondigitalocean.app/helios/2025-10-08 - Veracross - WhatsApp Groups.pdf" + } +]