Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

공지사항 Content 링크 처리 #343

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useNoticeDetailQuery } from '@/services/notice/queries';
import { color } from '@maru/theme';
import { color, font } from '@maru/theme';
import { Column, Text } from '@maru/ui';
import { flex, formatCreatedAt } from '@maru/utils';
import { convertLink, flex, formatCreatedAt } from '@maru/utils';
import styled from 'styled-components';

interface Props {
Expand All @@ -23,9 +23,7 @@ const NoticeDetailContent = ({ id }: Props) => {
</Text>
</Column>
</NoticeHeader>
<Text fontType="p2" color={color.gray900}>
{noticeDetailData.content}
</Text>
<Content dangerouslySetInnerHTML={{ __html: convertLink(noticeDetailData.content) }} />
SEOKKAMONI marked this conversation as resolved.
Show resolved Hide resolved
</StyledNoticeDetailContent>
) : null;
};
Expand All @@ -45,3 +43,7 @@ const NoticeHeader = styled.div`
border-bottom: 1px solid ${color.gray300};
margin-bottom: 8px;
`;
const Content = styled.div`
${font.p2};
color: ${color.gray900};
`;
6 changes: 6 additions & 0 deletions packages/maru-theme/src/global.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createGlobalStyle } from 'styled-components';
import { reset } from 'styled-reset';
import color from './color';

const GlobalStyle = createGlobalStyle`
${reset}
Expand Down Expand Up @@ -51,6 +52,11 @@ button {
padding: 0;
cursor: pointer;
}

.link {
color: ${color.maruDefault};
text-decoration: underline;
}
`;

export default GlobalStyle;
7 changes: 7 additions & 0 deletions packages/maru-utils/functions/convertLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const convertLink = (content: string): string => {
const pattern = /(https?:\/\/\S+)/g;

return content.replace(pattern, '<a href="$1" class="link">$1</a>').replace(/\n/g, '<br />');
};

export default convertLink;
2 changes: 1 addition & 1 deletion packages/maru-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// function
export { default as convertLink } from './functions/convertLink';
export { default as formatCreatedAt } from './functions/formatCreatedAt';
export { default as formatPostedAt } from './functions/formatPostedAt';
export { default as formatTime } from './functions/formatTime';

// style
export { default as flex } from './styles/flex';