mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-02-13 13:00:27 -05:00
feat(client): remove CAP and GAP scripts (#48508)
feat: Remove CAP and GAP scripts
This commit is contained in:
@@ -91,7 +91,6 @@
|
||||
"prismjs": "1.29.0",
|
||||
"process": "0.11.10",
|
||||
"prop-types": "15.8.1",
|
||||
"psl": "1.9.0",
|
||||
"query-string": "7.0.1",
|
||||
"react": "16.14.0",
|
||||
"react-dom": "16.14.0",
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
var hmt = hmt || [];
|
||||
(function() {
|
||||
var hm = document.createElement("script");
|
||||
hm.src = "https://hm.baidu.com/hm.js?5573716a80598952ad73aca7f896ef45";
|
||||
var s = document.getElementsByTagName("script")[0];
|
||||
s.parentNode.insertBefore(hm, s);
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,42 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
import { injectConditionalTags } from './tags';
|
||||
|
||||
describe('Tags', () => {
|
||||
it('injectConditionalTags should inject gap dev homelocation', () => {
|
||||
const injectedTags = injectConditionalTags(
|
||||
[],
|
||||
'https://www.freecodecamp.dev'
|
||||
);
|
||||
expect(injectedTags.length === 1).toBeTruthy();
|
||||
expect(injectedTags[0].props.id === 'gap-dev').toBeTruthy();
|
||||
});
|
||||
it('injectConditionalTags should inject gap for english homeLocation', () => {
|
||||
const injectedTags = injectConditionalTags(
|
||||
[],
|
||||
'https://www.freecodecamp.org'
|
||||
);
|
||||
expect(injectedTags.length === 1).toBeTruthy();
|
||||
expect(injectedTags[0].props.id === 'gap-org').toBeTruthy();
|
||||
});
|
||||
it('injectConditionalTags should inject gap for espanol homeLocation', () => {
|
||||
const injectedTags = injectConditionalTags(
|
||||
[],
|
||||
'https://www.freecodecamp.org/espanol'
|
||||
);
|
||||
expect(injectedTags.length === 1).toBeTruthy();
|
||||
expect(injectedTags[0].props.id === 'gap-org').toBeTruthy();
|
||||
});
|
||||
it('injectConditionalTags should inject cap and chinese gap for chinese homeLocation', () => {
|
||||
const injectedTags = injectConditionalTags(
|
||||
[],
|
||||
'https://chinese.freecodecamp.org'
|
||||
);
|
||||
expect(injectedTags.length === 2).toBeTruthy();
|
||||
expect(injectedTags[0].props.id === 'cap').toBeTruthy();
|
||||
expect(injectedTags[1].props.id === 'gap-org-chinese').toBeTruthy();
|
||||
});
|
||||
it('injectConditionalTags should not inject tags for localhost homeLocation', () => {
|
||||
const injectedTags = injectConditionalTags([], 'http://localhost:8000/');
|
||||
expect(injectedTags.length === 0).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,6 @@
|
||||
import { withPrefix } from 'gatsby';
|
||||
import i18next from 'i18next';
|
||||
import psl from 'psl';
|
||||
import React from 'react';
|
||||
import env from '../../config/env.json';
|
||||
|
||||
const { homeLocation } = env;
|
||||
|
||||
export function getheadTagComponents(): JSX.Element[] {
|
||||
const socialImage =
|
||||
@@ -53,67 +49,7 @@ export function getheadTagComponents(): JSX.Element[] {
|
||||
name='monetization'
|
||||
/>
|
||||
];
|
||||
return injectConditionalTags(headTags, homeLocation);
|
||||
}
|
||||
|
||||
// strips subpath and protocol
|
||||
|
||||
export function injectConditionalTags(
|
||||
tagsArray: JSX.Element[],
|
||||
homeLocation: string
|
||||
): JSX.Element[] {
|
||||
if (homeLocation.includes('localhost')) return tagsArray;
|
||||
|
||||
const parsedHomeUrl = psl.parse(
|
||||
new URL(homeLocation).host
|
||||
) as psl.ParsedDomain;
|
||||
|
||||
// inject gap all production languages except Chinese
|
||||
if (parsedHomeUrl.subdomain === 'www' && parsedHomeUrl.tld === 'org') {
|
||||
tagsArray.push(
|
||||
<script
|
||||
// @ts-expect-error TODO: check use of href/rel on <script>
|
||||
href={withPrefix('/misc/gap-org.js')}
|
||||
id='gap-org'
|
||||
key='gap-org'
|
||||
rel='stylesheet'
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// inject gap for staging
|
||||
if (parsedHomeUrl.subdomain === 'www' && parsedHomeUrl.tld === 'dev') {
|
||||
tagsArray.push(
|
||||
<script
|
||||
// @ts-expect-error See above
|
||||
href={withPrefix('/misc/gap-dev.js')}
|
||||
id='gap-dev'
|
||||
key='gap-dev'
|
||||
rel='stylesheet'
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// inject cap and Chinese gap for production Chinese
|
||||
if (parsedHomeUrl.subdomain === 'chinese' && parsedHomeUrl.tld === 'org') {
|
||||
tagsArray.push(
|
||||
<script
|
||||
// @ts-expect-error See above
|
||||
href={withPrefix('/misc/cap.js')}
|
||||
id='cap'
|
||||
key='cap'
|
||||
rel='stylesheet'
|
||||
/>,
|
||||
<script
|
||||
// @ts-expect-error See above
|
||||
href={withPrefix('/misc/gap-org-chinese.js')}
|
||||
id='gap-org-chinese'
|
||||
key='gap-org-chinese'
|
||||
rel='stylesheet'
|
||||
/>
|
||||
);
|
||||
}
|
||||
return tagsArray;
|
||||
return headTags;
|
||||
}
|
||||
|
||||
export function getPostBodyComponents(pathname: string): JSX.Element[] {
|
||||
|
||||
12
package-lock.json
generated
12
package-lock.json
generated
@@ -50,7 +50,6 @@
|
||||
"@types/lodash-es": "4.17.6",
|
||||
"@types/node": "16.18.3",
|
||||
"@types/prismjs": "1.26.0",
|
||||
"@types/psl": "1.1.0",
|
||||
"@types/reach__router": "1.3.11",
|
||||
"@types/react": "17.0.52",
|
||||
"@types/react-dom": "17.0.18",
|
||||
@@ -488,7 +487,6 @@
|
||||
"prismjs": "1.29.0",
|
||||
"process": "0.11.10",
|
||||
"prop-types": "15.8.1",
|
||||
"psl": "1.9.0",
|
||||
"query-string": "7.0.1",
|
||||
"react": "16.14.0",
|
||||
"react-dom": "16.14.0",
|
||||
@@ -14386,11 +14384,6 @@
|
||||
"version": "15.7.4",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/psl": {
|
||||
"version": "1.1.0",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/q": {
|
||||
"version": "1.5.5",
|
||||
"license": "MIT"
|
||||
@@ -57381,7 +57374,6 @@
|
||||
"prismjs": "1.29.0",
|
||||
"process": "0.11.10",
|
||||
"prop-types": "15.8.1",
|
||||
"psl": "1.9.0",
|
||||
"query-string": "7.0.1",
|
||||
"react": "16.14.0",
|
||||
"react-dom": "16.14.0",
|
||||
@@ -65571,10 +65563,6 @@
|
||||
"@types/prop-types": {
|
||||
"version": "15.7.4"
|
||||
},
|
||||
"@types/psl": {
|
||||
"version": "1.1.0",
|
||||
"dev": true
|
||||
},
|
||||
"@types/q": {
|
||||
"version": "1.5.5"
|
||||
},
|
||||
|
||||
@@ -136,7 +136,6 @@
|
||||
"@types/lodash-es": "4.17.6",
|
||||
"@types/node": "16.18.3",
|
||||
"@types/prismjs": "1.26.0",
|
||||
"@types/psl": "1.1.0",
|
||||
"@types/reach__router": "1.3.11",
|
||||
"@types/react": "17.0.52",
|
||||
"@types/react-dom": "17.0.18",
|
||||
|
||||
Reference in New Issue
Block a user