Skip to content

Commit 24b0d89

Browse files
committed
Show containing lists on film pages
1 parent 1d24f33 commit 24b0d89

6 files changed

Lines changed: 53 additions & 4 deletions

File tree

cmd/serve/assets/stylesheet/films.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ a.film-list {
200200
background: var(--accent-colour);
201201
}
202202

203+
& + & {
204+
margin-top: var(--medium-space);
205+
}
206+
203207
*, *:hover, *:active, *:focus {
204208
margin: 0;
205209
padding: 0;
@@ -339,9 +343,9 @@ ol.recent-films {
339343
display: grid;
340344

341345
@media(min-width: 1200px) {
342-
grid-template-areas: "header sidebar" "review sidebar";
346+
grid-template-areas: "header sidebar" "review sidebar" "review -";
343347
grid-template-columns: calc(var(--content-width) - 300px) 300px;
344-
grid-template-rows: auto 1fr;
348+
grid-template-rows: auto auto 1fr;
345349
column-gap: var(--medium-space);
346350

347351
aside {

cmd/serve/content/shortcodes/filmlist/render.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func RenderFromText(args []string, _ *context.Context) (string, error) {
2727
return "", fmt.Errorf("invalid film list ID: %s", args[0])
2828
}
2929

30+
return Render(id)
31+
}
32+
33+
func Render(id int) (string, error) {
3034
list, count, entries, err := db.GetFilmListWithFilms(id)
3135
if err != nil {
3236
return "", fmt.Errorf("failed to get film list: %w", err)
@@ -58,7 +62,7 @@ func RenderFromText(args []string, _ *context.Context) (string, error) {
5862
return "", fmt.Errorf("failed to render film list description: %w", err)
5963
}
6064

61-
return Render(Data{
65+
return renderTemplate(Data{
6266
ID: list.ID,
6367
Title: list.Title,
6468
Description: description,
@@ -68,7 +72,7 @@ func RenderFromText(args []string, _ *context.Context) (string, error) {
6872
})
6973
}
7074

71-
func Render(data Data) (string, error) {
75+
func renderTemplate(data Data) (string, error) {
7276
buf := &bytes.Buffer{}
7377
err := tmpl.Execute(buf, data)
7478
if err != nil {

cmd/serve/db/film_lists.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,18 @@ func GetNextPosition(listID int) (int, error) {
328328
}
329329
return position, nil
330330
}
331+
332+
func GetFilmListsContainingFilm(filmID int) ([]FilmList, error) {
333+
var lists []FilmList
334+
err := db.Select(&lists, `
335+
SELECT DISTINCT fl.id, fl.title, fl.description, fl.published, fl.path
336+
FROM film_lists fl
337+
JOIN film_list_entries fle ON fl.id = fle.film_list_id
338+
WHERE fl.published = true AND fle.film_id = $1
339+
ORDER BY fl.title
340+
`, filmID)
341+
if err != nil {
342+
return nil, err
343+
}
344+
return lists, nil
345+
}

cmd/serve/handlers/films.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"chameth.com/chameth.com/cmd/serve/assets"
1111
"chameth.com/chameth.com/cmd/serve/content"
1212
"chameth.com/chameth.com/cmd/serve/content/markdown"
13+
"chameth.com/chameth.com/cmd/serve/content/shortcodes/filmlist"
1314
"chameth.com/chameth.com/cmd/serve/content/shortcodes/rating"
1415
"chameth.com/chameth.com/cmd/serve/db"
1516
"chameth.com/chameth.com/cmd/serve/templates"
@@ -102,6 +103,21 @@ func Film(w http.ResponseWriter, r *http.Request) {
102103
posterPath = *film.PosterPath
103104
}
104105

106+
lists, err := db.GetFilmListsContainingFilm(film.ID)
107+
if err != nil {
108+
slog.Error("Failed to get film lists containing film", "film_id", film.ID, "error", err)
109+
}
110+
111+
var filmLists []template.HTML
112+
for _, list := range lists {
113+
listHTML, err := filmlist.Render(list.ID)
114+
if err != nil {
115+
slog.Error("Failed to render film list", "list_id", list.ID, "error", err)
116+
} else {
117+
filmLists = append(filmLists, template.HTML(listHTML))
118+
}
119+
}
120+
105121
w.Header().Set("Content-Type", "text/html; charset=utf-8")
106122
w.WriteHeader(http.StatusOK)
107123
err = templates.RenderFilm(w, templates.FilmData{
@@ -113,6 +129,7 @@ func Film(w http.ResponseWriter, r *http.Request) {
113129
TimesWatched: timesWatched,
114130
AverageRating: template.HTML(ratingHTML),
115131
PosterPath: posterPath,
132+
FilmLists: filmLists,
116133
PageData: templates.PageData{
117134
Title: fmt.Sprintf("%s (%s) · Chameth.com", film.Title, year),
118135
Stylesheet: assets.GetStylesheetPath(),

cmd/serve/templates/film.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type FilmData struct {
2626
TimesWatched int
2727
AverageRating template.HTML
2828
PosterPath string
29+
FilmLists []template.HTML
2930
}
3031

3132
type FilmReviewData struct {

cmd/serve/templates/film.html.gotpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
</blockquote>
2121
</section>
2222
{{end}}
23+
{{if .FilmLists}}
24+
<section class="film-lists">
25+
<h3>Appears in these lists</h3>
26+
{{range .FilmLists}}
27+
{{.}}
28+
{{end}}
29+
</section>
30+
{{end}}
2331
</div>
2432

2533
<aside class="film-sidebar">

0 commit comments

Comments
 (0)