aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes
diff options
context:
space:
mode:
authorwinter2024-12-23 18:20:25 +0000
committerwinter2024-12-23 18:20:25 +0000
commitbccad1118364427ea5c97c08d132fd128368760b (patch)
tree449a4f5b36309e1e80694718f72ebc6e136e0140 /routes
parent094b1d010253f1a9a114303d823739e513834742 (diff)
make a crummy template system and use it for global timeline
Diffstat (limited to 'routes')
-rw-r--r--routes/global_timeline.php22
-rw-r--r--routes/static.php19
2 files changed, 20 insertions, 21 deletions
diff --git a/routes/global_timeline.php b/routes/global_timeline.php
index c32419c..654d2c7 100644
--- a/routes/global_timeline.php
+++ b/routes/global_timeline.php
@@ -5,25 +5,5 @@ use Digitigrade\Timeline\GlobalTimeline;
Router::getInstance()->mount('/feed/global', function (array $args) {
$notes = (new GlobalTimeline())->getNotes();
- ?>
- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <title>digitigrade global timeline</title>
- </head>
-
- <body>
- <h1>Global timeline</h1>
- <?php foreach ($notes as $n): ?>
- <div style="margin: 8px; padding: 8px; border: 1px solid">
- <b><?= $n->author->displayName ?></b> <small><?= $n->author->uri ?></small><br>
- <p><?= $n->plainContent ?></p>
- <small><?= $n->created->format('c') ?></small>
- </div>
- <?php endforeach; ?>
- </body>
-
- </html>
- <?php
+ render_template('global_timeline', ['notes' => $notes]);
}); \ No newline at end of file
diff --git a/routes/static.php b/routes/static.php
new file mode 100644
index 0000000..2850d8f
--- /dev/null
+++ b/routes/static.php
@@ -0,0 +1,19 @@
+<?php
+
+use Digitigrade\HttpResponseStatus\NotFound;
+use Digitigrade\Router;
+
+Router::getInstance()->mount('/static/:path', function (array $args) {
+ // TODO: support nested paths (needs changes in router i think)
+ $realPath = __DIR__ . '/../static/' . $args['path'];
+ if (!is_file($realPath)) {
+ throw new NotFound('static resource ' . $args['path'] . ' does not exist');
+ }
+ $fileExtension = explode('.', basename($realPath));
+ $fileExtension = $fileExtension[count($fileExtension) - 1];
+ header('Content-Type: ' . match ($fileExtension) {
+ 'css' => 'text/css',
+ default => mime_content_type($realPath)
+ });
+ echo file_get_contents($realPath);
+}); \ No newline at end of file