From 42d72add684a97406519559a0295fcbbc3bd4175 Mon Sep 17 00:00:00 2001
From: Etienne LOUPIAS <eloupias@grandlyon.com>
Date: Mon, 20 Nov 2023 10:05:54 +0100
Subject: [PATCH] test og tags

---
 .../post-details/post-details.component.ts          | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/app/post/components/post-details/post-details.component.ts b/src/app/post/components/post-details/post-details.component.ts
index f429423bc..77bbd4a7b 100644
--- a/src/app/post/components/post-details/post-details.component.ts
+++ b/src/app/post/components/post-details/post-details.component.ts
@@ -1,5 +1,5 @@
 import { Component, ElementRef, OnInit, Renderer2, ViewEncapsulation } from '@angular/core';
-import { DomSanitizer, Title } from '@angular/platform-browser';
+import { DomSanitizer, Meta, Title } from '@angular/platform-browser';
 import { ActivatedRoute } from '@angular/router';
 import { RouterListenerService } from '../../../services/routerListener.service';
 import { Post } from '../../models/post.model';
@@ -22,6 +22,7 @@ export class PostDetailsComponent implements OnInit {
     private readonly elementRef: ElementRef,
     private renderer: Renderer2,
     private title: Title,
+    private meta: Meta,
   ) {}
 
   ngOnInit(): void {
@@ -33,6 +34,13 @@ export class PostDetailsComponent implements OnInit {
       this.postService.getPost(postSlug).subscribe((post) => {
         this.post = post.posts[0];
         this.post.safeHtml = this.sanitizer.bypassSecurityTrustHtml(this.post.html);
+
+        this.meta.addTag({ property: 'og:title', content: this.post.title });
+        // this.meta.addTag({ property: 'og:image', content: this.post.feature_image });
+        this.meta.addTag({
+          property: 'og:image',
+          content: 'https://resin-dev.apps.grandlyon.com/assets/logos/logo_europe.png',
+        });
       });
     }
     // add ghost JS
@@ -41,6 +49,9 @@ export class PostDetailsComponent implements OnInit {
     this.renderer.appendChild(this.elementRef.nativeElement, script);
     // set page title
     this.title.setTitle(this.post.title + " | Réseau des acteurs de l'inclusion numérique de la métropole de Lyon");
+
+    this.meta.updateTag({ property: 'og:title', content: this.post.title });
+    this.meta.updateTag({ property: 'og:image', content: this.post.feature_image });
   }
 
   public backToPosts(): void {
-- 
GitLab