diff --git a/handler/episode.go b/handler/episode.go index d44881e..d1dfc8c 100644 --- a/handler/episode.go +++ b/handler/episode.go @@ -2,6 +2,7 @@ package handler import ( "fmt" + "html/template" "io" "net/http" "os" @@ -40,20 +41,47 @@ func (h *EpisodeHandler) ServeDashboard(w http.ResponseWriter, r *http.Request) if title == "" { title = "Podstalk" } + type epView struct { + ID int64 + Title string + Description string + AudioPath string + ImageURL template.URL + PublishedAt time.Time + } + var epViews []epView + for _, ep := range episodes { + ev := epView{ + ID: ep.ID, + Title: ep.Title, + Description: ep.Description, + AudioPath: ep.AudioPath, + PublishedAt: ep.PublishedAt, + } + if ep.ImagePath != "" { + ev.ImageURL = template.URL("/uploads/" + ep.ImagePath) + } else if user.PodcastImage != "" { + ev.ImageURL = template.URL("/uploads/" + user.PodcastImage) + } + epViews = append(epViews, ev) + } + + podcastImageURL := template.URL("") + if user.PodcastImage != "" { + podcastImageURL = template.URL("/uploads/" + user.PodcastImage) + } + h.Tpl.Render(w, "dashboard", map[string]any{ - "Episodes": episodes, - "PodcastTitle": title, - "PodcastSlug": user.PodcastSlug, - "PodcastImage": user.PodcastImage, - "PodcastAuthor": user.PodcastAuthor, - "BaseURL": h.BaseURL, - "UserID": user.ID, + "Episodes": epViews, + "PodcastTitle": title, + "PodcastSlug": user.PodcastSlug, + "PodcastImageURL": podcastImageURL, + "PodcastAuthor": user.PodcastAuthor, + "RSSURL": template.URL(h.BaseURL + "/rss/" + user.PodcastSlug), }) } - func (h *EpisodeHandler) ServeNew(w http.ResponseWriter, r *http.Request) { userID := UserIDFromContext(r) - if r.Method == http.MethodGet { h.Tpl.Render(w, "episode_form", map[string]any{"Editing": false}) return diff --git a/handler/template.go b/handler/template.go index caa9198..51bc45e 100644 --- a/handler/template.go +++ b/handler/template.go @@ -3,6 +3,7 @@ package handler import ( "html/template" "io" + "log" ) type Templates struct { @@ -12,7 +13,8 @@ type Templates struct { func NewTemplates(tmpl *template.Template) *Templates { return &Templates{tmpl: tmpl} } - func (t *Templates) Render(w io.Writer, name string, data any) { - _ = t.tmpl.ExecuteTemplate(w, name+".html", data) + if err := t.tmpl.ExecuteTemplate(w, name+".html", data); err != nil { + log.Printf("template error: %s: %v", name, err) + } } diff --git a/podstalk b/podstalk index d9eef6c..d6ea5ae 100755 Binary files a/podstalk and b/podstalk differ diff --git a/podstalk.db b/podstalk.db index 20cb393..71048bb 100644 Binary files a/podstalk.db and b/podstalk.db differ diff --git a/template/dashboard.html b/template/dashboard.html index d4f5f71..e0ff5e8 100644 --- a/template/dashboard.html +++ b/template/dashboard.html @@ -11,15 +11,22 @@ .flash { padding: 0.75rem 1rem; margin-bottom: 1rem; border: 2px solid #000; } .flash-error { background: #ffcdd2; } .flash-success { background: #c8e6c9; } - .flash-info { background: #e3f2fd; } + .hidden { display: none; } .episode-actions { display: flex; gap: 0.5rem; } .settings-section { margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 2px solid #ddd; } .settings-form { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; } .settings-form .form-group { margin-bottom: 0; } - .hidden { display: none; } .file-upload { position: relative; display: inline-block; } .file-upload input[type="file"] { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; } .file-name { margin-left: 0.5rem; font-size: 0.85rem; color: #666; } + .form-flex-1 { flex: 1; min-width: 200px; } + .form-flex-slug { flex: 1; min-width: 160px; } + .podcast-img-preview { margin-top: 1rem; } + .podcast-img-preview img { max-width: 150px; max-height: 150px; border: 2px solid #000; } + .rss-card { margin-bottom: 1.5rem; } + .new-ep-row { margin-bottom: 1.5rem; } + .ep-thumb { max-width: 48px; max-height: 48px; border: 1px solid #000; } +