From b758d52ae21b0aeff17061ff226a0fa9ff06d623 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Mon, 30 Oct 2023 14:19:28 +0100 Subject: [PATCH] [Glossary] Introduce terms listing & show pages --- .../images/pages/glossary/glossary-banner.svg | 1 + config/packages/twig.yaml | 3 +- content/member/_sample.yaml | 4 - content/member/frey.yaml | 2 - content/member/gfaivre.yaml | 2 - content/member/yheitz.yaml | 2 - content/term/aws.md | 8 ++ content/term/aws.yaml | 3 - content/term/example.md | 17 ++++ content/term/example.yaml | 3 - content/term/ovh-cloud.md | 8 ++ content/term/ovh-cloud.yaml | 3 - content/term/scaleway.md | 8 ++ content/term/scaleway.yaml | 3 - src/Controller/GlossaryController.php | 62 +++++++++++++++ src/Glossary/GlossaryBuilder.php | 4 +- src/Model/Glossary/Term.php | 32 +++++++- src/Model/Member.php | 3 - templates/case_study/show.html.twig | 7 +- templates/glossary/index.html.twig | 69 ++++++++++++++++ .../_term_list.html.twig} | 4 +- templates/glossary/term.html.twig | 78 +++++++++++++++++++ 22 files changed, 291 insertions(+), 35 deletions(-) create mode 100644 assets/images/pages/glossary/glossary-banner.svg create mode 100644 content/term/aws.md delete mode 100644 content/term/aws.yaml create mode 100644 content/term/example.md delete mode 100644 content/term/example.yaml create mode 100644 content/term/ovh-cloud.md delete mode 100644 content/term/ovh-cloud.yaml create mode 100644 content/term/scaleway.md delete mode 100644 content/term/scaleway.yaml create mode 100644 src/Controller/GlossaryController.php create mode 100644 templates/glossary/index.html.twig rename templates/glossary/{term_list.html.twig => partials/_term_list.html.twig} (80%) create mode 100644 templates/glossary/term.html.twig diff --git a/assets/images/pages/glossary/glossary-banner.svg b/assets/images/pages/glossary/glossary-banner.svg new file mode 100644 index 00000000..3d514cc0 --- /dev/null +++ b/assets/images/pages/glossary/glossary-banner.svg @@ -0,0 +1 @@ + diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 808d615d..3d47229c 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -24,7 +24,7 @@ twig: trackers: matomo: "%env(MATOMO_ID)%" - + caseStudies: enabled: true @@ -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: diff --git a/content/member/_sample.yaml b/content/member/_sample.yaml index 31dab47f..2684f689 100644 --- a/content/member/_sample.yaml +++ b/content/member/_sample.yaml @@ -20,10 +20,6 @@ linkedIn: ~ email: ~ avatar: content/images/member/avatars/path-to-avatar.jpg -certifications: - - symfony - - opquast - emojis: - 🎲 - 🎮 diff --git a/content/member/frey.yaml b/content/member/frey.yaml index 2717cca3..64bb985e 100644 --- a/content/member/frey.yaml +++ b/content/member/frey.yaml @@ -17,8 +17,6 @@ linkedIn: ~ email: florian.rey@elao.com avatar: content/images/member/avatars/ffrey.jpg -certifications: [ ] - emojis: - 🌰 - 👾 diff --git a/content/member/gfaivre.yaml b/content/member/gfaivre.yaml index 2af72b72..8ee082d9 100644 --- a/content/member/gfaivre.yaml +++ b/content/member/gfaivre.yaml @@ -14,8 +14,6 @@ avatar: content/images/member/avatars/gfaivre.jpg phone: '007' -certifications: [ ] - emojis: - 🤾🏻‍♂️ - 🎮 diff --git a/content/member/yheitz.yaml b/content/member/yheitz.yaml index c2cd88ab..19d18d75 100644 --- a/content/member/yheitz.yaml +++ b/content/member/yheitz.yaml @@ -13,6 +13,4 @@ linkedIn: ~ email: yves.heitz@elao.com avatar: content/images/member/avatars/yheizt.png -certifications: [ ] - emojis: [ ] diff --git a/content/term/aws.md b/content/term/aws.md new file mode 100644 index 00000000..4a2010a0 --- /dev/null +++ b/content/term/aws.md @@ -0,0 +1,8 @@ +--- +name: "AWS" +logo: "build/images/services/aws.svg" +externalLink: https://aws.amazon.com/fr/ +#metaDescription: TODO +--- + +Some **markdown** content diff --git a/content/term/aws.yaml b/content/term/aws.yaml deleted file mode 100644 index 19474b6d..00000000 --- a/content/term/aws.yaml +++ /dev/null @@ -1,3 +0,0 @@ -name: "AWS" -logo: "build/images/services/aws.svg" -link: https://aws.amazon.com/fr/ diff --git a/content/term/example.md b/content/term/example.md new file mode 100644 index 00000000..a3469a6c --- /dev/null +++ b/content/term/example.md @@ -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 diff --git a/content/term/example.yaml b/content/term/example.yaml deleted file mode 100644 index 17f798a4..00000000 --- a/content/term/example.yaml +++ /dev/null @@ -1,3 +0,0 @@ -name: "Exemple" -logo: "build/images/technos/exemple.svg" -link: http://example.org diff --git a/content/term/ovh-cloud.md b/content/term/ovh-cloud.md new file mode 100644 index 00000000..520c35ce --- /dev/null +++ b/content/term/ovh-cloud.md @@ -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 diff --git a/content/term/ovh-cloud.yaml b/content/term/ovh-cloud.yaml deleted file mode 100644 index e824d23b..00000000 --- a/content/term/ovh-cloud.yaml +++ /dev/null @@ -1,3 +0,0 @@ -name: "OVH Cloud" -logo: "build/images/services/ovh-cloud.svg" -link: https://www.ovhcloud.com/fr/ diff --git a/content/term/scaleway.md b/content/term/scaleway.md new file mode 100644 index 00000000..1179ed93 --- /dev/null +++ b/content/term/scaleway.md @@ -0,0 +1,8 @@ +--- +name: "Scaleway" +logo: "build/images/services/scaleway.svg" +externalLink: https://www.scaleway.com/fr/ +#metaDescription: TODO +--- + +Some **markdown** content diff --git a/content/term/scaleway.yaml b/content/term/scaleway.yaml deleted file mode 100644 index 19e7b3eb..00000000 --- a/content/term/scaleway.yaml +++ /dev/null @@ -1,3 +0,0 @@ -name: "Scaleway" -logo: "build/images/services/scaleway.svg" -link: https://www.scaleway.com/fr/ diff --git a/src/Controller/GlossaryController.php b/src/Controller/GlossaryController.php new file mode 100644 index 00000000..7028bc20 --- /dev/null +++ b/src/Controller/GlossaryController.php @@ -0,0 +1,62 @@ +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); + } +} diff --git a/src/Glossary/GlossaryBuilder.php b/src/Glossary/GlossaryBuilder.php index f44b997f..6e193059 100644 --- a/src/Glossary/GlossaryBuilder.php +++ b/src/Glossary/GlossaryBuilder.php @@ -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 { diff --git a/src/Model/Glossary/Term.php b/src/Model/Glossary/Term.php index 6b1eafca..43e93983 100644 --- a/src/Model/Glossary/Term.php +++ b/src/Model/Glossary/Term.php @@ -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; } diff --git a/src/Model/Member.php b/src/Model/Member.php index 142ec773..7f1bde52 100644 --- a/src/Model/Member.php +++ b/src/Model/Member.php @@ -34,9 +34,6 @@ class Member public ?string $phone = null; - /** @var string[] */ - public array $certifications = []; - public ?array $emojis = []; // Flags diff --git a/templates/case_study/show.html.twig b/templates/case_study/show.html.twig index df8ef417..5cf88b94 100644 --- a/templates/case_study/show.html.twig +++ b/templates/case_study/show.html.twig @@ -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')) %} @@ -42,7 +43,7 @@
Les technos utilisées
- {% include "glossary/term_list.html.twig" with { + {% include "glossary/partials/_term_list.html.twig" with { terms: caseStudy.terms } only %} diff --git a/templates/glossary/index.html.twig b/templates/glossary/index.html.twig new file mode 100644 index 00000000..6aea19ac --- /dev/null +++ b/templates/glossary/index.html.twig @@ -0,0 +1,69 @@ +{% import "macros.html.twig" as macros %} + +{% extends 'base.html.twig' %} + +{% block meta_title -%} + Glossaire | {{ parent() }} +{%- endblock %} + +{% block meta_description -%} + {# TODO #} +{%- endblock %} + +{% block body_class 'page-glossary' %} + +{% block content %} +
+ + + +
+ {% for column in glossary %} +
    + {% for letter, group in column %} + {% for term in group %} +
  • + + {{ term.name }} + +
  • + {% endfor %} + {% endfor %} +
+ {% endfor %} +
+ +

Pour aller encore plus loin dans le quotidien d'un projet web, découvrez notre blog

+ + + + + + Tous les articles + + +
+{% endblock %} diff --git a/templates/glossary/term_list.html.twig b/templates/glossary/partials/_term_list.html.twig similarity index 80% rename from templates/glossary/term_list.html.twig rename to templates/glossary/partials/_term_list.html.twig index a71ce5ab..72f5920e 100644 --- a/templates/glossary/term_list.html.twig +++ b/templates/glossary/partials/_term_list.html.twig @@ -2,7 +2,9 @@ {% for slug in terms %} {% set term = content_get('App\\Model\\Glossary\\Term', slug) %}
  • - + Logo {{ term.logo }} {{ term.name }} diff --git a/templates/glossary/term.html.twig b/templates/glossary/term.html.twig new file mode 100644 index 00000000..ff738147 --- /dev/null +++ b/templates/glossary/term.html.twig @@ -0,0 +1,78 @@ +{% extends 'base.html.twig' %} + +{% import "macros.html.twig" as macros %} + +{% block meta_title term.metaTitle ?? term.name %} +{% block meta_description term.metaDescription ?? term.description ?? term.name %} + +{% block body_class 'page-glossary-term' %} + +{% block content %} + {# TODO: breadcrumb or link to tet back to glossary page ? #} + +
    +
    +

    + {{ term.name }} +

    + + {% if term.logo is not empty %} +
    + logo de {{ term.name }} +
    + {% endif %} + + + {% if term.externalLink is not empty %} +
    + Lien vers le site officiel +
    + {% endif %} +
    + +
    + {{ term.content|raw }} + +
    + + {# Related case-studies #} + {% if caseStudies is not empty %} +

    Projets créés avec {{ term.name }}

    + + {% endif %} + + {# Related articles #} + {% if articles is not empty %} +

    Articles liés à {{ term.name }}

    + + {% endif %} +
    +
    +{% endblock content %}