add podcast page

This commit is contained in:
2026-02-13 17:14:02 +03:00
parent e4c22dbe47
commit 9c7fa50fcd
2 changed files with 95 additions and 0 deletions

28
main.go
View File

@@ -357,6 +357,34 @@ func main() {
sendJSON(w, podcasts, 200) sendJSON(w, podcasts, 200)
}) })
mux.HandleFunc("GET /podcasts/{id}", func(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(r.PathValue("id"))
if err != nil {
http.Error(w, err.Error(), 404)
return
}
podcast, err := getPodcastById(db, int64(id))
if err != nil {
http.Error(w, err.Error(), 404)
return
}
episodes, err := getPodcastEpisodes(db, podcast.ID)
if err != nil {
http.Error(w, err.Error(), 404)
return
}
tmpl.ExecuteTemplate(w, "podcast.html", struct {
Podcast *Podcast
Episodes []*Episode
}{
Podcast: podcast,
Episodes: episodes,
})
})
mux.HandleFunc("POST /podcasts", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("POST /podcasts", func(w http.ResponseWriter, r *http.Request) {
var body struct { var body struct {
Feed string `json:"feed"` Feed string `json:"feed"`

67
views/podcast.html Normal file
View File

@@ -0,0 +1,67 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{.Podcast.Name}}</title>
<style>
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
max-width: 1440px;
width: 100%;
margin: 0 auto;
padding: 8px;
}
.header {
margin-top: 12px;
display: flex;
gap: 8px;
}
.header img {
width: 300px;
aspect-ration: 1/1;
}
.header .info {
display: flex;
flex-direction: column;
gap: 4px;
}
.episodes {
margin-top: 24px;
padding: 10px;
border-top: 1px solid;
}
</style>
</head>
<body>
<h1><a href="/">podcaster</a></h1>
<div class="header">
<img src="{{.Podcast.Image}}" alt="" />
<div class="info">
<h2>{{.Podcast.Name}}</h2>
<p>{{.Podcast.Description}}</p>
</div>
</div>
<div class="episodes">
{{range .Episodes}}
<div>
<span>{{.Title}}</span>
</div>
{{end}}
</div>
</body>
</html>