Browse Source

fix: some clean up

fix/enable-imgix
Thomas Osmonson 4 years ago
parent
commit
1c989aa78c
  1. BIN
      public/app-icon.png
  2. 3
      public/favicon-dark.svg
  3. 3
      public/favicon-light.svg
  4. BIN
      public/favicon.ico
  5. 69
      src/common/hooks/use-color-mode.ts
  6. 7
      src/common/hooks/use-favicon.ts
  7. 23
      src/components/app-wrapper.tsx
  8. 2
      src/components/color-mode-button.tsx
  9. 10
      src/components/icons/clock.tsx
  10. 12
      src/components/icons/gauge.tsx
  11. 14
      src/components/icons/tools.tsx
  12. 32
      src/components/layouts/markdown-wrapper.tsx
  13. 13
      src/components/meta-head.tsx
  14. 101
      src/pages/_app.tsx
  15. 13
      src/pages/_document.tsx

BIN
public/app-icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

3
public/favicon-dark.svg

@ -0,0 +1,3 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M0.296084 2.17027C-1.11759e-07 2.85448 -7.61996e-08 3.72699 0 5.472L2.85426e-07 12L5.70773e-07 18.528C6.4705e-07 20.273 0 21.1455 0.296084 21.8297C0.659732 22.6701 1.32993 23.3403 2.17027 23.7039C2.85448 24 3.72698 24 5.472 24H12H18.528C20.273 24 21.1455 24 21.8297 23.7039C22.6701 23.3403 23.3403 22.6701 23.7039 21.8297C24 21.1455 24 20.273 24 18.528V12V5.472C24 3.72698 24 2.85448 23.7039 2.17027C23.3403 1.32993 22.6701 0.65973 21.8297 0.296083C21.1455 -1.3411e-07 20.273 -7.61996e-08 18.528 0L12 2.85426e-07L5.472 5.70774e-07C3.72698 6.47051e-07 2.8125 5.81145e-07 2.17027 0.296084C1.32993 0.659733 0.659732 1.32993 0.296084 2.17027ZM15.8313 10.3393C14.6336 10.3393 13.6625 9.36817 13.6625 8.17022C13.6625 6.97287 14.6336 6.00176 15.8313 6.00176C17.029 6.00176 18.0001 6.97287 18.0001 8.17022C18.0001 9.36817 17.029 10.3393 15.8313 10.3393ZM10.3357 8.17001C10.3357 9.36716 9.36506 10.3379 8.16764 10.3379C6.97083 10.3379 6.00015 9.36716 6.00015 8.17001C6.00015 6.97286 6.97083 6.00215 8.16764 6.00215C9.36506 6.00215 10.3357 6.97286 10.3357 8.17001ZM15.8315 13.6692C14.6336 13.6692 13.6625 14.6403 13.6625 15.838C13.6625 17.0357 14.6336 18.0068 15.8315 18.0068C17.0289 18.0068 18 17.0357 18 15.838C18 14.6403 17.0289 13.6692 15.8315 13.6692ZM8.16783 13.6713C9.36497 13.6713 10.3357 14.642 10.3357 15.8394C10.3357 17.0362 9.36497 18.0068 8.16783 18.0068C6.9707 18.0068 6 17.0362 6 15.8394C6 14.642 6.9707 13.6713 8.16783 13.6713Z" fill="#0F1117"/>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

3
public/favicon-light.svg

@ -0,0 +1,3 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M0.296084 2.17027C-1.11759e-07 2.85448 -7.61996e-08 3.72699 0 5.472L2.85426e-07 12L5.70773e-07 18.528C6.4705e-07 20.273 0 21.1455 0.296084 21.8297C0.659732 22.6701 1.32993 23.3403 2.17027 23.7039C2.85448 24 3.72698 24 5.472 24H12H18.528C20.273 24 21.1455 24 21.8297 23.7039C22.6701 23.3403 23.3403 22.6701 23.7039 21.8297C24 21.1455 24 20.273 24 18.528V12V5.472C24 3.72698 24 2.85448 23.7039 2.17027C23.3403 1.32993 22.6701 0.65973 21.8297 0.296083C21.1455 -1.3411e-07 20.273 -7.61996e-08 18.528 0L12 2.85426e-07L5.472 5.70774e-07C3.72698 6.47051e-07 2.8125 5.81145e-07 2.17027 0.296084C1.32993 0.659733 0.659732 1.32993 0.296084 2.17027ZM15.8313 10.3393C14.6336 10.3393 13.6625 9.36817 13.6625 8.17022C13.6625 6.97287 14.6336 6.00176 15.8313 6.00176C17.029 6.00176 18.0001 6.97287 18.0001 8.17022C18.0001 9.36817 17.029 10.3393 15.8313 10.3393ZM10.3357 8.17001C10.3357 9.36716 9.36506 10.3379 8.16764 10.3379C6.97083 10.3379 6.00015 9.36716 6.00015 8.17001C6.00015 6.97286 6.97083 6.00215 8.16764 6.00215C9.36506 6.00215 10.3357 6.97286 10.3357 8.17001ZM15.8315 13.6692C14.6336 13.6692 13.6625 14.6403 13.6625 15.838C13.6625 17.0357 14.6336 18.0068 15.8315 18.0068C17.0289 18.0068 18 17.0357 18 15.838C18 14.6403 17.0289 13.6692 15.8315 13.6692ZM8.16783 13.6713C9.36497 13.6713 10.3357 14.642 10.3357 15.8394C10.3357 17.0362 9.36497 18.0068 8.16783 18.0068C6.9707 18.0068 6 17.0362 6 15.8394C6 14.642 6.9707 13.6713 8.16783 13.6713Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
public/favicon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

69
src/common/hooks/use-color-mode.ts

@ -0,0 +1,69 @@
import React from 'react';
import { useMediaQuery } from '@common/hooks/use-media-query';
import { THEME_STORAGE_KEY } from '@common/constants';
export const useColorMode = (): [string, () => void, (mode: 'dark' | 'light') => void] => {
const [darkmode] = useMediaQuery('(prefers-color-scheme: dark)');
const [lightmode] = useMediaQuery('(prefers-color-scheme: light)');
const setMode = typeof localStorage !== 'undefined' && localStorage.getItem(THEME_STORAGE_KEY);
const [colorMode, setColorMode] = React.useState<'dark' | 'light' | undefined>(undefined);
const setHtmlBackgroundColor = React.useCallback(() => {
document.documentElement.style.background = getComputedStyle(
document.documentElement
).getPropertyValue('--colors-bg');
}, []);
const setDarkMode = React.useCallback(() => {
localStorage.setItem(THEME_STORAGE_KEY, 'dark');
setColorMode('dark');
document.documentElement.classList.add('dark');
document.documentElement.classList.remove('light');
setHtmlBackgroundColor();
}, []);
const setLightMode = React.useCallback(() => {
localStorage.setItem(THEME_STORAGE_KEY, 'light');
setColorMode('light');
document.documentElement.classList.add('light');
document.documentElement.classList.remove('dark');
setHtmlBackgroundColor();
}, []);
React.useEffect(() => {
if (setMode) {
if (setMode === 'dark') {
setColorMode('dark');
}
if (setMode === 'light') {
setColorMode('light');
}
} else {
if (darkmode) {
setDarkMode();
}
if (lightmode) {
setLightMode();
}
}
}, [setMode, lightmode, darkmode]);
const toggleColorMode = React.useCallback(() => {
if (typeof document !== 'undefined') {
if (setMode) {
if (setMode === 'light') {
setDarkMode();
} else {
setLightMode();
}
} else if (darkmode) {
setLightMode();
} else {
setDarkMode();
}
}
}, [darkmode, lightmode, setMode, colorMode]);
return [colorMode, toggleColorMode, setColorMode];
};

7
src/common/hooks/use-favicon.ts

@ -0,0 +1,7 @@
import { useColorMode } from '@common/hooks/use-color-mode';
export const useFaviconName = () => {
const [mode] = useColorMode();
const darkmode = mode === 'dark';
return `favicon-${darkmode ? 'light' : 'dark'}.svg`;
};

23
src/components/app-wrapper.tsx

@ -0,0 +1,23 @@
import React from 'react';
import { MDXProvider } from '@mdx-js/react';
import { MDXComponents } from '@components/mdx';
import { AppStateProvider } from '@components/app-state';
import { MdxOverrides } from '@components/mdx/overrides';
import { ProgressBar } from '@components/progress-bar';
import { BaseLayout } from '@components/layouts/base-layout';
import { ColorModes } from '@components/color-modes/styles';
import { Meta } from '@components/meta-head';
export const AppWrapper: React.FC<any> = ({ children, isHome }) => (
<>
<Meta />
<MdxOverrides />
<ColorModes />
<ProgressBar />
<MDXProvider components={MDXComponents}>
<AppStateProvider>
<BaseLayout isHome={isHome}>{children}</BaseLayout>
</AppStateProvider>
</MDXProvider>
</>
);

2
src/components/color-mode-button.tsx

@ -3,7 +3,7 @@ import { LinkProps } from '@components/typography';
import { DarkModeIcon } from '@components/icons/dark-mode';
import { LightModeIcon } from '@components/icons/light-mode';
import { IconButton } from '@components/icon-button';
import { useColorMode } from '@pages/_app';
import { useColorMode } from '@common/hooks/use-color-mode';
export const ColorModeButton = forwardRef((props: LinkProps, ref: Ref<HTMLDivElement>) => {
const [colorMode, toggleColorMode] = useColorMode();

10
src/components/icons/clock.tsx

@ -0,0 +1,10 @@
import React from 'react';
import { BaseSvg, SvgProps } from '@components/icons/_base';
export const ClockIcon: SvgProps = props => (
<BaseSvg {...props}>
<path stroke="none" d="M0 0h24v24H0z" />
<circle cx="12" cy="12" r="9" />
<polyline points="12 7 12 12 15 15" />
</BaseSvg>
);

12
src/components/icons/gauge.tsx

@ -0,0 +1,12 @@
import React from 'react';
import { BaseSvg, SvgProps } from '@components/icons/_base';
export const GaugeIcon: SvgProps = props => (
<BaseSvg {...props}>
<path stroke="none" d="M0 0h24v24H0z" />
<circle cx="12" cy="12" r="9" />
<circle cx="12" cy="12" r="1" />
<line x1="13.41" y1="10.59" x2="16" y2="8" />
<path d="M7 12a5 5 0 0 1 5 -5" />
</BaseSvg>
);

14
src/components/icons/tools.tsx

@ -0,0 +1,14 @@
import React from 'react';
import { BaseSvg, SvgProps } from '@components/icons/_base';
export const ToolsIcon: SvgProps = props => (
<BaseSvg {...props}>
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M3 21h4l13 -13a1.5 1.5 0 0 0 -4 -4l-13 13v4" />
<line x1="14.5" y1="5.5" x2="18.5" y2="9.5" />
<polyline points="12 8 7 3 3 7 8 12" />
<line x1="7" y1="8" x2="5.5" y2="9.5" />
<polyline points="16 12 21 17 17 21 12 16" />
<line x1="16" y1="17" x2="14.5" y2="18.5" />
</BaseSvg>
);

32
src/components/layouts/markdown-wrapper.tsx

@ -1,17 +1,39 @@
import React from 'react';
import { Box, Flex, Stack, space } from '@blockstack/ui';
import { Box, Flex, Stack, space, BoxProps, color } from '@blockstack/ui';
import { MDContents } from '@components/mdx/md-contents';
import { H1 } from '@components/mdx';
import Head from 'next/head';
import { Caption, Text } from '@components/typography';
import { Text } from '@components/typography';
import { useRouter } from 'next/router';
import dynamic from 'next/dynamic';
import { getTitle } from '@common/utils';
import { css } from '@styled-system/css';
import { getHeadingStyles } from '@components/mdx/typography';
import { ToolsIcon } from '@components/icons/tools';
import { ClockIcon } from '@components/icons/clock';
const Search = dynamic(() => import('@components/search'));
const PageTop = props => {
const Experience: React.FC<BoxProps & { level?: 'beginner' | 'intermediate' | 'advanced' }> = ({
level,
...rest
}) => (
<Flex align="center" {...rest}>
<Box mr={space('extra-tight')} color={color('text-caption')}>
<ToolsIcon size="20px" />
</Box>
<Text textTransform="capitalize">{level}</Text>
</Flex>
);
const Duration: React.FC<BoxProps & { value?: string }> = ({ value, ...rest }) => (
<Flex align="center" {...rest}>
<Box mr={space('extra-tight')} color={color('text-caption')}>
<ClockIcon size="20px" />
</Box>
<Text>{value}</Text>
</Flex>
);
const PageTop: React.FC<any> = props => {
const router = useRouter();
const isHome = router?.pathname === '/';
return (
@ -40,8 +62,8 @@ const PageTop = props => {
) : null}
<Stack isInline spacing={space('base')} mt={space('extra-loose')}>
{props.experience ? <Caption textTransform="capitalize">{props.experience}</Caption> : null}
{!isHome && props.duration ? <Caption>{props.duration}</Caption> : null}
{props.experience ? <Experience level={props.experience} /> : null}
{!isHome && props.duration ? <Duration value={props.duration} /> : null}
</Stack>
</Box>
);

13
src/components/meta-head.tsx

@ -0,0 +1,13 @@
import React from 'react';
import Head from 'next/head';
import { useFaviconName } from '@common/hooks/use-favicon';
export const Meta: React.FC<any> = props => {
const filename = useFaviconName();
return (
<Head>
<link rel="icon" type="image/svg+xml" href={`/${filename}`} />
</Head>
);
};

101
src/pages/_app.tsx

@ -1,107 +1,18 @@
import React from 'react';
import { CSSReset, ThemeProvider } from '@blockstack/ui';
import { useMediaQuery } from '@common/hooks/use-media-query';
import { MDXProvider } from '@mdx-js/react';
import { MDXComponents } from '@components/mdx';
import { AppStateProvider } from '@components/app-state';
import { MdxOverrides } from '@components/mdx/overrides';
import { ProgressBar } from '@components/progress-bar';
import '@docsearch/css';
import { BaseLayout } from '@components/layouts/base-layout';
import { THEME_STORAGE_KEY } from '@common/constants';
import { ColorModes } from '@components/color-modes/styles';
const setHtmlBackgroundColor = () => {
const bgValue = getComputedStyle(document.documentElement).getPropertyValue('--colors-bg');
document.documentElement.style.background = bgValue;
};
const setDarkMode = setColorMode => {
localStorage.setItem(THEME_STORAGE_KEY, 'dark');
setColorMode('dark');
document.documentElement.classList.add('dark');
document.documentElement.classList.remove('light');
setHtmlBackgroundColor();
};
const setLightMode = setColorMode => {
localStorage.setItem(THEME_STORAGE_KEY, 'light');
setColorMode('light');
document.documentElement.classList.add('light');
document.documentElement.classList.remove('dark');
setHtmlBackgroundColor();
};
export const useColorMode = () => {
const [darkmode] = useMediaQuery('(prefers-color-scheme: dark)');
const [lightmode] = useMediaQuery('(prefers-color-scheme: light)');
const setMode = typeof localStorage !== 'undefined' && localStorage.getItem(THEME_STORAGE_KEY);
const [colorMode, setColorMode] = React.useState(undefined);
import type { AppProps } from 'next/app';
React.useEffect(() => {
if (setMode) {
if (setMode === 'dark') {
setColorMode('dark');
}
if (setMode === 'light') {
setColorMode('light');
}
} else {
if (darkmode) {
setDarkMode(setColorMode);
}
if (lightmode) {
setLightMode(setColorMode);
}
}
}, [setMode, lightmode, darkmode]);
const toggleColorMode = () => {
if (typeof document !== 'undefined') {
if (setMode) {
if (setMode === 'light') {
setDarkMode(setColorMode);
} else {
setLightMode(setColorMode);
}
} else if (darkmode) {
setLightMode(setColorMode);
} else {
setDarkMode(setColorMode);
}
}
};
return [colorMode, toggleColorMode, setColorMode];
};
import { CSSReset, ThemeProvider } from '@blockstack/ui';
import { AppWrapper } from '@components/app-wrapper';
const AppWrapper = ({ children, isHome }: any) => {
return (
<>
<MdxOverrides />
<ColorModes />
<ProgressBar />
<MDXProvider components={MDXComponents}>
<AppStateProvider>
<BaseLayout isHome={isHome}>{children}</BaseLayout>
</AppStateProvider>
</MDXProvider>
</>
);
};
import '@docsearch/css';
const MyApp = ({ Component, pageProps, colorMode, ...rest }: any) => {
const { isHome } = pageProps;
return (
<>
const MyApp: React.FC<AppProps> = ({ Component, pageProps, ...rest }) => (
<ThemeProvider>
<CSSReset />
<AppWrapper isHome={isHome} {...rest}>
<AppWrapper {...rest}>
<Component {...pageProps} />
</AppWrapper>
</ThemeProvider>
</>
);
};
export default MyApp;

13
src/pages/_document.tsx

@ -1,8 +1,15 @@
import Document, { DocumentContext, Html, Head, Main, NextScript } from 'next/document';
import Document, {
DocumentContext,
DocumentProps,
Html,
Head,
Main,
NextScript,
} from 'next/document';
import { THEME_STORAGE_KEY } from '@common/constants';
import { ServerStyleSheet } from 'styled-components';
export default class MyDocument extends Document<any> {
export default class MyDocument extends Document<DocumentProps> {
static async getInitialProps(ctx: DocumentContext) {
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;
@ -84,8 +91,6 @@ export default class MyDocument extends Document<any> {
/>
<link rel="preconnect" href="https://bh4d9od16a-dsn.algolia.net" crossOrigin="true" />
<link rel="preconnect" href="https://cdn.usefathom.com" crossOrigin="true" />
<link rel="preconnect" href="https://fonts.googleapis.com" crossOrigin="true" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="true" />
<Main />
<NextScript />
</body>

Loading…
Cancel
Save