Skip to content

Commit

Permalink
Show full link in preview except site URL for better understanding
Browse files Browse the repository at this point in the history
  • Loading branch information
AKSHAT2802 committed Nov 19, 2024
1 parent c772226 commit b132747
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/editor/src/components/post-url/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useMemo, useState } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { Dropdown, Button, ExternalLink } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { safeDecodeURIComponent } from '@wordpress/url';
import { store as coreStore } from '@wordpress/core-data';

/**
Expand Down Expand Up @@ -81,12 +80,21 @@ export default function PostURLPanel() {
}

function PostURLToggle( { isOpen, onClick } ) {
const { slug } = useSelect( ( select ) => {
const { permalink, homeUrl } = useSelect( ( select ) => {
const { getPermalink } = select( editorStore );
const { getEditedEntityRecord } = select( coreStore );
const siteSettings = getEditedEntityRecord( 'root', 'site' );

return {
slug: select( editorStore ).getEditedPostSlug(),
permalink: getPermalink(),
homeUrl: siteSettings?.url || '',
};
}, [] );
const decodedSlug = safeDecodeURIComponent( slug );

const croppedPermalink = permalink?.startsWith( homeUrl )
? permalink.slice( homeUrl.length )
: permalink;

return (
<Button
size="compact"
Expand All @@ -95,11 +103,11 @@ function PostURLToggle( { isOpen, onClick } ) {
aria-expanded={ isOpen }
aria-label={
// translators: %s: Current post link.
sprintf( __( 'Change link: %s' ), decodedSlug )
sprintf( __( 'Change link: %s' ), croppedPermalink || '' )
}
onClick={ onClick }
>
<>{ decodedSlug }</>
{ croppedPermalink }
</Button>
);
}
Expand Down

0 comments on commit b132747

Please sign in to comment.