File size: 1,091 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import { addQueryArgs } from '@wordpress/url';
import type { Site } from '../data/types';
/**
* Returns a user-friendly version of the site's URL.
*
* This not only produces a clean version of the site's domain, but
* also deals with the case of Jetpack multi-sites using subdirectory
* installations.
*/
export function getSiteDisplayUrl( site: Site ) {
return site.URL.replace( 'https://', '' ).replace( 'http://', '' );
}
/**
* Returns the URL for editing the site.
*/
export function getSiteEditUrl( site: Site, isSiteUsingBlockTheme?: boolean ) {
const location = typeof window !== 'undefined' ? window.location : null;
const queryArgs: Record< string, string > = {};
const siteAdminUrl = site.options?.admin_url;
if ( isSiteUsingBlockTheme ) {
if ( location && location.origin !== 'https://wordpress.com' ) {
queryArgs.calypso_origin = location.origin;
}
return addQueryArgs( `${ siteAdminUrl }site-editor.php`, queryArgs );
}
if ( location ) {
queryArgs.return = location.href;
}
return addQueryArgs( `${ siteAdminUrl }customize.php`, queryArgs );
}
|