Welcome to my digital playground.
-
Imprint
-
Privacy Policy
+
+
+
+
+
= $blog->formatDate() ?>
+
+
diff --git a/www/lib/_index.php b/www/lib/_index.php
index 737d7ca..506161a 100644
--- a/www/lib/_index.php
+++ b/www/lib/_index.php
@@ -2,4 +2,5 @@
require_once __DIR__ . '/style.php';
require_once __DIR__ . '/stars.php';
-require_once __DIR__ . '/fill.php';
\ No newline at end of file
+require_once __DIR__ . '/fill.php';
+require_once __DIR__ . '/blog.php';
\ No newline at end of file
diff --git a/www/lib/blog.php b/www/lib/blog.php
new file mode 100644
index 0000000..4083f81
--- /dev/null
+++ b/www/lib/blog.php
@@ -0,0 +1,74 @@
+id = $id;
+ $this->title = $title;
+ $this->date = $date;
+ $this->files = $files;
+ }
+
+ public function formatDate(): string
+ {
+ return date("F jS, Y", strtotime($this->date));
+ }
+
+ public function getSVGs(): array
+ {
+ return array_map(function ($file) {
+ $svg = file_get_contents(__DIR__ . '/../blog/' . $file);
+
+ if (str_starts_with($svg, ']+>\s*/', '', $svg);
+ }
+
+ return $svg;
+ }, $this->files);
+ }
+
+ public static function get(string|int $id): Blog|null
+ {
+ $path = __DIR__ . "/../blog/$id.json";
+ if (!file_exists($path))
+ return null;
+
+ try {
+ $json = json_decode(file_get_contents($path), true);
+ return new Blog($id, $json['title'], $json['date'], $json['files']);
+ } catch (Exception $e) {
+ return null;
+ }
+ }
+
+ /**
+ * @return Blog[]
+ */
+ public static function getAll()
+ {
+ $files = scandir(__DIR__ . '/../blog');
+ $files = array_filter($files, function ($file) {
+ return str_ends_with($file, '.json');
+ });
+
+ $ids = array_map(function ($file) {
+ return str_replace('.json', '', $file);
+ }, $files);
+
+ $blogs = [];
+
+ foreach ($ids as $id) {
+ $blog = Blog::get($id);
+ if ($blog !== null)
+ array_push($blogs, $blog);
+ }
+
+ return $blogs;
+ }
+}
\ No newline at end of file