fix: 修复线上管理入口被主题配置覆盖
This commit is contained in:
parent
76b9513d80
commit
52c9caea14
@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest'
|
|||||||
import {
|
import {
|
||||||
BLOG_ADMIN_MANAGEMENT_PATH,
|
BLOG_ADMIN_MANAGEMENT_PATH,
|
||||||
buildBlogAdminSsoUrl,
|
buildBlogAdminSsoUrl,
|
||||||
isLegacyWordpressAdminHref,
|
isLegacyBlogManagementHref,
|
||||||
resolveBlogAdminBaseUrl,
|
resolveBlogAdminBaseUrl,
|
||||||
} from '@/factories/blogAdminSsoFactory'
|
} from '@/factories/blogAdminSsoFactory'
|
||||||
|
|
||||||
@ -31,12 +31,15 @@ describe('Blog Admin SSO URL factory', () => {
|
|||||||
expect(resolveBlogAdminBaseUrl({ PROD: false })).toBe('http://localhost:5999/')
|
expect(resolveBlogAdminBaseUrl({ PROD: false })).toBe('http://localhost:5999/')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('identifies only legacy WordPress management destinations', () => {
|
it('identifies legacy WordPress and in-site management destinations', () => {
|
||||||
expect(isLegacyWordpressAdminHref('http://blog.kwitsukasa.top/wp-admin/')).toBe(true)
|
expect(isLegacyBlogManagementHref('http://blog.kwitsukasa.top/wp-admin/')).toBe(true)
|
||||||
expect(isLegacyWordpressAdminHref('/wp-admin')).toBe(true)
|
expect(isLegacyBlogManagementHref('/wp-admin')).toBe(true)
|
||||||
expect(isLegacyWordpressAdminHref('https://blog.kwitsukasa.top/post/wp-admin-migration')).toBe(
|
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,
|
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);
|
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();
|
const { applyWordpressThemeConfig, siteConfig } = useBlogTheme();
|
||||||
|
|
||||||
applyWordpressThemeConfig({
|
applyWordpressThemeConfig({
|
||||||
sidebarMenu: [
|
sidebarMenu: [
|
||||||
{
|
{
|
||||||
href: 'https://blog.kwitsukasa.top/wp-admin/',
|
href: '#/admin',
|
||||||
icon: 'fa-user',
|
icon: 'fa-user',
|
||||||
label: '管理',
|
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.
|
* @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 {
|
try {
|
||||||
const pathname = new URL(href, 'https://blog.invalid/').pathname.replace(/\/+$/g, '')
|
const url = new URL(href, 'https://blog.invalid/')
|
||||||
return pathname === '/wp-admin' || pathname.startsWith('/wp-admin/')
|
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 {
|
} catch {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import {
|
|||||||
import { createBlogMotionCssVariables } from '@/factories/blogAnimationFactory';
|
import { createBlogMotionCssVariables } from '@/factories/blogAnimationFactory';
|
||||||
import {
|
import {
|
||||||
buildBlogAdminSsoUrl,
|
buildBlogAdminSsoUrl,
|
||||||
isLegacyWordpressAdminHref,
|
isLegacyBlogManagementHref,
|
||||||
} from '@/factories/blogAdminSsoFactory';
|
} from '@/factories/blogAdminSsoFactory';
|
||||||
import { BLOG_META_NAMES, blogDomId, blogDomSelector, blogMetaSelector } from '@/factories/blogDomFactory';
|
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 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.
|
* @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(
|
function normalizeSidebarMenuItems(
|
||||||
items: BlogThemeMenuItem[],
|
items: BlogThemeMenuItem[],
|
||||||
siteHome = '',
|
siteHome = '',
|
||||||
): BlogThemeMenuItem[] {
|
): BlogThemeMenuItem[] {
|
||||||
return normalizeMenuItems(items, siteHome).map((item) =>
|
return normalizeMenuItems(items, siteHome).map((item) =>
|
||||||
isLegacyWordpressAdminHref(item.href)
|
isLegacyBlogManagementHref(item.href)
|
||||||
? {
|
? {
|
||||||
...item,
|
...item,
|
||||||
external: true,
|
external: true,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user