mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
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:
parent
1645f551bc
commit
9fc9e4311d
@ -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\./, '');
|
||||
}
|
||||
}
|
||||
|
25
ghost/admin/tests/unit/services/utils-test.js
Normal file
25
ghost/admin/tests/unit/services/utils-test.js
Normal 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');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user