add podcast page
This commit is contained in:
28
main.go
28
main.go
@@ -357,6 +357,34 @@ func main() {
|
||||
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) {
|
||||
var body struct {
|
||||
Feed string `json:"feed"`
|
||||
|
||||
67
views/podcast.html
Normal file
67
views/podcast.html
Normal 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>
|
||||
Reference in New Issue
Block a user