-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
61 lines (60 loc) · 1.34 KB
/
index.php
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
<!DOCTYPE html>
<html lang="en">
<?php
# A small helper to remove . and .. from scandir
function scandir2($n){
return array_slice(scandir($n), 2);
}
# POSTS STORED IN
$dir = 'blog';
# CHANGE THIS TO CHANGE THE NUMBER OF POSTS SHOWN ON THE FRONT PAGE
$MAX = 2;
?>
<head>
<title>index</title>
<style>
div {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
h1, h2, h3 {
text-align: center;
}
p {
text-align: justify;
}
</style>
</head>
<body>
<div>
<h1>index</h1>
<h3><a href="blog.php">blog</a></h3>
<?php
$posts = scandir2($dir);
if(!empty($posts)){
print "<h3>Recent Posts</h3>";
sort($posts);
#To flip the order of the files so that our newest files are first
$posts = array_reverse($posts);
for( $x = 0; $x < $MAX; $x++ ) {
$post = $posts[$x];
$files = scandir2("$dir/$post");
foreach($files as $file){
[$title, $ext] = explode(".", $file);
if ($ext == "md") {
$handler = fopen("$dir/$post/$file", "r");
$title = trim(str_replace('#', '',fgets($handler)));
fgets($handler); // Blank Line
$date = trim(str_replace('#', '',fgets($handler)));
fclose($handler);
echo "<p>$date - <a href=blog.php?post=$post>$title</a></p>";
}
}
}
}
?>
</div>
</body>
</html>