<commit_before>import React from 'react';
import { withPrefix } from 'gatsby';
import { Helmet } from 'react-helmet';
import { dependencies } from './package.json';
import { siteMetadata } from './gatsby-config';

/* It is better to pull these files directly from a CDN rather than bundling them ourselves. However, the packages are
 * still required to be installed as they are used elsewhere, so we import the versions here to ensure we are
 * consistent. */
export const onRenderBody = ({ setHeadComponents, setPostBodyComponents }) => {
    setHeadComponents([
        <link
            key="fontawesome"
            rel="stylesheet"
            href={`https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-svg-core@${dependencies['@fortawesome/fontawesome-svg-core']}/styles.min.css`}
            crossOrigin="anonymous" />,
        <link
            key="roboto"
            rel="stylesheet"
            href="https://cdn.jsdelivr.net/npm/@fontsource/roboto@4.1.0/index.min.css"
            crossOrigin="anonymous" />,
    ]);

    setPostBodyComponents([
        <script
            key="jquery"
            src={`https://cdnjs.cloudflare.com/ajax/libs/jquery/${dependencies['jquery']}/jquery.slim.min.js`}
            crossOrigin="anonymous" />,
        <script
            key="bootstrap"
            src={`https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/${dependencies['bootstrap']}/js/bootstrap.bundle.min.js`}
            crossOrigin="anonymous" />
    ]);
};

export const wrapPageElement = ({ element, props: { location: { pathname } } }) => {
    if (['/example-runner/', '/404/', '/404.html'].some(exclude => withPrefix(exclude) === pathname)) {
        return element;
    }

    const canonicalUrl = `${siteMetadata.siteUrl}${pathname || '/'}`;

    return (
        <>
            <Helmet link={[{ rel: 'canonical', key: canonicalUrl, href: canonicalUrl }]} />
            {element}
        </>
    );
};<commit_msg>AG-4865 - don't inline generated CSS<commit_after>import React from 'react';
import { withPrefix } from 'gatsby';
import { Helmet } from 'react-helmet';
import { dependencies } from './package.json';
import { siteMetadata } from './gatsby-config';

/* It is better to pull these files directly from a CDN rather than bundling them ourselves. However, the packages are
 * still required to be installed as they are used elsewhere, so we import the versions here to ensure we are
 * consistent. */
export const onRenderBody = ({ setHeadComponents, setPostBodyComponents }) => {
    setHeadComponents([
        <link
            key="fontawesome"
            rel="stylesheet"
            href={`https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-svg-core@${dependencies['@fortawesome/fontawesome-svg-core']}/styles.min.css`}
            crossOrigin="anonymous" />,
        <link
            key="roboto"
            rel="stylesheet"
            href="https://cdn.jsdelivr.net/npm/@fontsource/roboto@4.1.0/index.min.css"
            crossOrigin="anonymous" />,
    ]);

    setPostBodyComponents([
        <script
            key="jquery"
            src={`https://cdnjs.cloudflare.com/ajax/libs/jquery/${dependencies['jquery']}/jquery.slim.min.js`}
            crossOrigin="anonymous" />,
        <script
            key="bootstrap"
            src={`https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/${dependencies['bootstrap']}/js/bootstrap.bundle.min.js`}
            crossOrigin="anonymous" />
    ]);
};

export const wrapPageElement = ({ element, props: { location: { pathname } } }) => {
    if (['/example-runner/', '/404/', '/404.html'].some(exclude => withPrefix(exclude) === pathname)) {
        return element;
    }

    const canonicalUrl = `${siteMetadata.siteUrl}${pathname || '/'}`;

    return (
        <>
            <Helmet link={[{ rel: 'canonical', key: canonicalUrl, href: canonicalUrl }]} />
            {element}
        </>
    );
};

export const onPreRenderHTML = ({ getHeadComponents }) => {
    if (process.env.NODE_ENV !== 'production') {
        return;
    }

    getHeadComponents().forEach(el => {
        // remove inlined CSS
        if (el.type === 'style' && el.props['data-href']) {
            el.type = 'link';
            el.props['href'] = el.props['data-href'];
            el.props['rel'] = 'stylesheet';
            el.props['type'] = 'text/css';

            delete el.props['data-href'];
            delete el.props['dangerouslySetInnerHTML'];
        }
    });
};
{'fraction_non_alphanumeric': 0.15879059350503918, 'fraction_numerical': 0.004927211646136618, 'mean_word_length': 2.5444444444444443, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4819396', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1275, 'n_words': 260}