You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.7 KiB

@php
use App\Models\Competition;
use Illuminate\Support\Facades\File;
$slug = 'hsxt';
try {
$resolved = Competition::query()
->whereIn('status', ['published', 'signup_open', 'signup_closed', 'reviewing'])
->orderBy('id')
->value('slug');
if (! is_string($resolved) || trim($resolved) === '') {
$resolved = Competition::query()->orderBy('id')->value('slug');
}
if (is_string($resolved) && trim($resolved) !== '') {
$slug = trim($resolved);
}
} catch (Throwable) {
// 测试环境可能尚未建 competitions 表,回退默认 slug
}
// 生产 SPA base 为 /admin/(与 ChannelEntryController、Vite BASE_URL 一致)
// 资源用根相对路径,避免 APP_URL 写成 https 后证书无效导致图片/样式全部加载失败。
$participantLoginUrl = '/admin/c/'.rawurlencode($slug).'/login';
$audienceLoginUrl = '/admin/c/'.rawurlencode($slug).'/audience/login';
$homeUrl = '/';
$homeEnUrl = '/en';
$participantLoginEnUrl = '/admin/c/'.rawurlencode($slug).'/login?lang=en';
$audienceLoginEnUrl = '/admin/c/'.rawurlencode($slug).'/audience/login?lang=en';
$eventSiteRelative = $eventSiteRelative ?? 'frontend/event-site.html';
$eventSitePath = public_path($eventSiteRelative);
abort_unless(File::isFile($eventSitePath), 503, '赛事官网原型 '.$eventSiteRelative.' 不存在');
$html = File::get($eventSitePath);
$assetBase = '/frontend/assets';
$html = str_replace(
[
'url("assets/',
"url('assets/",
'src="assets/',
"src='assets/",
'data-src="assets/',
"data-src='assets/",
'srcset="assets/',
"srcset='assets/",
'href="assets/',
"href='assets/",
'href="event-site-en.html"',
"href='event-site-en.html'",
'href="event-site.html"',
"href='event-site.html'",
'href="login.html"',
"href='login.html'",
'href="prototype/login-en.html?role=user"',
"href='prototype/login-en.html?role=user'",
'href="prototype/login-en.html?role=audience"',
"href='prototype/login-en.html?role=audience'",
'href="login-en.html?role=user"',
"href='login-en.html?role=user'",
'href="login-en.html?role=audience"',
"href='login-en.html?role=audience'",
'href="layout.html?role=user&lang=en"',
"href='layout.html?role=user&lang=en'",
'href="layout.html?role=audience&lang=en"',
"href='layout.html?role=audience&lang=en'",
'href="layout.html?role=user&lang=en"',
"href='layout.html?role=user&lang=en'",
'href="layout.html?role=audience&lang=en"',
"href='layout.html?role=audience&lang=en'",
'href="layout.html?role=audience"',
"href='layout.html?role=audience'",
],
[
'url("'.$assetBase.'/',
"url('".$assetBase.'/',
'src="'.$assetBase.'/',
"src='".$assetBase.'/',
'data-src="'.$assetBase.'/',
"data-src='".$assetBase.'/',
'srcset="'.$assetBase.'/',
"srcset='".$assetBase.'/',
'href="'.$assetBase.'/',
"href='".$assetBase.'/',
'href="'.$homeEnUrl.'"',
"href='".$homeEnUrl."'",
'href="'.$homeUrl.'"',
"href='".$homeUrl."'",
'href="'.$participantLoginUrl.'"',
"href='".$participantLoginUrl."'",
'href="'.$participantLoginEnUrl.'"',
"href='".$participantLoginEnUrl."'",
'href="'.$audienceLoginEnUrl.'"',
"href='".$audienceLoginEnUrl."'",
'href="'.$participantLoginEnUrl.'"',
"href='".$participantLoginEnUrl."'",
'href="'.$audienceLoginEnUrl.'"',
"href='".$audienceLoginEnUrl."'",
'href="'.$participantLoginEnUrl.'"',
"href='".$participantLoginEnUrl."'",
'href="'.$audienceLoginEnUrl.'"',
"href='".$audienceLoginEnUrl."'",
'href="'.$participantLoginEnUrl.'"',
"href='".$participantLoginEnUrl."'",
'href="'.$audienceLoginEnUrl.'"',
"href='".$audienceLoginEnUrl."'",
'href="'.$audienceLoginUrl.'"',
"href='".$audienceLoginUrl."'",
],
$html
);
if (! empty($publicSourceCode)) {
$script = '<script>try{localStorage.setItem("cxxfds_public_source_code",'.json_encode((string) $publicSourceCode, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES).');localStorage.setItem("cxxfds_public_source_checked_at",String(Date.now()));}catch(e){}</script>';
$html = preg_replace('/<\/head>/i', $script."\n</head>", $html, 1) ?? ($html.$script);
}
@endphp
{!! $html !!}