
my $date = `date +%s`;
$date =~ s/\n/000/;


sub page {
	my ($slug,$title,$synopsis,$story) = @_;
	my $a = <<"";
{"date": $date,  "id": "c4737b88db772aaa", "type": "create", "item": {"title": "$title", "story": $story}}

	$page =~ s/}$/,"journal":[]}/;
	open F, ">$slug.json";
	print F <<"";
{"title": "$title", "story": $story, "journal": [$a]}

        push @sitemap, <<"";
{"slug": "$slug", "title": "$title", "date": $date, "synopsis": "$synopsis"}

}

for $r (<results/*>) {
	$c = $1 if $r =~ /\/(.*)$/;
	next unless -f "$r/name.txt";
	$t = `cat $r/name.txt`;
	next if $t =~ /^results/;
	chomp $t;
	$p = lc($t) . "-sensor";
	$i = `cat $r/info.html`;
	$i =~ s/\n/\\n/g;
	$i =~ s/<\/?p>//g;
	$i =~ s/"/\\"/g;
	$j .= $i while length($j) < 300;
	$u = "&deg; F";
	$u = `cat $r/unit.txt` if -f "$r/unit.txt";
	$u =~ s/\n/ /g;
	$d = `tail -n 288 $r/history.txt`;
	$d =~ s/(\d+)\t(.*?)\n/"[$1,".sprintf("%.1f",$2)."],"/geo;
	$d =~ s/([0-9.]+)],$/$1]/g;
	$s .= "<li>[[$t Sensor]] . . . $1 $u\\n";
	$date = (stat($r))[9]*1000;
	page $p, "$t Sensor", $i, <<"";
[
	{"type": "image", "id": "000$c", "url": "http://sensors.c2.com/$r/thumb.jpg", "caption": "device code $c"},
	{"type": "paragraph", "id": "001$c", "text": "$i"},
	{"type": "paragraph", "id": "b080bfe0541319e8", "text": "Try plotting this with [[D3 Line]]."},
	{"type": "paragraph", "id": "002$c", "text": "$j"},
	{"type": "chart", "id": "003$c", "caption": "$u<br>5 min refresh", "data": [$d]},
	{"type": "paragraph", "id": "004$c", "text": "$i $i $i"},
	{"type": "paragraph", "id": "005$c", "text": "$i"}
]

}

$t = `date`;
chomp $t;
$date = (stat($0))[9]*1000;
#$date = `date +%s`;
#$date =~ s/\n/000/;
page "list-of-sensors", "List of Sensors", "We generate reports for sensors from flat files.", <<"";
[
	{"type": "paragraph", "id": "0980234908098", "text": "We generate sensor reports from flat files maintained within the [http://c2.com/ward/arduino/SensorServer SensorServer] system with the [http://sensors.c2.com/mksensor.pl mksensor] script."},
	{"type": "html", "id": "9879589843018", "text": "<ul>\\n$s"},
	{"type": "paragraph", "id": "9820841928377", "text": "Reports are refreshed on five minute intervals. Numbers quoted above are the most recent, but not guarenteed to be current. Last report update $t."}
]

open F, ">system/sitemap.json";
$sitemap = join ",\n", @sitemap;
print F "[\n$sitemap\n]\n";

