From f606b2563617eb9932ec233a64d858f637088ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Wed, 10 Sep 2025 19:07:36 +0200 Subject: [PATCH] Fix article editing and images --- assets/styles/article.css | 7 +++++++ src/Controller/ArticleController.php | 8 +++----- src/Controller/AuthorController.php | 10 +++++----- templates/pages/article.html.twig | 19 ++++++++++--------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/assets/styles/article.css b/assets/styles/article.css index a2cfb07..7f70aae 100644 --- a/assets/styles/article.css +++ b/assets/styles/article.css @@ -7,6 +7,13 @@ margin-top: 2em; } +.article-actions { + display: flex; + justify-content: flex-start; + gap: 1rem; + margin: 1rem 0; +} + .article-main p, .article-main ul, .article-main ol, diff --git a/src/Controller/ArticleController.php b/src/Controller/ArticleController.php index 93bf545..bd70cbf 100644 --- a/src/Controller/ArticleController.php +++ b/src/Controller/ArticleController.php @@ -94,12 +94,10 @@ class ArticleController extends AbstractController usort($articles, function ($a, $b) { return $b->getCreatedAt() <=> $a->getCreatedAt(); }); - // get the last article - $article = end($articles); - } else { - $article = $articles[0]; } + $article = $articles[0]; + $cacheKey = 'article_' . $article->getEventId(); $cacheItem = $articlesCache->getItem($cacheKey); if (!$cacheItem->isHit()) { @@ -157,7 +155,7 @@ class ArticleController extends AbstractController usort($articles, function ($a, $b) { return $b->getCreatedAt() <=> $a->getCreatedAt(); }); - $article = end($articles); + $article = array_pop($articles); } if ($article->getPubkey() === null) { diff --git a/src/Controller/AuthorController.php b/src/Controller/AuthorController.php index 4a2fb16..480df6e 100644 --- a/src/Controller/AuthorController.php +++ b/src/Controller/AuthorController.php @@ -36,6 +36,11 @@ class AuthorController extends AbstractController $query = new Terms('pubkey', [$pubkey]); $list = array_merge($list, $finder->find($query, 25)); + // Sort articles by date + usort($list, function ($a, $b) { + return $b->getCreatedAt() <=> $a->getCreatedAt(); + }); + $articles = []; // Deduplicate by slugs foreach ($list as $item) { @@ -44,11 +49,6 @@ class AuthorController extends AbstractController } } - // Sort articles by date - usort($articles, function ($a, $b) { - return $b->getCreatedAt() <=> $a->getCreatedAt(); - }); - return $this->render('pages/author.html.twig', [ 'author' => $author, 'npub' => $npub, diff --git a/templates/pages/article.html.twig b/templates/pages/article.html.twig index 77f19e3..7d3e5e1 100644 --- a/templates/pages/article.html.twig +++ b/templates/pages/article.html.twig @@ -13,16 +13,17 @@ {% block body %} +
+ {% if canEdit %} + Edit article + {% endif %} - {% if canEdit %} - Edit article - {% endif %} - - {% if is_granted('ROLE_ADMIN') %} - - {% endif %} + {% if is_granted('ROLE_ADMIN') %} + + {% endif %} +