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
+3 -1
View File
@@ -3,7 +3,9 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>大锤商行</title>
<title>官方租号平台</title>
<!-- 生产请求由后端按 Host 注入租户标题、描述、OG 和图标;此处仅保留通用兜底。 -->
<meta name="site-shell-placeholder" content="1" />
<link id="site-apple-touch-icon" rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link id="site-icon" rel="icon" type="image/png" href="/apple-touch-icon.png" />
<script src="/site-bootstrap.js"></script>
+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'
)
})()
+12 -3
View File
@@ -473,9 +473,18 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
sessionStorage.removeItem('hfb_site_name')
localStorage.removeItem('hfb_site_code')
localStorage.removeItem('hfb_site_name')
document.title = '大锤商行 - 官方租号平台'
this.faviconUrl = siteBrandFor('dachui').favicon
this.applyFavicon()
// 服务端注入或静态 bootstrap 已经给出正确品牌时,不要因为接口失败
// 把经营租户域名回退成主站标题和图标。
const serverInjected =
typeof document !== 'undefined' &&
document.querySelector('meta[name="site-shell"]') !== null
const bootstrapped =
typeof document !== 'undefined' && Boolean(document.documentElement.dataset.siteBootstrap)
if (!serverInjected && !bootstrapped) {
document.title = '大锤商行 - 官方租号平台'
this.faviconUrl = siteBrandFor('dachui').favicon
this.applyFavicon()
}
},
applyTenantContext(info: TenantSiteContext) {