fn_b/resources/views/components/article-ads.blade.php

39 lines
2.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@php
$adChoices = collect([
['key' => 'dpl', 'file' => 'dpl-ad-compact-wordmark-20261031.png', 'width' => 2169, 'height' => 725, 'alt' => 'DP-LINK.NET:畅连全球网络。日常访问、远程办公、在线娱乐,查看套餐。'],
['key' => 'hn', 'file' => 'hn-ad-compact-lowercase-20261031.png', 'width' => 2021, 'height' => 778, 'alt' => 'hardnerd:硬核架构,品质专线,全球网络畅通无阻。'],
['key' => 'fuc', 'file' => 'fuc-ad-compact-five-years-20261031.png', 'width' => 2141, 'height' => 734, 'alt' => '福云:全球网络加速。五年稳定运营。开始使用。'],
])->filter(fn ($ad) => config('advertising.'.$ad['key'].'.enabled')
&& config('advertising.'.$ad['key'].'.url')
&& is_file(public_path('images/ads/'.$ad['file'])))->values();
@endphp
@if ($adChoices->isNotEmpty())
@once
@push('styles')
<link rel="stylesheet" href="/css/random-article-ad.css?v={{ filemtime(public_path('css/random-article-ad.css')) }}">
@endpush
@endonce
<aside class="random-article-ad" data-random-article-ad aria-label="网络服务广告" hidden>
@foreach ($adChoices as $ad)
<template data-ad-choice="{{ $ad['key'] }}">
<a href="{{ config('advertising.'.$ad['key'].'.url') }}" target="_blank" rel="sponsored noopener noreferrer" aria-label="广告:{{ $ad['alt'] }}(新窗口打开)">
<span class="random-article-ad__disclosure" aria-hidden="true">广告</span>
<img src="/images/ads/{{ $ad['file'] }}?v={{ filemtime(public_path('images/ads/'.$ad['file'])) }}" alt="{{ $ad['alt'] }}" width="{{ $ad['width'] }}" height="{{ $ad['height'] }}" decoding="async">
</a>
</template>
@endforeach
</aside>
<noscript>
@php($ad = $adChoices->first())
<aside class="random-article-ad" aria-label="网络服务广告">
<a href="{{ config('advertising.'.$ad['key'].'.url') }}" target="_blank" rel="sponsored noopener noreferrer">
<span class="random-article-ad__disclosure" aria-hidden="true">广告</span>
<img src="/images/ads/{{ $ad['file'] }}?v={{ filemtime(public_path('images/ads/'.$ad['file'])) }}" alt="{{ $ad['alt'] }}" width="{{ $ad['width'] }}" height="{{ $ad['height'] }}">
</a>
</aside>
</noscript>
@once
<script>{!! file_get_contents(public_path('js/random-article-ad.js')) !!}</script>
@endonce
@endif