-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerator.php
More file actions
82 lines (69 loc) · 1.7 KB
/
Copy pathgenerator.php
File metadata and controls
82 lines (69 loc) · 1.7 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*
* Lab Notebook Generator
* Created by FTC Team 4977, LANLords
*/
date_default_timezone_set("America/New_York");
require_once("Smarty.class.php");
require_once("markdown.php");
function filenameToTime($fn)
{
$a = str_split($fn);
$output = array();
$hitNumber = false;
$hitDash = false;
foreach ( $a as $c )
{
if ( intval($c) != 0 && !$hitNumber )
{
$output[] = " ";
$output[] = $c;
$hitNumber = true;
}
else if ( $c == "-" && !$hitDash )
{
$output[] = ", ";
$hitDash = true;
}
else
$output[] = $c;
}
return strtotime(implode("", $output));
}
$files = scandir("EngineeringNotebook2012-2013");
$files = array_reverse($files);
$entries = array();
$smarty = new Smarty();
foreach ( $files as $file )
{
if ( $file != "." && $file != ".." && strpos($file, ".md") !== false )
{
$noExt = substr($file, 0, -3);
$ts = strtotime($noExt);
$time = filenameToTime($noExt);
$data = array("content" => Markdown(file_get_contents("EngineeringNotebook2012-2013/".$file)),
"date" => date("M j, Y", $time),
"time" => $time,
"link" => substr($file, 0, -3).".html");
$entries[] = $data;
}
}
$pivot = array();
foreach ( $entries as $k=>$v )
{
$pivot[$k] = $v['time'];
}
array_multisort($pivot, SORT_DESC, $entries);
// Generate index
$smarty->assign("entries", $entries);
$smarty->assign("isSingleEntry", false);
file_put_contents("index.html", $smarty->fetch("template.html"));
// Generate permalink pages
foreach ( $entries as $entry )
{
$smarty->assign("entries", array($entry));
$smarty->assign("isSingleEntry", true);
$res = file_put_contents($entry['link'], $smarty->fetch("template.html"));
echo "wrote ".$res." bytes to ".$entry['link']."\n";
}
?>