Skip to content

Commit bd66632

Browse files
committed
meta-update, count category posts
1 parent 097934c commit bd66632

6 files changed

Lines changed: 55 additions & 17 deletions

File tree

config/autoload/app.global.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

33
declare(strict_types=1);
4-
4+
$baseUrl = 'https://light-blog.localhost/';
55
$app = [
6+
'baseUrl' => 'https://light-blog.localhost/',
67
'name' => 'Dotkernel Light | PSR-15 compliant application',
78
'meta' => [
89
'title' => 'Dotkernel Light',
@@ -11,11 +12,11 @@
1112
built on top of the Mezzio microframework using Laminas components. The goal is to provide a
1213
pre-configured environment for app',
1314

14-
'image' => '/uploads/logos/logo.png',
15+
'image' => $baseUrl . 'uploads/opengraph/dotkernel.png',
1516
'type' => 'website',
1617
'siteName' => 'Dotkernel Light',
1718
'locale' => 'en_US',
18-
'url' => 'https://www.dotkernel.com',
19+
'url' => $baseUrl,
1920
'twitterCard' => 'summary_large_image',
2021
'twitterSite' => '@dotkernel',
2122
],

src/App/templates/partial/left-menu.html.twig

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,29 @@
1212
</div>
1313
</div>
1414
</div>
15+
{% if data is defined %}
16+
<div class="card border-0 shadow-sm rounded-3 my-4">
17+
<div class="card-body p-3">
18+
<h6 class="fw-bold text-uppercase text-muted small px-1 mb-2">Recent Articles</h6>
1519

20+
<div class="list-group list-group-flush">
21+
22+
{% for article in data.items|slice(0, 3) %}
23+
<a href="{{ url('page::blog-resource', {categorySlug: article.category.slug, slug: article.slug}) }}"
24+
class="list-group-item list-group-item-action border-0 px-1 py-2 rounded">
25+
<p class="mb-1 small fw-semibold text-dark lh-sm">{{ article.title }}</p>
26+
<span class="text-muted" style="font-size: 11px;">
27+
<i class="bi bi-calendar3 me-1"></i>{{ article.postDate|date('M d, Y') }}
28+
</span>
29+
</a>
30+
{% else %}
31+
<p class="text-muted small mb-0">No recent articles.</p>
32+
{% endfor %}
33+
34+
</div>
35+
</div>
36+
</div>
37+
{% endif %}
1638
<div class="card border-0 shadow-sm rounded-3">
1739
<div class="card-body p-3">
1840
<h6 class="fw-bold text-uppercase text-muted small px-1 mb-2">Categories</h6>
@@ -22,7 +44,7 @@
2244
<a href="{{ url('page::category-resource', {slug: category.slug}) }}"
2345
class="list-group-item list-group-item-action d-flex align-items-center justify-content-between py-2 px-1 border-0 rounded text-secondary small">
2446
<span>{{ category.name }}</span>
25-
<i class="bi bi-chevron-right text-muted" style="font-size: 10px;"></i>
47+
<span class="badge bg-light text-secondary border ms-auto me-2">{{ category.posts.count() }}</span>
2648
</a>
2749
{% endfor %}
2850
</div>
@@ -31,7 +53,9 @@
3153
See all categories <i class="bi bi-arrow-right fs-7"></i>
3254
</a>
3355
</div>
56+
3457
</div>
58+
3559
</div>
3660

3761
</div>

src/App/templates/partial/meta.html.twig

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
44
<meta name="msapplication-TileColor" content="#2d89ef">
55
<meta name="theme-color" content="#ffffff">
6-
<title>{{ meta.title ?? meta.name?? app.meta.title }}</title>
7-
<meta name="description" content="{{ meta.description ?? meta.excerpt?? app.meta.description }}"/>
6+
<title>{{ meta.title ?? meta.name ?? app.meta.title }}</title>
87

9-
<meta property="og:title" content="{{ meta.title ?? app.meta.title }}"/>
10-
<meta name="description" content="{{ meta.description ?? meta.excerpt?? app.meta.description }}"/>
11-
<meta property="og:image" content="{{ meta.image ?? app.meta.image }}"/>
12-
<meta property="og:type" content="{{ meta.type ?? app.meta.type }}"/>
13-
<meta property="og:site_name" content="{{ app.meta.siteName }}"/>
14-
<meta property="og:url" content="{{ app.meta.url }}"/>
8+
<meta name="description" content="{{ meta.description ?? meta.excerpt ?? app.meta.description }}"/>
9+
<meta property="og:title" content="{{ meta.title ?? app.meta.title }}"/>
10+
<meta property="og:description" content="{{ meta.description ?? meta.excerpt ?? app.meta.description }}"/>
11+
<meta property="og:image" content="{{ meta.image ?? app.meta.image }}"/>
12+
<meta property="og:type" content="{{ meta.type ?? app.meta.type }}"/>
13+
<meta property="og:site_name" content="{{ app.meta.siteName }}"/>
14+
<meta property="og:url" content="{{ meta.url ?? app.meta.url }}"/>
15+
<meta property="og:locale" content="{{ app.meta.locale }}"/>
1516

1617
<meta name="twitter:card" content="{{ app.meta.twitterCard }}"/>
1718
<meta name="twitter:site" content="{{ app.meta.twitterSite }}"/>
18-
<meta name="twitter:title" content="{{ meta.title ?? meta.name?? app.meta.title }}"/>
19-
<meta name="twitter:description" content="{{ meta.excerpt ?? app.meta.description }}"/>
19+
<meta name="twitter:title" content="{{ meta.title ?? meta.name ?? app.meta.title }}"/>
20+
<meta name="twitter:description" content="{{ meta.description ?? meta.excerpt ?? app.meta.description }}"/>
2021
<meta name="twitter:image" content="{{ meta.image ?? app.meta.image }}"/>

src/Blog/src/Entity/Category.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
declare(strict_types=1);
44

55
namespace Light\Blog\Entity;
6-
6+
use Doctrine\Common\Collections\Collection;
77
use Doctrine\ORM\Mapping as ORM;
88
use Light\App\Entity\AbstractEntity;
99
use Light\Blog\Repository\CategoryRepository;
@@ -13,6 +13,7 @@
1313
#[ORM\HasLifecycleCallbacks]
1414
class Category extends AbstractEntity
1515
{
16+
1617
#[ORM\Column(name: 'name', type: 'text')]
1718
private string $name;
1819

@@ -22,6 +23,9 @@ class Category extends AbstractEntity
2223
#[ORM\Column(name: 'isVisible', type: 'boolean')]
2324
private bool $isVisible = true;
2425

26+
#[ORM\OneToMany(mappedBy: 'category', targetEntity: Post::class)]
27+
private Collection $posts;
28+
2529
public function getName(): string
2630
{
2731
return $this->name;
@@ -52,6 +56,11 @@ public function setVisibility(bool $isVisible): void
5256
$this->isVisible = $isVisible;
5357
}
5458

59+
public function getPosts(): Collection
60+
{
61+
return $this->posts;
62+
}
63+
5564
/**
5665
* @return array{
5766
* id: non-empty-string,
@@ -67,6 +76,8 @@ public function getArrayCopy(): array
6776
'name' => $this->name,
6877
'isVisible' => $this->isVisible,
6978
'slug' => $this->slug,
79+
'postCount' => $this->posts->count(),
80+
'posts' => $this->posts->map(fn (Post $post) => $post->getArrayCopy())->toArray(),
7081
];
7182
}
7283
}

src/Blog/src/Handler/GetPostResourceHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
2727
$categorySlug = $request->getAttribute('categorySlug');
2828
$article = $this->articleRepository->getArticleResource($slug, $categorySlug);
2929
$categories = $this->categoryRepository->getCategories();
30-
$meta = $article;
30+
$meta = $article;
3131
return new HtmlResponse(
3232
$this->template->render('page::blog-resource/' . $article->getCategory()->getSlug() . '/' . $slug, [
3333
'article' => $article,

src/Blog/src/Repository/CategoryRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ class CategoryRepository extends AbstractRepository
1717
public function getCategories(): array
1818
{
1919
$qb = $this->getQueryBuilder()
20-
->select('categories.name, categories.slug')
20+
->select('categories')
2121
->from(Category::class, 'categories')
2222
->where('categories.isVisible = :visible')
2323
->setParameter('visible', true);
24+
2425
return $qb->getQuery()->getResult();
2526
}
2627

0 commit comments

Comments
 (0)