| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import { safeParseJson } from '@shared/lib/parsing'; |
| 2 | +import { siteHost } from '@shared/lib/site-host'; | |
| 2 | 3 | import apiFetch from '@wordpress/api-fetch'; |
| 3 | 4 | import { decodeEntities } from '@wordpress/html-entities'; |
| 4 | 5 | |
| 5 | 6 | const { hostname } = window.location; |
| @@ -76,16 +77,21 @@ | ||
| 76 | 77 | * The domainSearchUrl may contain both {SLD} and {TLD} placeholders |
| 77 | 78 | * e.g., https://example.com?sld={SLD}&tld={TLD} |
| 78 | 79 | * If not present, fallback to {DOMAIN} format |
| 79 | 80 | */ |
| 80 | -export const createDomainUrlLink = (domainSearchUrl, domain) => { | |
| 81 | - if (domainSearchUrl.includes('{SLD}') && domainSearchUrl.includes('{TLD}')) { | |
| 81 | +export const createDomainUrlLink = ( | |
| 82 | + domainSearchUrl, | |
| 83 | + domain, | |
| 84 | + host = siteHost(), | |
| 85 | +) => { | |
| 86 | + const url = domainSearchUrl.replaceAll('{SITEURL}', host); | |
| 87 | + if (url.includes('{SLD}') && url.includes('{TLD}')) { | |
| 82 | 88 | const parts = domain.toLowerCase().split('.'); |
| 83 | 89 | const sld = parts[0]; |
| 84 | 90 | const tld = parts.slice(1).join('.'); |
| 85 | - return domainSearchUrl.replace('{SLD}', sld).replace('{TLD}', `.${tld}`); | |
| 91 | + return url.replace('{SLD}', sld).replace('{TLD}', `.${tld}`); | |
| 86 | 92 | } |
| 87 | - return domainSearchUrl.replace('{DOMAIN}', domain.toLowerCase()); | |
| 93 | + return url.replace('{DOMAIN}', domain.toLowerCase()); | |
| 88 | 94 | }; |
| 89 | 95 | |
| 90 | 96 | export const deleteDomainCache = () => |
| 91 | 97 | apiFetch({ |