diff --git a/code/app/admin/controller/Site.php b/code/app/admin/controller/Site.php index d7ab80f..2bc1ac9 100644 --- a/code/app/admin/controller/Site.php +++ b/code/app/admin/controller/Site.php @@ -62,6 +62,7 @@ use app\common\helper\DomainExternalSeoCollectorStatusHelper; use app\common\helper\DomainSupplyBatchHelper; use app\common\helper\DomainSupplyRunIndexHelper; use app\common\helper\DomainSupplyBatchTemplateHelper; +use app\common\helper\DomainSeoNamingHelper; use app\common\helper\DomainBootstrapEnvTemplateHelper; use app\common\helper\DomainSpiderCrawlWorkbenchHelper; use app\common\helper\DomainTrajectoryProbeHelper; @@ -1298,6 +1299,28 @@ class Site extends BaseController 'd_seed_scope' => $this->normalizeSeedScope($arrRowAssoc['d_seed_scope'] ?? DomainModel::SEED_SCOPE_DOMAIN), 'd_baidu_token' => $arrRowAssoc['d_baidu_token'] ?? null, ]; + if (DomainSeoNamingHelper::shouldOptimizeForOpenAi($strTkdProvider, $strTkdMode)) { + $arrSeoDefaults = DomainSeoNamingHelper::buildSeoDefaults( + (string)($arrDomain['d_name'] ?? ''), + (string)($arrDomain['d_domain'] ?? ''), + (string)($arrDomain['d_index_title'] ?? ''), + (string)($arrDomain['d_index_keywords'] ?? ''), + (string)($arrDomain['d_index_description'] ?? '') + ); + $arrDomain['d_name'] = $arrSeoDefaults['site_name']; + $arrDomain['d_index_title'] = $arrSeoDefaults['index_title']; + $arrDomain['d_index_keywords'] = $arrSeoDefaults['index_keywords']; + $arrDomain['d_index_description'] = $arrSeoDefaults['index_description']; + if (trim((string)($arrDomain['d_keywords'] ?? '')) === '') { + $arrDomain['d_keywords'] = $arrSeoDefaults['index_keywords']; + } + if (trim((string)($arrDomain['d_description'] ?? '')) === '') { + $arrDomain['d_description'] = $arrSeoDefaults['index_description']; + } + if (trim((string)($arrDomain['d_text_logo'] ?? '')) === '') { + $arrDomain['d_text_logo'] = $arrSeoDefaults['site_name']; + } + } $arrDomain['d_seo_cfg'] = $this->applySeoStrategyProfileForDomainData($arrRowAssoc['d_seo_cfg'] ?? null, $arrDomain, $strStrategyProfile); $arrDomain['d_seo_cfg']['tkd'] = array_merge( (array)($arrDomain['d_seo_cfg']['tkd'] ?? []), diff --git a/code/app/common/helper/DomainBootstrapRegisterHelper.php b/code/app/common/helper/DomainBootstrapRegisterHelper.php index e1e9099..11b0d1c 100644 --- a/code/app/common/helper/DomainBootstrapRegisterHelper.php +++ b/code/app/common/helper/DomainBootstrapRegisterHelper.php @@ -69,6 +69,21 @@ class DomainBootstrapRegisterHelper ? DomainModel::TKD_MODE_AI_OPTIMIZE : ($boolHasImportedHomeTkd ? DomainModel::TKD_MODE_FORCE_IMPORT : DomainModel::TKD_MODE_AUTO_GENERATE); } + if (DomainSeoNamingHelper::shouldOptimizeForOpenAi($strTkdProviderNormalized, $strTkdModeInput)) { + $arrSeoDefaults = DomainSeoNamingHelper::buildSeoDefaults( + $strSiteName, + $strDomain, + $strRawIndexTitle, + $strRawIndexKeywords, + $strRawIndexDescription + ); + $strSiteName = $arrSeoDefaults['site_name']; + $strSiteKeywords = trim((string)($arrPayload['d_keywords'] ?? $strSiteName)); + $strSiteDescription = trim((string)($arrPayload['d_description'] ?? ($strSiteName . '内容整理与推荐。'))); + $strIndexTitle = $arrSeoDefaults['index_title']; + $strIndexKeywords = $arrSeoDefaults['index_keywords']; + $strIndexDescription = $arrSeoDefaults['index_description']; + } $arrSeoCfgInput['tkd'] = array_merge( (array)($arrSeoCfgInput['tkd'] ?? []), [ diff --git a/code/app/common/helper/DomainSeoNamingHelper.php b/code/app/common/helper/DomainSeoNamingHelper.php new file mode 100644 index 0000000..2c718c6 --- /dev/null +++ b/code/app/common/helper/DomainSeoNamingHelper.php @@ -0,0 +1,87 @@ + $strSiteName, + 'index_title' => trim($strIndexTitle), + 'index_keywords' => trim($strIndexKeywords), + 'index_description' => trim($strIndexDescription), + ]; + } + + protected static function fallbackNameFromDomain(string $strDomain): string + { + $strDomain = strtolower(trim($strDomain)); + $strDomain = preg_replace('/^https?:\/\//', '', $strDomain) ?: $strDomain; + $strDomain = preg_replace('/^www\./', '', $strDomain) ?: $strDomain; + $strDomain = explode('/', $strDomain)[0] ?? $strDomain; + $strDomain = explode('.', $strDomain)[0] ?? $strDomain; + $strDomain = str_replace(['-', '_'], '', $strDomain); + + return $strDomain !== '' ? $strDomain : '影视站'; + } +} diff --git a/code/app/home/BaseController.php b/code/app/home/BaseController.php index 7c56e31..cdc8e82 100644 --- a/code/app/home/BaseController.php +++ b/code/app/home/BaseController.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace app\home; +use app\common\helper\DomainSeoNamingHelper; use app\model\ConverterMovel; use app\model\GanRaoMaModel; use app\model\CategoryModel; @@ -75,8 +76,16 @@ abstract class BaseController */ private function initSiteTKD() { + $strSiteName = DomainSeoNamingHelper::normalizeSiteName( + (string)($this->request->DomainModel->d_name ?? ''), + (string)($this->request->DomainModel->d_domain ?? '') + ); + if ($strSiteName !== '' && isset($this->request->DomainModel)) { + $this->request->DomainModel->d_name = $strSiteName; + } + ConverterMovel::setVal([ - 'strSiteName' => $this->request->DomainModel->d_name, + 'strSiteName' => $strSiteName, 'strSiteDomain' => $this->request->DomainModel->d_domain, 'strSiteKeywords' => $this->request->DomainModel->d_keywords, 'strSiteDescription' => $this->request->DomainModel->d_description, diff --git a/code/app/services/SiteContext.php b/code/app/services/SiteContext.php index e6b135d..4c5aba2 100644 --- a/code/app/services/SiteContext.php +++ b/code/app/services/SiteContext.php @@ -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