Browse Source

Fix article editing and images

imwald
Nuša Pukšič 4 months ago
parent
commit
f606b25636
  1. 7
      assets/styles/article.css
  2. 8
      src/Controller/ArticleController.php
  3. 10
      src/Controller/AuthorController.php
  4. 19
      templates/pages/article.html.twig

7
assets/styles/article.css

@ -7,6 +7,13 @@ @@ -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,

8
src/Controller/ArticleController.php

@ -94,12 +94,10 @@ class ArticleController extends AbstractController @@ -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 @@ -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) {

10
src/Controller/AuthorController.php

@ -36,6 +36,11 @@ class AuthorController extends AbstractController @@ -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 @@ -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,

19
templates/pages/article.html.twig

@ -13,16 +13,17 @@ @@ -13,16 +13,17 @@
{% block body %}
<div class="article-actions">
{% if canEdit %}
<a class="btn btn-primary" href="{{ path('editor-edit-slug', {'slug': article.slug}) }}">Edit article</a>
{% endif %}
{% if canEdit %}
<a class="btn btn-primary" href="{{ path('editor-edit-slug', {'slug': article.slug}) }}">Edit article</a>
{% endif %}
{% if is_granted('ROLE_ADMIN') %}
<button class="btn btn-primary" onclick="navigator.clipboard.writeText('30023:{{ article.pubkey }}:{{ article.slug }}')">
Copy coordinates
</button>
{% endif %}
{% if is_granted('ROLE_ADMIN') %}
<button class="btn btn-primary" onclick="navigator.clipboard.writeText('30023:{{ article.pubkey }}:{{ article.slug }}')">
Copy coordinates
</button>
{% endif %}
</div>
<div class="card">
<div class="card-header">

Loading…
Cancel
Save