| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- {{--
- Partial: мета-теги в <head> — Open Graph, Twitter Card, Яндекс.Метрика, Google Analytics.
- Подключается из layouts/app.blade.php внутри <head>.
- Переменная $siteSettings: Collection/array из Setting::all() (через ViewComposer).
- Приоритеты OG-данных:
- og:title → @section('og_title') | @section('title') | og_site_name
- og:description → @section('og_description') | og_description из настроек
- og:image → @section('og_image') | og_image из настроек
- og:url → request()->url() (без query-string)
- --}}
- @php
- // ── Вспомогательная функция для получения значения Blade-секции как строки ──
- // $__env->yieldContent() возвращает строку, если секция определена в дочернем шаблоне.
- $ss = is_array($siteSettings) ? $siteSettings : $siteSettings->toArray();
- // og:title — берём секцию og_title, иначе title, иначе название сайта
- $ogTitle = trim($__env->yieldContent('og_title', ''))
- ?: trim(strip_tags($__env->yieldContent('title', '')))
- ?: ($ss['og_site_name'] ?? config('app.name', 'Точка'));
- // og:description
- $ogDesc = trim($__env->yieldContent('og_description', ''))
- ?: ($ss['og_description'] ?? '');
- // og:image — секция может содержать абсолютный URL (от car-страницы)
- $ogImageRaw = trim($__env->yieldContent('og_image', ''))
- ?: ($ss['og_image'] ?? '');
- $ogImageUrl = $ogImageRaw
- ? (str_starts_with($ogImageRaw, 'http') ? $ogImageRaw : asset($ogImageRaw))
- : '';
- // og:url
- $ogUrl = request()->url();
- // og:locale и og:site_name из настроек
- $ogLocale = $ss['og_locale'] ?? 'ru_RU';
- $ogSiteName = $ss['og_site_name'] ?? config('app.name', 'Точка');
- // og:type — может быть переопределён страницей через @section('og_type')
- $ogType = trim($__env->yieldContent('og_type', '')) ?: 'website';
- // Аналитика
- $ymId = trim($ss['yandex_metrika'] ?? '');
- $gaId = trim($ss['google_analytics'] ?? '');
- @endphp
- {{-- ──────────────── NOINDEX (если включено в настройках) ──────────────── --}}
- @if(($ss['site_noindex'] ?? '0') === '1')
- <meta name="robots" content="noindex, nofollow"/>
- @endif
- {{-- ──────────────── OPEN GRAPH ──────────────── --}}
- <meta property="og:type" content="{{ $ogType }}"/>
- <meta property="og:locale" content="{{ $ogLocale }}"/>
- <meta property="og:site_name" content="{{ $ogSiteName }}"/>
- <meta property="og:url" content="{{ $ogUrl }}"/>
- @if($ogTitle)
- <meta property="og:title" content="{{ $ogTitle }}"/>
- @endif
- @if($ogDesc)
- <meta property="og:description" content="{{ $ogDesc }}"/>
- @endif
- @if($ogImageUrl)
- <meta property="og:image" content="{{ $ogImageUrl }}"/>
- <meta property="og:image:width" content="1200"/>
- <meta property="og:image:height" content="630"/>
- <meta property="og:image:alt" content="{{ $ogTitle }}"/>
- @endif
- {{-- ──────────────── TWITTER / X CARD ──────────────── --}}
- <meta name="twitter:card" content="summary_large_image"/>
- @if($ogTitle)
- <meta name="twitter:title" content="{{ $ogTitle }}"/>
- @endif
- @if($ogDesc)
- <meta name="twitter:description" content="{{ $ogDesc }}"/>
- @endif
- @if($ogImageUrl)
- <meta name="twitter:image" content="{{ $ogImageUrl }}"/>
- @endif
- {{-- ──────────────── ЯНДЕКС.МЕТРИКА ──────────────── --}}
- @if($ymId)
- <script type="text/javascript">
- (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
- m[i].l=1*new Date();
- for(var j=0;j<document.scripts.length;j++){if(document.scripts[j].src===r){return;}}
- k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
- (window,document,"script","https://mc.yandex.ru/metrika/tag.js","ym");
- ym({{ $ymId }},"init",{clickmap:true,trackLinks:true,accurateTrackBounce:true,webvisor:true});
- </script>
- <noscript><div><img src="https://mc.yandex.ru/watch/{{ $ymId }}" style="position:absolute;left:-9999px" alt=""/></div></noscript>
- @endif
- {{-- ──────────────── GOOGLE ANALYTICS (GA4) ──────────────── --}}
- @if($gaId)
- <script async src="https://www.googletagmanager.com/gtag/js?id={{ $gaId }}"></script>
- <script>
- window.dataLayer=window.dataLayer||[];
- function gtag(){dataLayer.push(arguments);}
- gtag('js',new Date());
- gtag('config','{{ $gaId }}');
- </script>
- @endif
|