Removed www prefix from newsletter link table

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
This commit is contained in:
Rishabh 2023-01-13 15:38:54 +05:30
parent 1645f551bc
commit 9fc9e4311d
2 changed files with 30 additions and 3 deletions

View File

@ -16,9 +16,9 @@ export default class UtilsService extends Service {
/**
* Remove tracking parameters from a URL
* @param {string} url
* @param {string} url
* @param {boolean} [display] Set to true to remove protocol and hash from the URL
* @returns
* @returns
*/
cleanTrackedUrl(url, display = false) {
// Remove our own querystring parameters and protocol
@ -31,6 +31,8 @@ export default class UtilsService extends Service {
return urlObj.toString();
}
// Return URL without protocol
return urlObj.host + (urlObj.pathname === '/' && !urlObj.search ? '' : urlObj.pathname) + (urlObj.search ? urlObj.search : '') + (urlObj.hash ? urlObj.hash : '');
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\./, '');
}
}

View File

@ -0,0 +1,25 @@
import {describe, it} from 'mocha'; import {expect} from 'chai';
import {setupTest} from 'ember-mocha';
describe('Unit: Service: utils', function () {
setupTest();
describe('cleanTrackedUrl', function () {
let utilsService;
beforeEach(function () {
utilsService = this.owner.lookup('service:utils');
});
it('removes protocol and www from url if display is true', function () {
const url = 'https://www.ghost.org';
const output = utilsService.cleanTrackedUrl(url, true);
expect(output).to.be('ghost.org');
});
it('removes tracking params from the url', function () {
const url = 'https://www.ghost.org?ref=123&attribution_id=something&attribution_type=something&leave=123';
const output = utilsService.cleanTrackedUrl(url, false);
expect(output).to.be('https://www.ghost.org?leave=123');
});
});
});