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

37 lines
2.3 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-site-style-20261028.png', 'width' => 1962, 'height' => 801, 'alt' => 'DPL:畅连全球网络。日常访问、远程办公、在线娱乐,查看套餐。'],
['key' => 'hn', 'file' => 'hn-ad-refined-20261031.png', 'width' => 1964, 'height' => 801, 'alt' => 'Hardnerd:硬核架构,品质专线,全球网络畅通无阻。'],
['key' => 'fuc', 'file' => 'fuc-ad-site-style-20261028.png', 'width' => 1962, 'height' => 801, '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'] }}(新窗口打开)">
<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">
<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