diff --git a/pkg/list/list.go b/pkg/list/list.go
index 3aa9d65676a9bffc0007249d53373ac2dfc209df..b6b6b89135839693af2eb32d797c76492381af2c 100644
--- a/pkg/list/list.go
+++ b/pkg/list/list.go
@@ -13,15 +13,15 @@ Left T
Right U
}
-func Chunck[T any](slice []T, size int) [][]T {
+func Distribuite[T any](slice []T, size int) [][]T {
chuncks := make([][]T, size)
for i := 0; i < len(slice); i += size {
for x := 0; x < size; x++ {
end := i + x
- if end > len(slice) {
- break
+ if end >= len(slice) {
+ return chuncks
}
chuncks[x] = append(chuncks[x], slice[end])
diff --git a/pkg/view/media.go b/pkg/view/media.go
index 3124119f901e683cddd810c4694584937b5c859f..d5aace24688b861992e6f6147889e9b5a25eb5ac 100644
--- a/pkg/view/media.go
+++ b/pkg/view/media.go
@@ -44,7 +44,8 @@ page = p
}
if albumIDStr == "" {
- page = 0
+ id := uint(0)
+ albumID = &id
} else if p, err := strconv.Atoi(albumIDStr); err == nil {
id := uint(p)
albumID = &id
@@ -132,9 +133,9 @@ return nil
}
func (self *MediaView) SetMyselfIn(r *ext.Router) {
- r.GET("/media/", self.Index)
- r.POST("/media/", self.Index)
+ r.GET("/media", self.Index)
+ r.POST("/media", self.Index)
- r.GET("/media/image/", self.GetImage)
- r.GET("/media/thumbnail/", self.GetThumbnail)
+ r.GET("/media/image", self.GetImage)
+ r.GET("/media/thumbnail", self.GetThumbnail)
}
diff --git a/templates/album.qtpl b/templates/album.qtpl
index 328c6d444892cad0792ba27695045a93199e0b0f..1f25bf6a6e2aa62127718cc5c94e62d908a57568 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 @@ <a href="/album/?albumId={%s FromUInttoString(&a.ID) %}" class="tag text-size-2">{%s a.Name %}</a>
{% 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 7dcdf54a8c8e329be1b29912260e59d5e22b1ba5..737d03d63a2ae301fc37dd3a9926e216a6fe325a 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 (p *MediaPage) Title() %}Media{% endfunc %}
{% 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 0000000000000000000000000000000000000000..18dbcba489fef78faa1326522e834762f3efadba
--- /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 %}