From 52c9caea14e0667589680c5cd98ae8a18325691e Mon Sep 17 00:00:00 2001 From: sunlei Date: Thu, 16 Jul 2026 11:05:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BA=BF=E4=B8=8A?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=85=A5=E5=8F=A3=E8=A2=AB=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/BlogAdminSso.spec.ts | 15 +++++++++------ src/__tests__/useBlogTheme.spec.ts | 4 ++-- src/factories/blogAdminSsoFactory.ts | 20 +++++++++++++++----- src/hooks/useBlogTheme.ts | 8 ++++---- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/__tests__/BlogAdminSso.spec.ts b/src/__tests__/BlogAdminSso.spec.ts index c622565..95b6121 100644 --- a/src/__tests__/BlogAdminSso.spec.ts +++ b/src/__tests__/BlogAdminSso.spec.ts @@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest' import { BLOG_ADMIN_MANAGEMENT_PATH, buildBlogAdminSsoUrl, - isLegacyWordpressAdminHref, + isLegacyBlogManagementHref, resolveBlogAdminBaseUrl, } from '@/factories/blogAdminSsoFactory' @@ -31,12 +31,15 @@ describe('Blog Admin SSO URL factory', () => { expect(resolveBlogAdminBaseUrl({ PROD: false })).toBe('http://localhost:5999/') }) - it('identifies only legacy WordPress management destinations', () => { - expect(isLegacyWordpressAdminHref('http://blog.kwitsukasa.top/wp-admin/')).toBe(true) - expect(isLegacyWordpressAdminHref('/wp-admin')).toBe(true) - expect(isLegacyWordpressAdminHref('https://blog.kwitsukasa.top/post/wp-admin-migration')).toBe( + it('identifies legacy WordPress and in-site management destinations', () => { + expect(isLegacyBlogManagementHref('http://blog.kwitsukasa.top/wp-admin/')).toBe(true) + expect(isLegacyBlogManagementHref('/wp-admin')).toBe(true) + expect(isLegacyBlogManagementHref('#/admin')).toBe(true) + expect(isLegacyBlogManagementHref('https://blog.kwitsukasa.top/#/admin/settings')).toBe(true) + expect(isLegacyBlogManagementHref('/admin')).toBe(true) + expect(isLegacyBlogManagementHref('https://blog.kwitsukasa.top/post/wp-admin-migration')).toBe( false, ) - expect(isLegacyWordpressAdminHref('https://example.com/manage')).toBe(false) + expect(isLegacyBlogManagementHref('https://example.com/manage')).toBe(false) }) }) diff --git a/src/__tests__/useBlogTheme.spec.ts b/src/__tests__/useBlogTheme.spec.ts index 05a1b1b..4deada4 100644 --- a/src/__tests__/useBlogTheme.spec.ts +++ b/src/__tests__/useBlogTheme.spec.ts @@ -198,13 +198,13 @@ describe('useBlogTheme', () => { expect(siteConfig.value.headerMenuVisible).toBe(true); }); - it('migrates same-site WordPress management without changing unrelated sidebar links', async () => { + it('migrates the remote in-site management route without changing unrelated sidebar links', async () => { const { applyWordpressThemeConfig, siteConfig } = useBlogTheme(); applyWordpressThemeConfig({ sidebarMenu: [ { - href: 'https://blog.kwitsukasa.top/wp-admin/', + href: '#/admin', icon: 'fa-user', label: '管理', }, diff --git a/src/factories/blogAdminSsoFactory.ts b/src/factories/blogAdminSsoFactory.ts index fb9b3a3..e5d6306 100644 --- a/src/factories/blogAdminSsoFactory.ts +++ b/src/factories/blogAdminSsoFactory.ts @@ -46,14 +46,24 @@ export function buildBlogAdminSsoUrl(adminBaseUrl = resolveBlogAdminBaseUrl()) { } /** - * Detects the legacy WordPress dashboard destination that remote Argon theme data may still expose. + * Detects historical Blog management destinations that remote Argon theme data may still expose. * @param href Normalized sidebar destination, absolute or site-relative. - * @returns Whether the destination is the WordPress administration root or one of its descendants. + * @returns Whether the destination is a legacy WordPress or in-site Blog administration route. */ -export function isLegacyWordpressAdminHref(href: string) { +export function isLegacyBlogManagementHref(href: string) { try { - const pathname = new URL(href, 'https://blog.invalid/').pathname.replace(/\/+$/g, '') - return pathname === '/wp-admin' || pathname.startsWith('/wp-admin/') + const url = new URL(href, 'https://blog.invalid/') + const pathname = url.pathname.replace(/\/+$/g, '') + const hashParts = url.hash.replace(/^#/, '').split('?') + const hashPath = (hashParts[0] || '').replace(/\/+$/g, '') + + return [pathname, hashPath].some( + (path) => + path === '/admin' || + path.startsWith('/admin/') || + path === '/wp-admin' || + path.startsWith('/wp-admin/'), + ) } catch { return false } diff --git a/src/hooks/useBlogTheme.ts b/src/hooks/useBlogTheme.ts index aad0229..e591ff1 100644 --- a/src/hooks/useBlogTheme.ts +++ b/src/hooks/useBlogTheme.ts @@ -12,7 +12,7 @@ import { import { createBlogMotionCssVariables } from '@/factories/blogAnimationFactory'; import { buildBlogAdminSsoUrl, - isLegacyWordpressAdminHref, + isLegacyBlogManagementHref, } from '@/factories/blogAdminSsoFactory'; import { BLOG_META_NAMES, blogDomId, blogDomSelector, blogMetaSelector } from '@/factories/blogDomFactory'; @@ -1019,17 +1019,17 @@ function normalizeMenuItems(items: BlogThemeMenuItem[], siteHome = ''): BlogThem } /** - * Normalizes sidebar items and migrates the legacy WordPress dashboard entry to KT Admin SSO. + * Normalizes sidebar items and migrates historical management entries to KT Admin SSO. * @param items Raw sidebar items supplied by the Blog theme API. * @param siteHome Public Blog home URL used to collapse same-site links into RouterLink paths. - * @returns Sidebar items with only the legacy management destination replaced by an external SSO URL. + * @returns Sidebar items with only historical management destinations replaced by an external SSO URL. */ function normalizeSidebarMenuItems( items: BlogThemeMenuItem[], siteHome = '', ): BlogThemeMenuItem[] { return normalizeMenuItems(items, siteHome).map((item) => - isLegacyWordpressAdminHref(item.href) + isLegacyBlogManagementHref(item.href) ? { ...item, external: true,