Skip to content

Commit

Permalink
feat: allow previews on blog
Browse files Browse the repository at this point in the history
  • Loading branch information
Grafikart committed Mar 8, 2025
1 parent e9b9643 commit 31f774f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
16 changes: 11 additions & 5 deletions assets/css/modules/_formatted.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
}

.formatted {

iframe {
aspect-ratio: 16 / 9;
width: 100%;
Expand Down Expand Up @@ -71,12 +70,11 @@
ul,
ol,
blockquote {
margin-top: 1rem;
margin-bottom: 30px;
margin-block: 1.33rem;
}

p, ul, ol {
line-height: 1.6;
ul ul {
margin-top: 0;
}

p:first-child {
Expand All @@ -94,6 +92,7 @@

h1 {
font-size: 2em;
line-height: 1.1;
}

h2 {
Expand Down Expand Up @@ -223,3 +222,10 @@
outline: none;
}
}

@media (min-width: 1024px) {
.formatted {
font-size: 1.125rem;
line-height: 1.7777778;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grafikart",
"version": "1.0.108",
"version": "1.0.109",
"main": "index.js",
"license": "MIT",
"type": "module",
Expand Down
14 changes: 13 additions & 1 deletion src/Http/Security/PostVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
namespace App\Http\Security;

use App\Domain\Blog\Post;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;

class PostVoter extends Voter
{
final public const SHOW = 'show';

public function __construct(private RequestStack $requestStack)
{
}

protected function supports(string $attribute, $subject): bool
{
return in_array($attribute, [
Expand All @@ -23,6 +28,13 @@ protected function supports(string $attribute, $subject): bool
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
return $subject instanceof Post && $subject->getCreatedAt() < new \DateTimeImmutable();
if (!($subject instanceof Post)) {
return false;
}
if ($this->requestStack->getMainRequest()?->query->getBoolean('preview')) {
return true;
}

return $subject->isOnline() && $subject->getCreatedAt() < new \DateTimeImmutable();
}
}

0 comments on commit 31f774f

Please sign in to comment.