Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove base url from link control search results #54553

Merged
merged 14 commits into from
Sep 21, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
file,
} from '@wordpress/icons';
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
import { safeDecodeURI, filterURLForDisplay } from '@wordpress/url';
import { safeDecodeURI, filterURLForDisplay, getPath } from '@wordpress/url';

const ICONS_MAP = {
post: postList,
Expand Down Expand Up @@ -52,9 +52,15 @@ export const LinkControlSearchItem = ( {
isURL = false,
shouldShowType = false,
} ) => {
// Remove the site URL from any suggestion that is not a manually entered URL.
// This is to reduce visual noise in the search results.
const suggestionURL = isURL
? suggestion?.url
: '/' + getPath( suggestion?.url ) + '/';

Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
const info = isURL
? __( 'Press ENTER to add this link' )
: filterURLForDisplay( safeDecodeURI( suggestion?.url ), 24 );
: filterURLForDisplay( safeDecodeURI( suggestionURL ), 24 );

return (
<MenuItem
Expand Down
Loading