mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-30 16:01:14 -04:00
feat(client): remove CAP and GAP scripts (#48508)
feat: Remove CAP and GAP scripts
This commit is contained in:
@@ -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[] {
|
||||
|
||||
Reference in New Issue
Block a user