Browse Source

Add a description meta tag, while common to all pages

Visman 2 years ago
parent
commit
1057701d0c

+ 2 - 0
app/Models/Page.php

@@ -69,6 +69,8 @@ abstract class Page extends Model
         $this->fDescription = $container->config->o_board_desc;
         $this->fRootLink    = $container->Router->link('Index');
 
+        $this->mDescription = $this->c->config->s_meta_desc;
+
         if (1 === $container->config->b_announcement) {
             $this->fAnnounce = $container->config->o_announcement_message;
         }

+ 1 - 0
app/Models/Pages/Admin/Install.php

@@ -1581,6 +1581,7 @@ class Install extends Admin
             'i_search_ttl'            => 900,
             'b_ant_hidden_ch'         => 1,
             'b_ant_use_js'            => 0,
+            's_meta_desc'             => '',
         ];
 
         foreach ($forkConfig as $name => $value) {

+ 8 - 0
app/Models/Pages/Admin/Options.php

@@ -43,6 +43,7 @@ class Options extends Admin
                     'token'                   => 'token:AdminOptions',
                     'o_board_title'           => 'required|string:trim|max:255',
                     'o_board_desc'            => 'exist|string:trim,empty|max:65000 bytes|html',
+                    's_meta_desc'             => 'exist|string:trim,empty|max:255',
                     'o_default_timezone'      => [
                         'required',
                         'string:trim',
@@ -236,6 +237,13 @@ class Options extends Admin
                     'caption' => 'Board desc label',
                     'help'    => 'Board desc help',
                 ],
+                's_meta_desc' => [
+                    'type'      => 'text',
+                    'maxlength' => '255',
+                    'value'     => $config->s_meta_desc,
+                    'caption'   => 'Meta desc label',
+                    'help'      => 'Meta desc help',
+                ],
                 'o_default_timezone' => [
                     'type'    => 'select',
                     'options' => $this->createTimeZoneOptions(),

+ 14 - 0
app/Models/Pages/Admin/Update.php

@@ -871,4 +871,18 @@ class Update extends Admin
 
         return null;
     }
+
+    /**
+     * rev.67 to rev.68
+     */
+    protected function stageNumber67(array $args): ?int
+    {
+        $config = $this->c->config;
+
+        $config->s_meta_desc ??= '';
+
+        $config->save();
+
+        return null;
+    }
 }

+ 6 - 0
app/lang/en/admin_options.po

@@ -446,3 +446,9 @@ msgstr "Search cache lifetime"
 
 msgid "Search cache lifetime help"
 msgstr "Search query caching time in seconds."
+
+msgid "Meta desc label"
+msgstr "Meta tag <i>description</i>"
+
+msgid "Meta desc help"
+msgstr "This meta tag can be used by search engines to form a snippet that is displayed in the search results."

+ 6 - 0
app/lang/ru/admin_options.po

@@ -446,3 +446,9 @@ msgstr "Время жизни кеша поиска"
 
 msgid "Search cache lifetime help"
 msgstr "Время кэширования поисковых запросов в секундах."
+
+msgid "Meta desc label"
+msgstr "Мета-тег <i>description</i>"
+
+msgid "Meta desc help"
+msgstr "Данный мета-тег может быть использован поисковыми системами для формирования сниппета, который отображается в результатах поисковой выдачи."

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

@@ -4,6 +4,9 @@
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>{{! $p->pageTitle !}}</title>
+@if ($p->mDescription)
+  <meta name="description" content="{{ $p->mDescription }}">
+@endif
 @foreach ($p->pageHeaders as $pageHeader)
     @if ('style' === $pageHeader['type'])
   <style>{!! $pageHeader['values'][0] !!}</style>

+ 4 - 1
app/templates/layouts/redirect.forkbb.php

@@ -4,7 +4,10 @@
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta http-equiv="refresh" content="{{ $p->timeout }}; URL={{ $p->link }}">
-  <title>{!! \htmlspecialchars($p->pageTitle, \ENT_HTML5 | \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8', false) !!}</title>
+  <title>{{! $p->pageTitle !}}</title>
+@if ($p->mDescription)
+  <meta name="description" content="{{ $p->mDescription }}">
+@endif
 @foreach ($p->pageHeaders as $pageHeader)
     @if ('style' === $pageHeader['type'])
   <style>{!! $pageHeader['values'][0] !!}</style>