package homeview import "github.com/tigorlazuardi/redmage/models" import "fmt" import "github.com/tigorlazuardi/redmage/views/utils" import "strconv" import "github.com/alecthomas/units" type ImageCardOption uint func (o ImageCardOption) Has(opt ImageCardOption) bool { return o&opt != 0 } const ( HideTitle ImageCardOption = 1 << iota HideDescription HideSubreddit HidePoster ) templ RecentlyAddedImageCard(data *models.Image, opts ImageCardOption) {
{
if !opts.Has(HideTitle) { { truncateTitle(data.PostTitle) } } { data.PostAuthor }
@utils.RelativeTimeNode(fmt.Sprintf("relative-time-%s", data.PostName), data.CreatedAt, "text-sm")

Width

{ strconv.Itoa(int(data.ImageWidth)) } px

Height

{ strconv.Itoa(int(data.ImageHeight)) } px

Size

{ units.MetricBytes(data.ImageSize).Round(1).String() }

} func truncateTitle(title string) string { if len(title) > 50 { return title[:50] + "..." } return title } templ RecentlyAddedImageList(images models.ImageSlice, opts ImageCardOption) {
for _, data := range images { @RecentlyAddedImageCard(data, opts) }
}