summary refs log tree commit diff stats
path: root/lib/Crater/Gallery.rakumod
blob: 19b0d694309cf33aa31166d9fffc5a1352f35e1d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Crater::Gallery {
    has IO $.directory is required;

    method list() {
        my @gallery;
        for $!directory.dir.sort(*.modified) {
            if .IO.d {

            } elsif .IO.f {
                my Str $ext = .extension.lc;
                if $ext eq "jpg"|"png" {
                    push @gallery, %(
                        :type<img>, :src($_.relative($!directory)),
                        :alt($_)
                    );
                } elsif $ext eq "0" {
                    push @gallery, %( :type<heading>, :text($_.slurp) );
                } elsif $ext eq "txt" {
                    push @gallery, %( :type<text>, :text($_.slurp) );
                } else {
                    warn "Unhandled file :$_";
                }
            }
        }
        return @gallery;
    }
}