Skip to content

Commit

Permalink
[Glossary] Introduce terms listing & show pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ogizanagi committed Oct 30, 2023
1 parent 57929a7 commit b758d52
Show file tree
Hide file tree
Showing 22 changed files with 291 additions and 35 deletions.
1 change: 1 addition & 0 deletions assets/images/pages/glossary/glossary-banner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion config/packages/twig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ twig:

trackers:
matomo: "%env(MATOMO_ID)%"

caseStudies:
enabled: true

Expand All @@ -45,6 +45,7 @@ twig:
footer:
- { path: "case_studies", label: "Cas clients" }
- { path: "about", label: "À propos" }
- { path: "glossary", label: "Glossaire" }
- { path: "contact", label: "Contact" }

footerServices:
Expand Down
4 changes: 0 additions & 4 deletions content/member/_sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ linkedIn: ~
email: ~
avatar: content/images/member/avatars/path-to-avatar.jpg

certifications:
- symfony
- opquast

emojis:
- 🎲
- 🎮
Expand Down
2 changes: 0 additions & 2 deletions content/member/frey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ linkedIn: ~
email: florian.rey@elao.com
avatar: content/images/member/avatars/ffrey.jpg

certifications: [ ]

emojis:
- 🌰
- 👾
Expand Down
2 changes: 0 additions & 2 deletions content/member/gfaivre.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ avatar: content/images/member/avatars/gfaivre.jpg

phone: '007'

certifications: [ ]

emojis:
- 🤾🏻‍♂️
- 🎮
Expand Down
2 changes: 0 additions & 2 deletions content/member/yheitz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ linkedIn: ~
email: yves.heitz@elao.com
avatar: content/images/member/avatars/yheizt.png

certifications: [ ]

emojis: [ ]
8 changes: 8 additions & 0 deletions content/term/aws.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: "AWS"
logo: "build/images/services/aws.svg"
externalLink: https://aws.amazon.com/fr/
#metaDescription: TODO
---

Some **markdown** content
3 changes: 0 additions & 3 deletions content/term/aws.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions content/term/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: "Exemple"
logo: "build/images/technos/exemple.svg"
externalLink: http://example.org

# False to prevent listing it on the glossary page.
# Cans till be externalLinked from articles or case studies.
listInGlossary: false

# Array of slugs of related articles to show on the glossary term page.
# If not provided (null), will search for related articles by their tags.
articles: []

metaDescription: Une description courte à utiliser dans les meta de la page
---

Some **markdown** content
3 changes: 0 additions & 3 deletions content/term/example.yaml

This file was deleted.

8 changes: 8 additions & 0 deletions content/term/ovh-cloud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: "OVH Cloud"
logo: "build/images/services/ovh-cloud.svg"
externalLink: https://www.ovhcloud.com/fr/
#metaDescription: TODO
---

Some **markdown** content
3 changes: 0 additions & 3 deletions content/term/ovh-cloud.yaml

This file was deleted.

8 changes: 8 additions & 0 deletions content/term/scaleway.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: "Scaleway"
logo: "build/images/services/scaleway.svg"
externalLink: https://www.scaleway.com/fr/
#metaDescription: TODO
---

Some **markdown** content
3 changes: 0 additions & 3 deletions content/term/scaleway.yaml

This file was deleted.

62 changes: 62 additions & 0 deletions src/Controller/GlossaryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace App\Controller;

use App\Glossary\GlossaryBuilder;
use App\Model\Article;
use App\Model\CaseStudy;
use App\Model\Glossary\Term;
use Stenope\Bundle\ContentManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

#[Route('/glossaire')]
class GlossaryController extends AbstractController
{
private ContentManagerInterface $manager;

public function __construct(ContentManagerInterface $manager)
{
$this->manager = $manager;
}

#[Route('/', name: 'glossary')]
public function glossary(GlossaryBuilder $builder): Response
{
$terms = $this->manager->getContents(Term::class, 'name', ['listInGlossary' => true]);
$articles = $this->manager->getContents(Article::class, ['date' => false]);

return $this->render('glossary/index.html.twig', [
'glossary' => $builder->build($terms),
'articles' => \array_slice($articles, 0, 4),
]);
}

#[Route('/{term}', name: 'glossary_term')]
public function show(Term $term): Response
{
$articlesFilter = null !== $term->articles
// Search for articles by their slug if provided
? static fn ($article) => \in_array($article->slug, $term->articles, true)
// otherwise by their tags matching the term slug
: static fn (Article $article): bool => $article->hasTag($term->slug)
;

$articles = $this->manager->getContents(Article::class, ['date' => false], $articlesFilter);

$caseStudies = $this->manager->getContents(
CaseStudy::class,
['date' => false],
fn (CaseStudy $caseStudy): bool => $caseStudy->enabled && $caseStudy->hasTerm($term)
);

return $this->render('glossary/term.html.twig', [
'term' => $term,
'articles' => \array_slice($articles, 0, 3),
'caseStudies' => $caseStudies,
])->setLastModified($term->lastModified);
}
}
4 changes: 2 additions & 2 deletions src/Glossary/GlossaryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
class GlossaryBuilder
{
/**
* @param array|Term[] $terms
* @param int<0, max> $split
* @param Term[] $terms
* @param int<0, max> $split
*/
public function build(array $terms, int $split = 3): array
{
Expand Down
32 changes: 29 additions & 3 deletions src/Model/Glossary/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,37 @@

namespace App\Model\Glossary;

use App\Model\MetaTrait;

class Term
{
public string $name;
public ?string $logo = null;
use MetaTrait;

public string $slug;
public string $link;

public ?string $logo = null;

/** Link to outside resource for this term. */
public string $externalLink;

public string $name;

/** Main, markdown content */
public ?string $content = null;

/**
* Array of slugs of related articles to show on the glossary term page.
* If not provided (null), will search for related articles by their tags.
*
* @var string[]|null
*/
public ?array $articles = null;

public \DateTimeInterface $lastModified;

/**
* Set as false to prevent this term to appear in glossary listing.
* The term can still be referenced from articles or case studies.
*/
public bool $listInGlossary = true;
}
3 changes: 0 additions & 3 deletions src/Model/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ class Member

public ?string $phone = null;

/** @var string[] */
public array $certifications = [];

public ?array $emojis = [];

// Flags
Expand Down
7 changes: 4 additions & 3 deletions templates/case_study/show.html.twig
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{% import "macros.html.twig" as macros %}

{% extends 'base.html.twig' %}

{% block meta_title -%}
{{ caseStudy.metaTitle|default(caseStudy.title) }} | {{ parent() }}
{{ caseStudy.metaTitle ?? caseStudy.title }} | {{ parent() }}
{%- endblock %}

{% block meta_description -%}
{{ caseStudy.metaDescription|default(caseStudy.description)|default(parent()) }}
{{ caseStudy.metaDescription ?? parent() }}
{%- endblock %}

{% block og_image asset(caseStudy.images|first|glide_image_preset('opengraph_image')) %}
Expand Down Expand Up @@ -42,7 +43,7 @@
<div class="technologies-list__title">
<span class="h3--small">Les technos utilisées</span>
</div>
{% include "glossary/term_list.html.twig" with {
{% include "glossary/partials/_term_list.html.twig" with {
terms: caseStudy.terms
} only %}
</div>
Expand Down
Loading

0 comments on commit b758d52

Please sign in to comment.