mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-02 08:13:34 +03:00
9fc9e4311d
closes https://github.com/TryGhost/Team/issues/2206 - removes `www.` from the url shown on links table in post analytics - we had previously removed http(s) protocol from it as well, and they are only shown while editing the url
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
import Service from '@ember/service';
|
|
|
|
export default class UtilsService extends Service {
|
|
downloadFile(url) {
|
|
let iframe = document.getElementById('iframeDownload');
|
|
|
|
if (!iframe) {
|
|
iframe = document.createElement('iframe');
|
|
iframe.id = 'iframeDownload';
|
|
iframe.style.display = 'none';
|
|
document.body.append(iframe);
|
|
}
|
|
|
|
iframe.setAttribute('src', url);
|
|
}
|
|
|
|
/**
|
|
* Remove tracking parameters from a URL
|
|
* @param {string} url
|
|
* @param {boolean} [display] Set to true to remove protocol and hash from the URL
|
|
* @returns
|
|
*/
|
|
cleanTrackedUrl(url, display = false) {
|
|
// Remove our own querystring parameters and protocol
|
|
const removeParams = ['ref', 'attribution_id', 'attribution_type'];
|
|
const urlObj = new URL(url);
|
|
for (const param of removeParams) {
|
|
urlObj.searchParams.delete(param);
|
|
}
|
|
if (!display) {
|
|
return urlObj.toString();
|
|
}
|
|
// Return URL without protocol
|
|
const urlWithoutProtocol = urlObj.host + (urlObj.pathname === '/' && !urlObj.search ? '' : urlObj.pathname) + (urlObj.search ? urlObj.search : '') + (urlObj.hash ? urlObj.hash : '');
|
|
// remove www. from the start of the URL
|
|
return urlWithoutProtocol.replace(/^www\./, '');
|
|
}
|
|
}
|