<commit_before>import React from "react";
import Document, { Html, Head, Main, NextScript } from "next/document";
import { ServerStyleSheet } from "styled-components";

import { theme } from "../site.config";

class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const sheet = new ServerStyleSheet();
    const originalRenderPage = ctx.renderPage;

    try {
      ctx.renderPage = () =>
        originalRenderPage({
          enhanceApp: App => props => sheet.collectStyles(<App {...props} />)
        });

      const initialProps = await Document.getInitialProps(ctx);
      return {
        ...initialProps,
        styles: (<commit_msg>Redirect to non-www if www exists<commit_after>import React from "react";
import Document, { Html, Head, Main, NextScript } from "next/document";
import { ServerStyleSheet } from "styled-components";

import { theme } from "../site.config";

class MyDocument extends Document {
  static async getInitialProps(ctx) {
    // Redirect to www if no www used
    if (ctx.req.headers.host === "www.isaacbythewood.com") {
      ctx.res.writeHead(301, {
        Location: `https://isaacbythewood.com${ctx.req.url}`
      });
      ctx.res.end();
      return {};
    }

    // Setup styled-components for rendering server side
    const sheet = new ServerStyleSheet();
    const originalRenderPage = ctx.renderPage;

    try {
      ctx.renderPage = () =>
        originalRenderPage({
          enhanceApp: App => props => sheet.collectStyles(<App {...props} />)
        });

      const initialProps = await Document.getInitialProps(ctx);
      return {
        ...initialProps,
        styles: (
{'fraction_non_alphanumeric': 0.12809667673716013, 'fraction_numerical': 0.0018126888217522659, 'mean_word_length': 2.8333333333333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 1, 'lorem ipsum': 0, 'www.': 5, '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': '3053953', 'n_tokens_mistral': 464, 'n_tokens_neox': 458, 'n_words': 124}