summaryrefslogtreecommitdiff
path: root/blog/index.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-12-12 10:34:56 +0500
committerilotterytea <iltsu@alright.party>2025-12-12 10:34:56 +0500
commit853d253a7dc0c7de6438310cd94a7ece2da9397c (patch)
treec0035cabd2253146a313bb023d0d05aafc12536f /blog/index.php
parent125a28557b42cfadc5a8c237a9b8d1ea0260a206 (diff)
feat: store posts in text format
Diffstat (limited to 'blog/index.php')
-rw-r--r--blog/index.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/blog/index.php b/blog/index.php
new file mode 100644
index 0000000..773cc6f
--- /dev/null
+++ b/blog/index.php
@@ -0,0 +1,62 @@
+<?php
+include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/time.php';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/post.php';
+
+$post_id = null;
+$url = parse_url($_SERVER['REQUEST_URI']);
+if (strlen($url['path']) > 1) {
+ $post_id = explode("/", substr($url['path'], 1), 2);
+ $post_id = $post_id[count($post_id) - 1];
+}
+
+if ($post_id) {
+ $post = read_post(urldecode($post_id));
+ if (!$post) {
+ http_response_code(404);
+ exit("Post not found");
+ }
+} else {
+ $posts = get_posts();
+}
+?>
+<!DOCTYPE html>
+<html>
+
+<head>
+ <title>blog - ilt.su</title>
+ <meta name="description" content="my blog.">
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+ <link rel="stylesheet" href="/static/style.css">
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
+ <meta name="robots" content="noindex, nofollow">
+</head>
+
+<body>
+ <main>
+ <p><a href="/">ilt.su</a> - <a href="/blog/">blog</a></p>
+ <?php if (isset($post)): ?>
+ <h1><?= $post['name'] ?? '<i>No title.</i>' ?></h1>
+ <div>
+ <?= $post['contents'] ?? '<i>No contents.</i>' ?>
+ </div>
+ <p><i>Posted <?= format_timestamp(time() - $post['time']) ?> ago</i></p>
+ <?php endif; ?>
+
+ <?php if (isset($posts)): ?>
+ <h1>Blog</h1>
+ <ul>
+ <?php foreach ($posts as $s): ?>
+ <li><a href="/blog/<?= urlencode($s['name']) ?>"><?= $s['name'] ?></a>
+ <i><?= format_timestamp(time() - $s['time']) ?>
+ ago</i>
+ </li>
+ <?php endforeach; ?>
+ <?php if (empty($posts)): ?>
+ <i>No posts yet.</i>
+ <?php endif; ?>
+ </ul>
+ <?php endif; ?>
+ </main>
+</body>
+
+</html> \ No newline at end of file