Skip to content

Commit

Permalink
feat: add foundational work
Browse files Browse the repository at this point in the history
refs #21
  • Loading branch information
mezeitamas committed Jun 1, 2023
1 parent 4eedad2 commit 5c96d57
Show file tree
Hide file tree
Showing 34 changed files with 286 additions and 96 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {

// Coverage
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.test.{ts,tsx}', '!src/gatsby-types.d.ts'],
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.types.{ts,tsx}', '!src/**/*.test.{ts,tsx}', '!src/gatsby-types.d.ts'],
coverageDirectory: 'reports/coverage',
coveragePathIgnorePatterns: ['/node_modules/'],
coverageProvider: 'babel',
Expand Down
31 changes: 31 additions & 0 deletions src/components/dark-mode-switch/dark-mode-switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useCallback, useState } from 'react';
import type { FunctionComponent, ReactElement } from 'react';

import { FiSun, FiMoon } from 'react-icons/fi';

const DarkModeSwitch: FunctionComponent = (): ReactElement => {
const [darkMode, setDarkMode] = useState<boolean>(false);

const toggleDarkMode = useCallback(() => {
setDarkMode(!darkMode);
document.documentElement.classList.toggle('dark');
}, [darkMode]);

return (
<>
{darkMode === true ? (
<FiMoon
size="28"
onClick={toggleDarkMode}
/>
) : (
<FiSun
size="28"
onClick={toggleDarkMode}
/>
)}
</>
);
};

export { DarkModeSwitch };
24 changes: 24 additions & 0 deletions src/components/document-head/document-head.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import type { FunctionComponent, PropsWithChildren } from 'react';

const DocumentHead: FunctionComponent<PropsWithChildren> = ({ children }) => {
return (
<>
<html lang="en" />

<meta
httpEquiv="cache-control"
content="public, max-age=0, must-revalidate"
/>

<meta
name="color-scheme"
content="light dark"
/>

{children}
</>
);
};

export { DocumentHead };
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

exports[`<SeoBlogPosting /> should render 1`] = `
[
<html
lang="en"
/>,
<title>
Hosting a static website on Amazon S3
</title>,
<meta
content="public, max-age=0, must-revalidate"
httpEquiv="cache-control"
/>,
<meta
content="Hosting a simple static website on Amazon Web Services (AWS) can be daunting at first, but luckily it’s quite straightforward. One option..."
name="description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

exports[`<SeoWebPage /> should render 1`] = `
[
<html
lang="en"
/>,
<title>
Broken Robot
</title>,
<meta
content="public, max-age=0, must-revalidate"
httpEquiv="cache-control"
/>,
<meta
content="Personal website and blog of Tamas Mezei. Welcome to my little corner of the web, where I share my professional experiences, thoughts, adventures, and projects with the world."
name="description"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import type { FunctionComponent } from 'react';

import type { Author } from '../../site-metadata/site-metadata.types';
import type { Author } from '../../../site-metadata/site-metadata.types';

type MetaTwitterProps = {
title: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { FunctionComponent } from 'react';

import type { Person, Organization, WebSite, BlogPosting, WithContext } from 'schema-dts';

import type { Author } from '../../site-metadata/site-metadata.types';
import type { Author } from '../../../site-metadata/site-metadata.types';

type RichResultsBlogPostingProps = {
siteName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { FunctionComponent } from 'react';

import type { Person, Organization, WithContext, WebPage } from 'schema-dts';

import type { Author } from '../../site-metadata/site-metadata.types';
import type { Author } from '../../../site-metadata/site-metadata.types';

type RichResultsWebPageProps = {
siteName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { create } from 'react-test-renderer';
import { SeoBlogPosting } from './seo-blog-posting';
import type { SeoBlogPostingProps } from './seo-blog-posting';

jest.mock('../site-metadata/use-site-metadata', () => {
jest.mock('../../site-metadata/use-site-metadata', () => {
return {
useSiteMetadata: jest.fn().mockImplementation(() => {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import type { FunctionComponent, PropsWithChildren } from 'react';
import type { FunctionComponent } from 'react';

import { useSiteMetadata } from '../site-metadata/use-site-metadata';
import { useSiteMetadata } from '../../site-metadata/use-site-metadata';

import { MetaOgArticle } from './meta-og-article/meta-og-article';
import { MetaTwitter } from './meta-twitter/meta-twitter';
Expand All @@ -15,28 +15,14 @@ type SeoBlogPostingProps = {
tags: string[];
};

const SeoBlogPosting: FunctionComponent<PropsWithChildren<SeoBlogPostingProps>> = ({
title,
description,
pathname,
published,
tags,
children
}) => {
const SeoBlogPosting: FunctionComponent<SeoBlogPostingProps> = ({ title, description, pathname, published, tags }) => {
const { title: siteName, siteUrl, author } = useSiteMetadata();
const url = `${siteUrl}${pathname}`;

return (
<>
<html lang="en" />

<title>{title}</title>

<meta
httpEquiv="cache-control"
content="public, max-age=0, must-revalidate"
/>

<meta
name="description"
content={description}
Expand Down Expand Up @@ -73,8 +59,6 @@ const SeoBlogPosting: FunctionComponent<PropsWithChildren<SeoBlogPostingProps>>
url={url}
author={author}
/>

{children}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { create } from 'react-test-renderer';
import { SeoWebPage } from './seo-web-page';
import type { SeoWebPageProps } from './seo-web-page';

jest.mock('../site-metadata/use-site-metadata', () => {
jest.mock('../../site-metadata/use-site-metadata', () => {
return {
useSiteMetadata: jest.fn().mockImplementation(() => {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import type { FunctionComponent, PropsWithChildren } from 'react';
import type { FunctionComponent } from 'react';

import { useSiteMetadata } from '../site-metadata/use-site-metadata';
import { useSiteMetadata } from '../../site-metadata/use-site-metadata';

import { MetaOgWebsite } from './meta-og-website/meta-og-website';
import { MetaTwitter } from './meta-twitter/meta-twitter';
Expand All @@ -13,26 +13,14 @@ type SeoWebPageProps = {
pathname: string;
};

const SeoWebPage: FunctionComponent<PropsWithChildren<SeoWebPageProps>> = ({
title,
description,
pathname,
children
}) => {
const SeoWebPage: FunctionComponent<SeoWebPageProps> = ({ title, description, pathname }) => {
const { title: siteName, siteUrl, author } = useSiteMetadata();
const url = `${siteUrl}${pathname}`;

return (
<>
<html lang="en" />

<title>{title}</title>

<meta
httpEquiv="cache-control"
content="public, max-age=0, must-revalidate"
/>

<meta
name="description"
content={description}
Expand All @@ -57,8 +45,6 @@ const SeoWebPage: FunctionComponent<PropsWithChildren<SeoWebPageProps>> = ({
url={url}
author={author}
/>

{children}
</>
);
};
Expand Down
71 changes: 71 additions & 0 deletions src/components/layout/__snapshots__/layout.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,77 @@ exports[`<Layout /> should render 1`] = `
About me
</a>
</span>
<svg
fill="none"
height="28"
onClick={[Function]}
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
style={
{
"color": undefined,
}
}
viewBox="0 0 24 24"
width="28"
xmlns="http://www.w3.org/2000/svg"
>
<circle
cx="12"
cy="12"
r="5"
/>
<line
x1="12"
x2="12"
y1="1"
y2="3"
/>
<line
x1="12"
x2="12"
y1="21"
y2="23"
/>
<line
x1="4.22"
x2="5.64"
y1="4.22"
y2="5.64"
/>
<line
x1="18.36"
x2="19.78"
y1="18.36"
y2="19.78"
/>
<line
x1="1"
x2="3"
y1="12"
y2="12"
/>
<line
x1="21"
x2="23"
y1="12"
y2="12"
/>
<line
x1="4.22"
x2="5.64"
y1="19.78"
y2="18.36"
/>
<line
x1="18.36"
x2="19.78"
y1="5.64"
y2="4.22"
/>
</svg>
</div>
</nav>
<hr />
Expand Down
71 changes: 71 additions & 0 deletions src/components/layout/header/__snapshots__/header.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,77 @@ exports[`<Header /> should render 1`] = `
About me
</a>
</span>
<svg
fill="none"
height="28"
onClick={[Function]}
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
style={
{
"color": undefined,
}
}
viewBox="0 0 24 24"
width="28"
xmlns="http://www.w3.org/2000/svg"
>
<circle
cx="12"
cy="12"
r="5"
/>
<line
x1="12"
x2="12"
y1="1"
y2="3"
/>
<line
x1="12"
x2="12"
y1="21"
y2="23"
/>
<line
x1="4.22"
x2="5.64"
y1="4.22"
y2="5.64"
/>
<line
x1="18.36"
x2="19.78"
y1="18.36"
y2="19.78"
/>
<line
x1="1"
x2="3"
y1="12"
y2="12"
/>
<line
x1="21"
x2="23"
y1="12"
y2="12"
/>
<line
x1="4.22"
x2="5.64"
y1="19.78"
y2="18.36"
/>
<line
x1="18.36"
x2="19.78"
y1="5.64"
y2="4.22"
/>
</svg>
</div>
</nav>
<hr />
Expand Down
Loading

0 comments on commit 5c96d57

Please sign in to comment.