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

@@ -62,6 +62,7 @@ use app\common\helper\DomainExternalSeoCollectorStatusHelper;
use app\common\helper\DomainSupplyBatchHelper; use app\common\helper\DomainSupplyBatchHelper;
use app\common\helper\DomainSupplyRunIndexHelper; use app\common\helper\DomainSupplyRunIndexHelper;
use app\common\helper\DomainSupplyBatchTemplateHelper; use app\common\helper\DomainSupplyBatchTemplateHelper;
use app\common\helper\DomainSeoNamingHelper;
use app\common\helper\DomainBootstrapEnvTemplateHelper; use app\common\helper\DomainBootstrapEnvTemplateHelper;
use app\common\helper\DomainSpiderCrawlWorkbenchHelper; use app\common\helper\DomainSpiderCrawlWorkbenchHelper;
use app\common\helper\DomainTrajectoryProbeHelper; 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_seed_scope' => $this->normalizeSeedScope($arrRowAssoc['d_seed_scope'] ?? DomainModel::SEED_SCOPE_DOMAIN),
'd_baidu_token' => $arrRowAssoc['d_baidu_token'] ?? null, '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'] = $this->applySeoStrategyProfileForDomainData($arrRowAssoc['d_seo_cfg'] ?? null, $arrDomain, $strStrategyProfile);
$arrDomain['d_seo_cfg']['tkd'] = array_merge( $arrDomain['d_seo_cfg']['tkd'] = array_merge(
(array)($arrDomain['d_seo_cfg']['tkd'] ?? []), (array)($arrDomain['d_seo_cfg']['tkd'] ?? []),

View File

@@ -69,6 +69,21 @@ class DomainBootstrapRegisterHelper
? DomainModel::TKD_MODE_AI_OPTIMIZE ? DomainModel::TKD_MODE_AI_OPTIMIZE
: ($boolHasImportedHomeTkd ? DomainModel::TKD_MODE_FORCE_IMPORT : DomainModel::TKD_MODE_AUTO_GENERATE); : ($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( $arrSeoCfgInput['tkd'] = array_merge(
(array)($arrSeoCfgInput['tkd'] ?? []), (array)($arrSeoCfgInput['tkd'] ?? []),
[ [

View File

@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace app\common\helper;
use app\model\DomainModel;
class DomainSeoNamingHelper
{
public static function shouldOptimizeForOpenAi(?string $strTkdProvider, ?string $strTkdMode): bool
{
$strProvider = DomainModel::normalizeTkdProvider((string)$strTkdProvider);
$strMode = DomainModel::normalizeTkdMode((string)$strTkdMode);
return $strProvider === DomainModel::TKD_PROVIDER_OPENAI
|| $strMode === DomainModel::TKD_MODE_AI_OPTIMIZE;
}
public static function normalizeSiteName(string $strSiteName, string $strDomain = ''): string
{
$strSiteName = trim($strSiteName);
$strSiteName = preg_replace('/\s+/u', '', $strSiteName) ?: $strSiteName;
$strSiteName = trim($strSiteName, "-_\t\n\r\0\x0B .|");
if ($strSiteName === '') {
$strSiteName = self::fallbackNameFromDomain($strDomain);
}
foreach (['影视网', '电影网', '剧情网', '短剧网', '影视', '影院', '视频', '短剧', '剧情'] as $suffix) {
$quoted = preg_quote($suffix, '/');
$strSiteName = preg_replace('/(' . $quoted . '){2,}$/u', $suffix, $strSiteName) ?: $strSiteName;
}
$strSiteName = preg_replace('/^(.{2,12}?)\1$/u', '$1', $strSiteName) ?: $strSiteName;
$strSiteName = preg_replace('/官网网$/u', '官网', $strSiteName) ?: $strSiteName;
return trim($strSiteName) !== '' ? trim($strSiteName) : self::fallbackNameFromDomain($strDomain);
}
public static function buildSeoDefaults(
string $strSiteName,
string $strDomain = '',
string $strIndexTitle = '',
string $strIndexKeywords = '',
string $strIndexDescription = ''
): array {
$strSiteName = self::normalizeSiteName($strSiteName, $strDomain);
if (trim($strIndexTitle) === '') {
$strIndexTitle = $strSiteName . '-高清影视内容精选-每日更新';
}
if (trim($strIndexKeywords) === '') {
$strIndexKeywords = implode(',', array_values(array_unique(array_filter([
$strSiteName,
'高清影视',
'热播短剧',
'剧情介绍',
'热门推荐',
]))));
}
if (trim($strIndexDescription) === '') {
$strIndexDescription = $strSiteName . '专注于高清影视、热播短剧与剧情内容整理,支持分类浏览、搜索查找和热门推荐,内容持续更新。';
}
return [
'site_name' => $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 : '影视站';
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace app\home; namespace app\home;
use app\common\helper\DomainSeoNamingHelper;
use app\model\ConverterMovel; use app\model\ConverterMovel;
use app\model\GanRaoMaModel; use app\model\GanRaoMaModel;
use app\model\CategoryModel; use app\model\CategoryModel;
@@ -75,8 +76,16 @@ abstract class BaseController
*/ */
private function initSiteTKD() 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([ ConverterMovel::setVal([
'strSiteName' => $this->request->DomainModel->d_name, 'strSiteName' => $strSiteName,
'strSiteDomain' => $this->request->DomainModel->d_domain, 'strSiteDomain' => $this->request->DomainModel->d_domain,
'strSiteKeywords' => $this->request->DomainModel->d_keywords, 'strSiteKeywords' => $this->request->DomainModel->d_keywords,
'strSiteDescription' => $this->request->DomainModel->d_description, 'strSiteDescription' => $this->request->DomainModel->d_description,

View File

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