fix: prioritize home seo defaults for openai domains

This commit is contained in:
Your Name
2026-04-18 15:06:34 +08:00
parent 02a65d97ee
commit 2ea87050a5
5 changed files with 183 additions and 12 deletions

View File

@@ -2,6 +2,7 @@
namespace app\services;
use app\common\helper\DomainSeoNamingHelper;
use app\model\ConverterMovel;
use app\model\DomainModel;
use app\model\GanRaoMaModel;
@@ -218,8 +219,16 @@ class SiteContext
View::assign('DomainModel', $this->DomainModel);
View::assign('TemplatesModel', $this->TemplatesModel);
$strSiteName = DomainSeoNamingHelper::normalizeSiteName(
(string)($this->DomainModel->d_name ?? ''),
(string)($this->DomainModel->d_domain ?? '')
);
if ($strSiteName !== '') {
$this->DomainModel->d_name = $strSiteName;
}
ConverterMovel::setVal([
'strSiteName' => $this->DomainModel->d_name,
'strSiteName' => $strSiteName,
'strSiteDomain' => $this->DomainModel->d_domain,
'strSiteKeywords' => $this->DomainModel->d_keywords,
'strSiteDescription' => $this->DomainModel->d_description,
@@ -374,7 +383,10 @@ class SiteContext
public function initHomeTKD()
{
ConverterMovel::setVal([
'strSiteName' => $this->DomainModel->d_name,
'strSiteName' => DomainSeoNamingHelper::normalizeSiteName(
(string)($this->DomainModel->d_name ?? ''),
(string)($this->DomainModel->d_domain ?? '')
),
]);
}
@@ -755,14 +767,17 @@ class SiteContext
$arrCandidates = [];
// 1. 新 GPT SEO 池
$arrCandidates[] = $this->renderSeoFromPool($strCode, $strPage);
// 2. 旧 SubjectFomart key 兼容层
$arrCandidates[] = $this->renderSeoFromLegacyKey($strCode, $strPage);
// 3. domain 表兜底
$arrCandidates[] = $this->renderSeoFromDomainRecord($strCode, $strPage);
if ($strPage === 'home') {
// 首页优先吃 domain 表,避免已导入/AI 生成的首页 TKD 被旧标题池覆盖。
$arrCandidates[] = $this->renderSeoFromDomainRecord($strCode, $strPage);
$arrCandidates[] = $this->renderSeoFromPool($strCode, $strPage);
$arrCandidates[] = $this->renderSeoFromLegacyKey($strCode, $strPage);
} else {
// 其它页面仍保持“新池优先,旧逻辑兜底”的兼容顺序。
$arrCandidates[] = $this->renderSeoFromPool($strCode, $strPage);
$arrCandidates[] = $this->renderSeoFromLegacyKey($strCode, $strPage);
$arrCandidates[] = $this->renderSeoFromDomainRecord($strCode, $strPage);
}
foreach ($arrCandidates as $strCandidate) {
$strCandidate = $this->normalizeSeoText($strCandidate);
@@ -896,6 +911,17 @@ class SiteContext
$strValue = preg_replace('/^[\\s\\-|_,,。;:]+/u', '', $strValue) ?? $strValue;
$strValue = preg_replace('/[\\s\\-|_,,。;:]+$/u', '', $strValue) ?? $strValue;
if ($this->DomainModel instanceof DomainModel) {
$strRawSiteName = trim((string)($this->DomainModel->d_name ?? ''));
$strNormalizedSiteName = DomainSeoNamingHelper::normalizeSiteName(
$strRawSiteName,
(string)($this->DomainModel->d_domain ?? '')
);
if ($strRawSiteName !== '' && $strNormalizedSiteName !== '' && $strRawSiteName !== $strNormalizedSiteName) {
$strValue = str_replace($strRawSiteName, $strNormalizedSiteName, $strValue);
}
}
if ($strValue === '' || preg_match('/^[-|_,,。;:\\s]+$/u', $strValue)) {
return '';
}
@@ -1174,11 +1200,22 @@ class SiteContext
$arrResolvedDomain = DomainModel::resolveDomainContextByHost($strHost);
$RuntimeDomainModel = $arrResolvedDomain['runtime'] ?? null;
if ($RuntimeDomainModel instanceof DomainModel) {
$RuntimeDomainModel->d_name = DomainSeoNamingHelper::normalizeSiteName(
(string)($RuntimeDomainModel->d_name ?? ''),
(string)($RuntimeDomainModel->d_domain ?? '')
);
return $RuntimeDomainModel;
}
$strDomain = (string)$this->Request->rootDomain();
return DomainModel::getDomainOnCacheByDomain($strDomain);
$DomainModel = DomainModel::getDomainOnCacheByDomain($strDomain);
if ($DomainModel instanceof DomainModel) {
$DomainModel->d_name = DomainSeoNamingHelper::normalizeSiteName(
(string)($DomainModel->d_name ?? ''),
(string)($DomainModel->d_domain ?? '')
);
}
return $DomainModel;
}
public function getPinlunData(int $intVideoId): array