From a1f09d1f143012570a62bcb2a8fe51c439ad68fb Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Fri, 18 Aug 2023 21:57:47 +0200 Subject: feat: Make mosaic reusable --- templates/album.qtpl | 21 ++------------------- templates/media.qtpl | 21 ++------------------- templates/mosaic.qtpl | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 38 deletions(-) create mode 100644 templates/mosaic.qtpl (limited to 'templates') diff --git a/templates/album.qtpl b/templates/album.qtpl index 328c6d4..1f25bf6 100644 --- a/templates/album.qtpl +++ b/templates/album.qtpl @@ -1,5 +1,4 @@ {% import "git.sr.ht/~gabrielgio/img/pkg/database/repository" %} -{% import "git.sr.ht/~gabrielgio/img/pkg/list" %} {% code type AlbumPage struct { @@ -28,26 +27,10 @@ func (m *AlbumPage) PreloadAttr() string { {% endfor %}
-{% for _, c := range list.Chunck(p.Medias, 4) %} -
- {% for _, media := range c %} -
- {% if media.IsVideo() %} - - {% else %} -
- -
- {% endif %} -
- {% endfor %} -
-{% endfor %} +{%= Mosaic(p.Medias, p.PreloadAttr()) %}
- next + next
{% endfunc %} diff --git a/templates/media.qtpl b/templates/media.qtpl index 7dcdf54..737d03d 100644 --- a/templates/media.qtpl +++ b/templates/media.qtpl @@ -1,5 +1,4 @@ {% import "git.sr.ht/~gabrielgio/img/pkg/database/repository" %} -{% import "git.sr.ht/~gabrielgio/img/pkg/list" %} {% code type MediaPage struct { @@ -20,26 +19,10 @@ func (m *MediaPage) PreloadAttr() string { {% func (p *MediaPage) Content() %}
-{% for _, c := range list.Chunck(p.Medias, 4) %} -
- {% for _, media := range c %} -
- {% if media.IsVideo() %} - - {% else %} -
- -
- {% endif %} -
- {% endfor %} -
-{% endfor %} +{%= Mosaic(p.Medias, p.PreloadAttr()) %}
- next + next
{% endfunc %} diff --git a/templates/mosaic.qtpl b/templates/mosaic.qtpl new file mode 100644 index 0000000..18dbcba --- /dev/null +++ b/templates/mosaic.qtpl @@ -0,0 +1,24 @@ +{% import "git.sr.ht/~gabrielgio/img/pkg/database/repository" %} +{% import "git.sr.ht/~gabrielgio/img/pkg/list" %} + +{% func Mosaic(medias []*repository.Media, preloadAttr string) %} +
+{% for _, c := range list.Distribuite(medias, 6) %} +
+ {% for _, media := range c %} +
+ {% if media.IsVideo() %} + + {% else %} +
+ +
+ {% endif %} +
+ {% endfor %} +
+{% endfor %} +
+{% endfunc %} -- cgit v1.2.3