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

@@ -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'] ?? []),
[

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 : '影视站';
}
}