fix: 修复线上管理入口被主题配置覆盖
This commit is contained in:
parent
76b9513d80
commit
52c9caea14
@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@ -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: '管理',
|
||||
},
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user