fix(site): 按 Host 注入租户标题与 SEO 信息

This commit is contained in:
2026-11-19 16:54:50 +08:00
parent e80a461182
commit 3492ecbe9b
12 changed files with 969 additions and 28 deletions
+25 -9
View File
@@ -1,6 +1,10 @@
/* global document, URLSearchParams, window */
(() => {
;(() => {
// 生产 HTML 已由后端按 Host 注入 title/meta/icon;已注入时不要重复覆盖。
// 这里仅作为静态兜底,兼容缓存中的旧 HTML 和尚未接入后端注入的域名。
if (document.querySelector('meta[name="site-shell"]')) return
const host = window.location.hostname.toLowerCase()
const params = new URLSearchParams(window.location.search)
const tenantHint = (params.get('tenant_code') || params.get('tenant') || '').toLowerCase()
@@ -12,13 +16,25 @@
if (!isJieyou) return
document.title = '解忧商行 - 官方租号平台'
const icon = document.getElementById('site-icon')
if (icon) {
icon.href = '/jieyou-favicon.svg'
icon.type = 'image/svg+xml'
}
const appleIcon = document.getElementById('site-apple-touch-icon')
if (appleIcon) {
appleIcon.href = '/jieyou-apple-touch-icon.png'
document.documentElement.dataset.siteBootstrap = 'jieyou'
function applyIcon(id, rel, href, type) {
let link = document.getElementById(id)
if (!link) {
link = document.createElement('link')
link.id = id
link.rel = rel
document.head.appendChild(link)
}
link.href = href
if (type) link.type = type
}
applyIcon('site-icon', 'icon', '/jieyou-favicon.svg', 'image/svg+xml')
applyIcon(
'site-apple-touch-icon',
'apple-touch-icon',
'/jieyou-apple-touch-icon.png',
'image/png'
)
})()