From add698651efc2b7ce5f3aaf0a4b504159a3f8104 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Mon, 22 Jan 2024 16:31:16 +0100 Subject: [PATCH] feat: :sparkles: add gallery page --- www/router.php | 26 ++++++++++-- www/templates/post_types/gallery.html | 59 +++++++++++++++++++++++++++ www/templates/root.dergplate | 18 -------- www/templates/root.html | 5 +++ 4 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 www/templates/post_types/gallery.html delete mode 100644 www/templates/root.dergplate diff --git a/www/router.php b/www/router.php index 7baf82a..91b9779 100644 --- a/www/router.php +++ b/www/router.php @@ -99,6 +99,7 @@ function render_twig($template, $args = []) { "site_name" => $SITE_CONFIG['opengraph']['site_name'], "title" => $meta['title'] ?? $SITE_CONFIG['opengraph']['site_name'], "url" => $_SERVER['REQUEST_URI'], + "type" => "article", "description" => $meta['description'] ?? $settings['description'] ?? $SITE_CONFIG['opengraph']['description'] @@ -106,9 +107,10 @@ function render_twig($template, $args = []) { if(($meta['type'] ?? '') == 'image') { $args['og']['image'] ??= $meta['media_file']; + $args['og']['type'] = "image"; } - $args['og']['image'] ??= $SITE_CONFIG['uri_prefix'] . $args['banner'][0]["src"]; + $args['og']['image'] ??= $args['banner'][0]["src"]; $args['banner'] = json_encode($args['banner']); @@ -161,6 +163,25 @@ function try_render_post($SURI) { ]); break; + case 'gallery': + if(preg_match('/^(.*[^\/])((?:#.*)?)$/', $SURI, $match)) { + header('Location: ' . $match[1] . '/' . $match[2]); + + die(); + } + + $search_query = $post['post_metadata']['search_tags'] ?? + ('+type:image +path:' . $post['post_path'] . '/*'); + + $search_result = $adapter->perform_post_search($search_query); + + echo render_twig('post_types/gallery.html', [ + "post" => $post, + "subposts" => $adapter->get_subposts_by_path($SURI), + "gallery_images" => $search_result['results'] + ]); + break; + case 'image': echo render_twig('post_types/image.html', [ "post" => $post, @@ -227,9 +248,6 @@ function generate_website($SURI) { header('Etag: W/"' . $SURI . '/' . strtotime($feed['feed_ts']) . '"'); echo $feed['feed']; - } elseif(!preg_match('/^\s*text\/html/', $_SERVER['HTTP_ACCEPT'])) { - header('Location: /raw' . $SURI); - exit(0); } elseif(true) { try_render_post($SURI); } diff --git a/www/templates/post_types/gallery.html b/www/templates/post_types/gallery.html new file mode 100644 index 0000000..4e96b3d --- /dev/null +++ b/www/templates/post_types/gallery.html @@ -0,0 +1,59 @@ + + +{% extends "pathed_content.html" %} + +{% block extra_head %} + + +{%endblock%} + +{%block content_article%} + {% if subposts|length > 0 %} + +

Art Subfolders:

+ + + + + + + {% for subpost in subposts %} + + + + + + + {% endfor %} +
NameTitleModified
+ {{ fa[subpost.post_metadata.icon] | raw }} + + {{subpost.post_basename}} + + {{ subpost.post_metadata.title }} + + {{ subpost.post_update_time }} +
+ {% endif %} + + {{ content_html|raw }} + + {% if gallery_images|length > 0 %} + + {%else%} +

How sad. There are no images yet... What a real shame :c

+ {% endif %} +{%endblock%} diff --git a/www/templates/root.dergplate b/www/templates/root.dergplate deleted file mode 100644 index fa4e62b..0000000 --- a/www/templates/root.dergplate +++ /dev/null @@ -1,18 +0,0 @@ - - - PHP Test - - - Hello World

'; - - require 'src/templater.php'; - - $test = new TemplateFillout('test.dergplate'); - - $test->render(); - - ?> - - diff --git a/www/templates/root.html b/www/templates/root.html index 11f0c14..01a87d6 100644 --- a/www/templates/root.html +++ b/www/templates/root.html @@ -23,12 +23,17 @@ + + + + + {% endblock %}