Skip to content

Commit

Permalink
Merge pull request #11 from hyesungoh/refactor/#8
Browse files Browse the repository at this point in the history
refactor: #8
  • Loading branch information
hyesungoh authored Mar 30, 2022
2 parents dd8d91f + 922b0fa commit d413ec5
Show file tree
Hide file tree
Showing 12 changed files with 375 additions and 369 deletions.
64 changes: 64 additions & 0 deletions apps/blog/src/components/AuthorSection/AuthorSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import styled from '@emotion/styled';
import { Avatar, Link } from '@nextui-org/react';
import { KBarToggleButton } from 'core';

import { authorImage, authorName, defaultUrl } from 'core/constants';
import { blogDescription } from '../../../_config';

interface Props {
marginBottom?: string;
hasKbarButton?: boolean;
}

function AuthorSection({ marginBottom = '3.5rem', hasKbarButton = false }: Props) {
return (
<Section style={{ marginBottom }}>
<Div>
<Avatar src={authorImage.default.src} alt={authorName} text={authorName} size="xl" />
<TextWrapper>
<H2>
Personal blog by{' '}
<Link href={defaultUrl} target="_blank" rel="noreferrer" color="primary">
{authorName}
</Link>
.
</H2>
<p>{blogDescription}</p>
</TextWrapper>
</Div>

{hasKbarButton && <KBarToggleButton />}
</Section>
);
}

export default AuthorSection;

const Section = styled.section`
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
`;

const Div = styled.div`
display: flex;
align-items: center;
`;

const TextWrapper = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
margin-left: 0.875rem;
& > * {
margin: 0;
font-size: 1rem;
line-height: 1.5rem;
}
`;

const H2 = styled.h2`
font-weight: normal;
`;
65 changes: 1 addition & 64 deletions apps/blog/src/components/AuthorSection/index.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1 @@
import styled from '@emotion/styled';
import { Avatar, Link } from '@nextui-org/react';
import { KBarToggleButton } from 'core';

import { authorImage, authorName, defaultUrl } from 'core/constants';
import { blogDescription } from '../../../_config';

interface Props {
marginBottom?: string;
hasKbarButton?: boolean;
}

function AuthorSection({ marginBottom = '3.5rem', hasKbarButton = false }: Props) {
return (
<Section style={{ marginBottom }}>
<Div>
<Avatar src={authorImage.default.src} alt={authorName} text={authorName} size="xl" />
<TextWrapper>
<H2>
Personal blog by{' '}
<Link href={defaultUrl} target="_blank" rel="noreferrer" color="primary">
{authorName}
</Link>
.
</H2>
<p>{blogDescription}</p>
</TextWrapper>
</Div>

{hasKbarButton && <KBarToggleButton />}
</Section>
);
}

export default AuthorSection;

const Section = styled.section`
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
`;

const Div = styled.div`
display: flex;
align-items: center;
`;

const TextWrapper = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
margin-left: 0.875rem;
& > * {
margin: 0;
font-size: 1rem;
line-height: 1.5rem;
}
`;

const H2 = styled.h2`
font-weight: normal;
`;
export { default } from './AuthorSection';
64 changes: 64 additions & 0 deletions apps/blog/src/components/Comments/Comments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useEffect, useRef } from 'react';
import { useTheme } from '@nextui-org/react';
import { blogRepo } from '../../../_config';

const src = 'https://utteranc.es/client.js';
const LIGHT_THEME = 'github-light';
const DARK_THEME = 'github-dark';
const SYSTEM_THEME = 'preferred-color-scheme';
const UTTERANCE_QUERY = '.utterances-frame';

function Comments() {
const rootElm = useRef<HTMLElement>();
const { isDark } = useTheme();

// for initial
useEffect(() => {
function getCurrentTheme() {
const initialTheme = document.querySelector('html').classList[0];
if (initialTheme) {
return initialTheme.includes('dark') ? DARK_THEME : LIGHT_THEME;
}
return SYSTEM_THEME;
}

if (!rootElm.current) return;
if (document.querySelector(UTTERANCE_QUERY)) return; // prevant duplicate

const utterances = document.createElement('script');
const utterancesConfig = {
src,
repo: blogRepo,
theme: getCurrentTheme(),
label: 'comment',
async: true,
'issue-term': 'pathname',
crossorigin: 'anonymous',
};

Object.keys(utterancesConfig).forEach(key => {
utterances.setAttribute(key, utterancesConfig[key]);
});
rootElm.current.appendChild(utterances);
}, []);

// for theme changed
useEffect(() => {
if (document.querySelector(UTTERANCE_QUERY)) {
const iframe = document.querySelector<HTMLIFrameElement>(UTTERANCE_QUERY);

if (!iframe) {
return;
}

iframe?.contentWindow?.postMessage(
{ type: 'set-theme', theme: isDark ? DARK_THEME : LIGHT_THEME },
'https://utteranc.es'
);
}
}, [isDark]);

return <section ref={rootElm} />;
}

export default Comments;
65 changes: 1 addition & 64 deletions apps/blog/src/components/Comments/index.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1 @@
import { useEffect, useRef } from 'react';
import { useTheme } from '@nextui-org/react';
import { blogRepo } from '../../../_config';

const src = 'https://utteranc.es/client.js';
const LIGHT_THEME = 'github-light';
const DARK_THEME = 'github-dark';
const SYSTEM_THEME = 'preferred-color-scheme';
const UTTERANCE_QUERY = '.utterances-frame';

function Comments() {
const rootElm = useRef<HTMLElement>();
const { isDark } = useTheme();

// for initial
useEffect(() => {
function getCurrentTheme() {
const initialTheme = document.querySelector('html').classList[0];
if (initialTheme) {
return initialTheme.includes('dark') ? DARK_THEME : LIGHT_THEME;
}
return SYSTEM_THEME;
}

if (!rootElm.current) return;
if (document.querySelector(UTTERANCE_QUERY)) return; // prevant duplicate

const utterances = document.createElement('script');
const utterancesConfig = {
src,
repo: blogRepo,
theme: getCurrentTheme(),
label: 'comment',
async: true,
'issue-term': 'pathname',
crossorigin: 'anonymous',
};

Object.keys(utterancesConfig).forEach(key => {
utterances.setAttribute(key, utterancesConfig[key]);
});
rootElm.current.appendChild(utterances);
}, []);

// for theme changed
useEffect(() => {
if (document.querySelector(UTTERANCE_QUERY)) {
const iframe = document.querySelector<HTMLIFrameElement>(UTTERANCE_QUERY);

if (!iframe) {
return;
}

iframe?.contentWindow?.postMessage(
{ type: 'set-theme', theme: isDark ? DARK_THEME : LIGHT_THEME },
'https://utteranc.es'
);
}
}, [isDark]);

return <section ref={rootElm} />;
}

export default Comments;
export { default } from './Comments';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import NextLink from 'next/link';
import { Link } from '@nextui-org/react';

interface Props {
date: string;
category?: string;
}

function DateAndCategoryLink({ date, category }: Props) {
return (
<>
{date}
{category && (
<>
{' '}
at{' '}
<NextLink href={`/category/${category}`} passHref>
<Link color="primary">{category}</Link>
</NextLink>{' '}
category
</>
)}
</>
);
}
export default DateAndCategoryLink;
27 changes: 1 addition & 26 deletions apps/blog/src/components/DateAndCategoryLink/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1 @@
import NextLink from 'next/link';
import { Link } from '@nextui-org/react';

interface Props {
date: string;
category?: string;
}

function DateAndCategoryLink({ date, category }: Props) {
return (
<>
{date}
{category && (
<>
{' '}
at{' '}
<NextLink href={`/category/${category}`} passHref>
<Link color="primary">{category}</Link>
</NextLink>{' '}
category
</>
)}
</>
);
}
export default DateAndCategoryLink;
export { default } from './DateAndCategoryLink';
47 changes: 47 additions & 0 deletions apps/blog/src/components/PostCard/PostCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import styled from '@emotion/styled';
import NextLink from 'next/link';
import { Link, NextUITheme, theme } from '@nextui-org/react';
import DateAndCategoryLink from '../DateAndCategoryLink';

interface Props {
slug: string;
title: string;
subtitle?: string;
date: string;
category?: string;
theme: typeof theme;
}

function PostCard({ slug, title, subtitle, date, category, theme }: Props) {
return (
<Article>
<h3>
<NextLink href={`/${slug}`} passHref>
<Link underline css={{ color: theme.colors.text.value }}>
{title}
</Link>
</NextLink>
</h3>
<Small theme={theme}>
<DateAndCategoryLink date={date} category={category} />
</Small>
{subtitle && <P>{subtitle}</P>}
</Article>
);
}

export default PostCard;

const Article = styled.article`
width: 100%;
margin-bottom: 2.5rem;
`;

const Small = styled.small<{ theme: NextUITheme | undefined }>`
color: ${({ theme }) => theme.colors.accents6.value};
`;

const P = styled.p`
width: 100%;
margin: 0;
`;
Loading

2 comments on commit d413ec5

@vercel
Copy link

@vercel vercel bot commented on d413ec5 Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

comet-land-blog – ./apps/blog

comet-land-blog-git-main-hyesungoh.vercel.app
comet-land-blog-hyesungoh.vercel.app
comet-land-blog.vercel.app

@vercel
Copy link

@vercel vercel bot commented on d413ec5 Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

comet-land-resume – ./apps/resume

comet-land-resume-hyesungoh.vercel.app
comet-land-resume.vercel.app
comet-land-resume-git-main-hyesungoh.vercel.app

Please sign in to comment.