aboutsummaryrefslogtreecommitdiff
path: root/mkgallery
blob: 6791a8faa0fc481b52af1dfbae2f68bed51e1f33 (plain)
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
28
29
30
31
32
33
34
35
36
37
38
#!/bin/rc
rfork en

fn entitle {
	basename $1 | sed 's/-/ /g' | bin/capitalize
}

fn usage {
	echo usage: $0 path >[1=2]
	exit usage
}

if(! ~ $#* 1)
	usage

if(! test -d $1)
	usage

media=`{walk -f $1 | grep -i '\.(jpe?g|png|webp|mp4|webm)$'}

>$1/index.html {
	title=`{entitle $1 | sed 's/\./ /g'}
	<tpl/head sed 's/(<title>[^<]*)/\1 - '^$"title^'/'
	cat tpl/menu
	echo '<h1>'^$"title^'</h1>'
	echo '<div id="gallery">'
	for(p in $media){
		if(~ $p *.mp4 *.webm)
			echo -n '<video width="200px" height="auto" controls><source src="/'^$p^'"></video>'
		if not {
			echo -n '<a href="/'^$p^'" target="_blank">'
			echo -n '<img src="/'^$p^'" width="200px" height="auto"></img>'
			echo '</a>'
		}
	}
	echo '</div>'
	cat tpl/feet
}