Browse Source

Add Open Graph

Visman 1 năm trước cách đây
mục cha
commit
8b829e571a
2 tập tin đã thay đổi với 22 bổ sung0 xóa
  1. 6 0
      app/Models/Page.php
  2. 16 0
      app/templates/layouts/main.forkbb.php

+ 6 - 0
app/Models/Page.php

@@ -71,6 +71,12 @@ abstract class Page extends Model
 
         $this->mDescription = $this->c->config->s_meta_desc;
 
+        if (! empty($this->c->config->a_og_image['file'])) {
+            $this->mOgImage  = $this->c->PUBLIC_URL . '/img/og/' . $this->c->config->a_og_image['file'];
+            $this->mOgImageX = $this->c->config->a_og_image['width'] ?? null;
+            $this->mOgImageY = $this->c->config->a_og_image['height'] ?? null;
+        }
+
         if (1 === $container->config->b_announcement) {
             $this->fAnnounce = $container->config->o_announcement_message;
         }

+ 16 - 0
app/templates/layouts/main.forkbb.php

@@ -12,6 +12,22 @@
 @endif
 @if ($p->canonical)
   <link rel="canonical" href="{{ $p->canonical }}">
+    @if ($p->mOgImage)
+  <meta property="og:title" content="{{! $p->pageTitle !}}">
+  <meta property="og:type" content="{{ $p->mOgType or 'website' }}">
+  <meta property="og:url" content="{{ $p->canonical }}">
+  <meta property="og:image" content="{{ $p->mOgImage }}">
+        @if ($p->mOgImageX)
+  <meta property="og:image:width" content="{{ $p->mOgImageX }}">
+        @endif
+        @if ($p->mOgImageY)
+  <meta property="og:image:height" content="{{ $p->mOgImageY }}">
+        @endif
+        @if ($p->mDescription)
+  <meta property="og:description" content="{{! $p->mDescription !}}">
+        @endif
+  <meta property="og:site_name" content="{{ $p->fTitle }}">
+    @endif
 @endif
 @foreach ($p->pageHeaders as $pageHeader)
     @if ('style' === $pageHeader['type'])