-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathessay-index.php
130 lines (107 loc) · 3.23 KB
/
essay-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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Essays</title>
<style>
a {
font-size: 24px;
}
body {
background-color: black;
margin: 0;
padding: 0;
}
h1 {
font-size: 90px;
font-weight: bold;
margin-top: 0;
margin-bottom: 0;
text-align: center;
}
h2 {
font-size: 30px;
font-weight: bold;
margin-top: 0;
margin-bottom: 0;
}
.main-container {
margin: 0 auto;
width: 960px;
padding: 30px;
background-color: white;
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
height: 100vh;
}
.search-container {
text-align: center;
margin-top: 10px;
margin-bottom: 10px;
}
.search-container input[type="text"] {
padding: 8px;
font-size: 16px;
border: solid 1px;
width: 60%;
margin-right: 10px;
border-radius: 10px;
margin-bottom: 5px;
}
.search-container button {
padding: 8px;
font-size: 16px;
border: 1px;
border-radius: 10px;
}
.search-container button:hover {
cursor: pointer;
}
</style>
</head>
<body>
<div class="main-container">
<h1>
All my essays
</h1>
<div class="search-container">
<label for="search-input"></label><input type="text" placeholder="Search for an essay by tag or title..." id="search-input">
<button>Search</button>
</div>
<ul>
<?php
$folder = "essays/";
$files = scandir($folder);
$categories = array();
// Loop through files to extract category and file name
foreach ($files as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) == "html") {
$html = file_get_contents($folder . $file);
preg_match('/name="([^"]*)"\s/', $html, $match);
$name = isset($match[1]) ? $match[1] : "Essay";
preg_match('/content="(.*?)">/', $html, $match);
$current_category = isset($match[1]) ? $match[1] : "Uncategorized";
// Add new category to array if it doesn't already exist
if (!in_array($current_category, $categories)) {
$categories[] = $current_category;
}
$file_list[$current_category][] = array("name" => $name, "file" => $file);
}
}
// Loop through categories and output each one along with its corresponding files
foreach ($categories as $category) {
echo "<h2><br>" . $category . "<br></h2>";
echo "<ul>";
foreach ($file_list[$category] as $file_info) {
echo "<li><a href='" . $folder . $file_info["file"] . "'>" . $file_info["name"] . "</a></li>";
}
echo "</ul>";
}
?>
</ul>
</div>
</body>
<script src="../js/search.js"></script>
</html>