Skip to content

Commit

Permalink
GP: Duplicate meta descriptions (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
xbpcb authored Jan 2, 2025
1 parent 5d8c12c commit a4b2e85
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 69 deletions.
38 changes: 32 additions & 6 deletions src/routes/globalping.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,48 @@ koaElasticUtils.addRoutes(router, [
* Network tools pages.
*/
koaElasticUtils.addRoutes(router, [
[ '/network-tools', '/network-tools/:params' ],
[ '/network-tools', '/network-tools/:params?' ],
], async (ctx) => {
let data = {
params: ctx.params.params || '',
};
let data;
let newPath;
let { params = '' } = ctx.params;
let splitPoint = '-from-';
let splitPointIdx = params.indexOf(splitPoint);
let [ testType, target ] = splitPointIdx === -1
? params.split(splitPoint)
: [ params.slice(0, splitPointIdx), params.slice(splitPointIdx + splitPoint.length) ];
let allowedTestTypes = [ 'ping', 'dns', 'mtr', 'http', 'traceroute' ];
let isTestTypeValid = allowedTestTypes.includes(testType);

try {
// check if test type is correct
if (isTestTypeValid) {
if (!target) {
newPath = `${testType}-from-world`;

throw new Error(`Redirecting to ${newPath}!`);
}

data = {
params: ctx.params.params || '',
};
} else {
// redirect conserving the target or just to default ping-from-world test page
newPath = target ? `ping-from-${target.toLowerCase()}` : 'ping-from-world';

throw new Error(`Measurement type ${testType} is incorrect! Redirecting to ${newPath}!`);
}

ctx.body = await ctx.render('pages/globalping/network-tools.html', data);
ctx.maxAge = 5 * 60;
} catch (e) {
if (app.env === 'development') {
if (ctx.app.env === 'development') {
console.error(e);
}

ctx.status = 301;
return ctx.redirect('/');

return ctx.redirect(`/network-tools/${newPath}`);
}
});

Expand Down
1 change: 1 addition & 0 deletions src/views/pages/globalping/docs/api.globalping.io.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
data () {
return {
title: 'Globalping API',
description: 'Use the Globalping API to access thousands of global probes and build your own tools and integrations.',
};
},
computed: {
Expand Down
1 change: 1 addition & 0 deletions src/views/pages/globalping/docs/auth.globalping.io.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
data () {
return {
title: 'Globalping Authentication API',
description: 'Authenticate your Globalping integrations using our OAuth API for the best user flow.',
};
},
computed: {
Expand Down
107 changes: 45 additions & 62 deletions src/views/pages/globalping/network-tools.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ <h1>{{displayingTestType}} from {{#if locationData.probesCnt}}multiple locations

<span>test</span>
</div>
{{elseif placeholerLocation}}
{{elseif rawLocationToDisplay}}
<h1>{{displayingTestType}} from multiple locations in </h1>
<span class="gp-nettools_main-info_content_temp-location">
{{#if placeholerLocation.toLowerCase() !== 'world'}}
{{placeholerLocation}},
{{#if rawLocationToDisplay.toLowerCase() !== 'world'}}
{{rawLocationToDisplay}},
{{/if}}

<a target="_blank" rel="noopener noreferrer" href="{{global.location.origin}}/network-tools/{{selectedTestType}}-from-world" class="gp-nettools_green-text">
Expand Down Expand Up @@ -277,15 +277,30 @@ <h1>{{displayingTestType}} from multiple locations in </h1>
probesParsed: false,
testReqParams: null,
rawLocation: null,
rawLocationToDisplay: null,
allRequiredDataReady: false,
};
},
onconfig () {
if (!Ractive.isServer) {
let title, description;
let { rawTestType, rawLocation, rawLocationToDisplay } = this.getInitialRawDataFromUrl();

// create temp title, descr before any checks, required by GA
title = this.createMetaTitle(rawTestType, rawLocationToDisplay);
description = this.createMetaDescr(rawTestType, rawLocationToDisplay);

this.set('title', title);
this.set('description', description);
this.set('selectedTestType', rawTestType);
this.set('rawLocation', rawLocation);
this.set('rawLocationToDisplay', rawLocationToDisplay);
}
},
oninit () {
if (!Ractive.isServer) {
this.getGlobalpingProbesData();

this.getParamsFromUrl();

this.observe('selectedTestType', (selectedTestType) => {
if (selectedTestType) {
switch (selectedTestType.toLowerCase()) {
Expand Down Expand Up @@ -356,7 +371,7 @@ <h1>{{displayingTestType}} from multiple locations in </h1>
let rawLocation = this.get('rawLocation');

// handle locationData, highLevelLocationHref
if (rawLocation && rawLocation !== 'world') {
if (rawLocation && rawLocation.toLowerCase() !== 'world') {
let locationData = this.getLocDataByLocValue(rawLocation);

if (locationData) {
Expand All @@ -365,16 +380,18 @@ <h1>{{displayingTestType}} from multiple locations in </h1>
this.set('highLevelLocationHref', `${global.location.origin}${this.modifyQueryPart(selectedTestType, locationData.fromAsUrlPart)}`);
} else {
// when testType correct but location absent at the moment among the probes or incorrect
this.moveToNewPageURL(selectedTestType, null, true);
this.moveToNewPageURL(selectedTestType);

return;
}
} else {
this.set('locationData', { from: 'World', probesCnt: this.get('totalProbesCnt') });
this.set('highLevelLocationHref', `${global.location.origin}${this.modifyQueryPart(selectedTestType, null, true)}`);
this.set('highLevelLocationHref', `${global.location.origin}${this.modifyQueryPart(selectedTestType)}`);
}

// handle meta tag title and description once location is confirmed as presented
let locationData = this.getLocDataByLocValue(rawLocation);
let title = this.createMetaTitle(selectedTestType, locationData ? locationData.name : 'world');
let title = this.createMetaTitle(selectedTestType, locationData ? locationData.name : 'World');
let description = this.createMetaDescr(selectedTestType, locationData ? locationData.name : 'world');

this.set('title', title);
Expand Down Expand Up @@ -721,18 +738,16 @@ <h1>{{displayingTestType}} from multiple locations in </h1>

app.router.dispatch(newPath, { noScroll: true });
},
moveToNewPageURL (testType, newLocation = null, leaveTestOnly = false) {
let newPath = this.modifyQueryPart(testType, newLocation, leaveTestOnly);
moveToNewPageURL (testType, newLocation = 'world') {
let newPath = this.modifyQueryPart(testType, newLocation);

window.location.replace(newPath);
},
modifyQueryPart (testType = 'ping', newLocation = null, leaveTestOnly = false) {
modifyQueryPart (testType = 'ping', newLocation = null) {
let newQueryTestFromValue = '';

if (newLocation) {
newQueryTestFromValue = `${testType}-from-${newLocation}`;
} else if (leaveTestOnly) {
newQueryTestFromValue = testType;
} else {
let splittedQueryTestFrom = app.router.uri.path.split('/');
let currQueryTestFromValue = splittedQueryTestFrom[splittedQueryTestFrom.length - 1];
Expand All @@ -756,54 +771,6 @@ <h1>{{displayingTestType}} from multiple locations in </h1>
http.fetchGlobalpingProbes().then(this.handleProbesResponse(false));
}
},
getParamsFromUrl () {
let rawParamsValue = this.get('params');

// if user tries to get the network-tools page without providing at least testType
// navigate to default network-tools page
if (rawParamsValue === null || typeof rawParamsValue === 'undefined') {
this.moveToNewPageURL(INITIAL_OPTS_VALUES.type, null, true);

return;
}

let clearParamsValue = rawParamsValue.replace(/\/network-tools\/?/, '').toLowerCase();
let splitPoint = '-from-';
let splitPointIdx = clearParamsValue.indexOf(splitPoint);
let [ rawTestType, rawLocation ] = splitPointIdx === -1
? clearParamsValue.split(splitPoint)
: [ clearParamsValue.slice(0, splitPointIdx), clearParamsValue.slice(splitPointIdx + splitPoint.length) ];

// if testType provided by user is incorrect
// navigate to default network-tools testType page but conserve the location
if (!this.checkIfTestTypeCorrect(rawTestType)) {
let isFullParam = clearParamsValue.includes(splitPoint) && rawLocation && rawTestType;

this.moveToNewPageURL(INITIAL_OPTS_VALUES.type, isFullParam ? rawLocation : null, !isFullParam);

return;
}

// if testType provided by user is correct but there is no location provided
// navigate to provided by user testType network-tools page
if (clearParamsValue.includes(splitPoint) && !rawLocation) {
this.moveToNewPageURL(rawTestType, null, true);

return;
}

this.set('selectedTestType', rawTestType);
this.set('rawLocation', rawLocation || 'world');
let placeholderLocation = _.capitalizeStrEveryFirstLetter((rawLocation || 'world').split('-').join(' '), CAPITALIZE_EXCLUDE_LIST);
this.set('placeholerLocation', placeholderLocation);

// set temp meta tag title, descr
let title = this.createMetaTitle(rawTestType, placeholderLocation);
let description = this.createMetaDescr(rawTestType, placeholderLocation);

this.set('title', title);
this.set('description', description);
},
checkIfTestTypeCorrect (testType) {
if (!testType) { return false; }

Expand Down Expand Up @@ -886,5 +853,21 @@ <h1>{{displayingTestType}} from multiple locations in </h1>

return true;
},
getInitialRawDataFromUrl () {
let rawParamsValue = this.get('params');
let clearParamsValue = rawParamsValue.replace(/\/network-tools\/?/, '').toLowerCase();
let splitPoint = '-from-';
let splitPointIdx = clearParamsValue.indexOf(splitPoint);
let [ rawTestType, rawLocation = 'world' ] = splitPointIdx === -1
? clearParamsValue.split(splitPoint)
: [ clearParamsValue.slice(0, splitPointIdx), clearParamsValue.slice(splitPointIdx + splitPoint.length) ];
let rawLocationToDisplay = _.capitalizeStrEveryFirstLetter((rawLocation || 'world').split('-').join(' '), CAPITALIZE_EXCLUDE_LIST);

return {
rawTestType,
rawLocation,
rawLocationToDisplay,
};
},
};
</script>
2 changes: 1 addition & 1 deletion src/views/pages/globalping/network.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
data () {
return {
title: 'Network - Globalping',
description: 'Network - Globalping',
description: 'Explore the global network map of Globalping probes.',
availableFilters: [
{
name: 'Europe',
Expand Down
1 change: 1 addition & 0 deletions src/views/pages/globalping/terms.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ <h1 class="page-content_main_title">Terms &amp; Policies</h1>
data () {
return {
title: 'Terms & Policies - Globalping',
description: 'Learn about the terms of usage of the global network testing platform Globalping.',
currentPolicy: 'terms-of-use',
};
},
Expand Down

0 comments on commit a4b2e85

Please sign in to comment.