summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.php74
1 files changed, 70 insertions, 4 deletions
diff --git a/index.php b/index.php
index 1dddf72..87b0845 100644
--- a/index.php
+++ b/index.php
@@ -270,6 +270,9 @@ function template_root(string $content, array $meta = []): string
word-break: break-word;
}
}
+ td {
+ padding: 0.25rem 0.5rem;
+ }
</style>
</head>
<body><?php echo $content; ?></body>
@@ -280,6 +283,25 @@ function template_root(string $content, array $meta = []): string
}
+function template_project(string $project_path, string $content): string
+{
+ $project_path = trim($project_path, "/");
+
+ ob_start();
+
+ ?>
+ <nav><ul>
+ <li><a href="/<?php echo uri_encode($project_path); ?>">root</a></li>
+ <li><a href="/<?php echo uri_encode($project_path); ?>/tree">tree</a></li>
+ <li><a href="/<?php echo uri_encode($project_path); ?>/log">log</a></li>
+ </ul></nav>
+ <main><?php echo $content; ?></main>
+ <?php
+
+ return template_root(ob_get_clean());
+}
+
+
/**
* build breadcrumbs
*/
@@ -383,6 +405,8 @@ if ($url["path"] == "/") {
</tbody>
</table>
<?php
+
+ echo template_root(ob_get_clean());
}
@@ -430,6 +454,8 @@ elseif (preg_match("#(.*)/tree/?(.*)#", $url["path"], $matches)) {
</tbody>
</table>
<?php
+
+ echo template_project($project, ob_get_clean());
}
@@ -467,14 +493,54 @@ elseif (preg_match("#(.*)/blob/?(.*)#", $url["path"], $matches)) {
<?php endif; ?>
</div>
<?php
+
+ echo template_project($project, ob_get_clean());
+}
+
+
+// Route: /$project/log
+elseif (str_ends_with($url["path"], "/log")) {
+ $project = substr($url["path"], 0, -4);
+ $log = parse_log($projects_path . $project);
+
+ ?>
+ <table border>
+ <thead>
+ <tr>
+ <th>Commit</th>
+ <th>Author</th>
+ <th>Date</th>
+ <th>Message</th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php
+
+ foreach ($log as $entry) {
+ ?>
+ <tr>
+ <td><?php echo $entry["commit"]; ?></td>
+ <td><?php echo $entry["author"]; ?></td>
+ <td><?php echo $entry["date"]; ?></td>
+ <td><?php echo $entry["message"]; ?></td>
+ </tr>
+ <?php
+ }
+
+ ?>
+ </tbody>
+ </table>
+ <?php
+
+ echo template_project($project, ob_get_clean());
}
+// assume project base path
else {
$path = $projects_path . $url["path"];
var_dump(parse_log($path));
-}
-
-// display
-echo template_root(ob_get_clean());
+
+ echo template_project($url["path"], ob_get_clean());
+}