diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-18 21:57:47 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-18 21:57:47 +0200 |
commit | a1f09d1f143012570a62bcb2a8fe51c439ad68fb (patch) | |
tree | 591cf29229453f2402fc82f50f6b4e0bee8f0e22 /templates | |
parent | d2a9e162352646e7f1550823c3d88496590f8760 (diff) | |
download | lens-a1f09d1f143012570a62bcb2a8fe51c439ad68fb.tar.gz lens-a1f09d1f143012570a62bcb2a8fe51c439ad68fb.tar.bz2 lens-a1f09d1f143012570a62bcb2a8fe51c439ad68fb.zip |
feat: Make mosaic reusable
Diffstat (limited to 'templates')
-rw-r--r-- | templates/album.qtpl | 21 | ||||
-rw-r--r-- | templates/media.qtpl | 21 | ||||
-rw-r--r-- | templates/mosaic.qtpl | 24 |
3 files changed, 28 insertions, 38 deletions
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 %} </div> <div class="columns"> -{% for _, c := range list.Chunck(p.Medias, 4) %} - <div class="column is-3"> - {% for _, media := range c %} - <div class="card-image"> - {% if media.IsVideo() %} - <video class="image is-fit" controls muted="true" poster="/media/thumbnail/?path_hash={%s media.PathHash %}" preload="{%s p.PreloadAttr() %}"> - <source src="/media/image/?path_hash={%s media.PathHash %}" type="{%s media.MIMEType %}"> - </video> - {% else %} - <figure class="image is-fit"> - <img src="/media/thumbnail/?path_hash={%s media.PathHash %}"> - </figure> - {% endif %} - </div> - {% endfor %} - </div> -{% endfor %} +{%= Mosaic(p.Medias, p.PreloadAttr()) %} </div> <div> - <a href="/media/?page={%d p.Next.Page %}" class="button is-pulled-right">next</a> + <a href="/media?page={%d p.Next.Page %}" class="button is-pulled-right">next</a> </div> {% 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() %} <div class="columns"> -{% for _, c := range list.Chunck(p.Medias, 4) %} - <div class="column is-3"> - {% for _, media := range c %} - <div class="card-image"> - {% if media.IsVideo() %} - <video class="image is-fit" controls muted="true" poster="/media/thumbnail/?path_hash={%s media.PathHash %}" preload="{%s p.PreloadAttr() %}"> - <source src="/media/image/?path_hash={%s media.PathHash %}" type="{%s media.MIMEType %}"> - </video> - {% else %} - <figure class="image is-fit"> - <img src="/media/thumbnail/?path_hash={%s media.PathHash %}"> - </figure> - {% endif %} - </div> - {% endfor %} - </div> -{% endfor %} +{%= Mosaic(p.Medias, p.PreloadAttr()) %} </div> <div> - <a href="/media/?page={%d p.Next.Page %}" class="button is-pulled-right">next</a> + <a href="/media?page={%d p.Next.Page %}" class="button is-pulled-right">next</a> </div> {% 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) %} +<div class="columns"> +{% for _, c := range list.Distribuite(medias, 6) %} + <div class="column is-2"> + {% for _, media := range c %} + <div class="card-image"> + {% if media.IsVideo() %} + <video class="image is-fit" controls muted="true" poster="/media/thumbnail?path_hash={%s media.PathHash %}" preload="{%s preloadAttr %}"> + <source src="/media/image?path_hash={%s media.PathHash %}" type="{%s media.MIMEType %}"> + </video> + {% else %} + <figure class="image is-fit"> + <img src="/media/thumbnail?path_hash={%s media.PathHash %}"> + </figure> + {% endif %} + </div> + {% endfor %} + </div> +{% endfor %} +</div> +{% endfunc %} |