diff --git a/app/[lang]/posts/[postPath]/page.tsx b/app/[lang]/posts/[postPath]/page.tsx index 7ab6d48..6f3bc59 100644 --- a/app/[lang]/posts/[postPath]/page.tsx +++ b/app/[lang]/posts/[postPath]/page.tsx @@ -13,8 +13,6 @@ import { getSession } from '@/lib/auth/session'; import { formatDate } from '@/lib/dashboard/format'; import { localizedPermanentRedirect } from '@/lib/i18n/request'; import { getLocale, initLingui } from '@/lib/i18n/server'; -import { isGithubAvatar } from '@/lib/posts/avatar'; -import { getGithubProfileUrl } from '@/lib/posts/github-profile'; import { buildPostMetadata, getSiteOrigin } from '@/lib/posts/metadata'; import { buildBlogPostingJsonLd, serializeJsonLd } from '@/lib/seo/json-ld'; import { localizePath } from '@/lib/i18n/config'; @@ -93,8 +91,8 @@ export default async function PostPage({ params }: PostPageProps) { } const isRepublished = post.updatedAt.getTime() > post.publishedAt.getTime(); - // 작성자 GitHub 아이디가 있으면 아바타·이름을 GitHub 프로필 새 탭 링크로 - const authorProfileUrl = getGithubProfileUrl(post.author.githubLogin); + // 글쓴이가 프로필을 보이기로 했으면 아바타·이름을 GitHub 프로필 새 탭 링크로 + const authorProfileUrl = post.author.profileUrl; // 검색 결과의 글 정보 (schema.org BlogPosting, 대표 주소는 게시할 때의 언어 기준) const origin = getSiteOrigin(); const canonicalUrl = @@ -119,7 +117,7 @@ export default async function PostPage({ params }: PostPageProps) { ); const author = ( <> - {isGithubAvatar(post.author.image) && ( + {post.author.image && ( { + const handlePublish = async ( + visibility: PostVisibility, + authorDisplay: AuthorDisplaySettings, + ) => { if (!draft || !editor || isPending) { return; } @@ -141,6 +145,7 @@ const PublishActions = ({ JSON.stringify(editor.getJSON()), visibility, locale, + authorDisplay, ); if (result.status === 'published') { @@ -283,18 +288,21 @@ const PublishActions = ({ )} )} - {openDialog === 'publish' && ( + {openDialog === 'publish' && draft && ( void handlePublish(visibility)} + onSubmit={(visibility, authorDisplay) => + void handlePublish(visibility, authorDisplay) + } onClose={closeDialog} /> )} diff --git a/components/studio/publish-author-fields.tsx b/components/studio/publish-author-fields.tsx new file mode 100644 index 0000000..d77da70 --- /dev/null +++ b/components/studio/publish-author-fields.tsx @@ -0,0 +1,171 @@ +'use client'; + +import { useId } from 'react'; +import Image from 'next/image'; +import { Trans, useLingui } from '@lingui/react/macro'; +import { + AUTHOR_NICKNAME_MAX_LENGTH, + getNicknameProblem, + normalizeAuthorNickname, + resolvePostAuthor, + type AuthorDisplayDraft, + type AuthorDisplayMode, + type AuthorIdentity, +} from '@/lib/posts/author-display'; + +interface PublishAuthorFieldsProps { + identity: AuthorIdentity; + value: AuthorDisplayDraft; + onChange: (value: AuthorDisplayDraft) => void; +} + +/** + * 게시 창의 작성자 표시 선택 + * - GitHub 이름 / GitHub 아이디(있을 때만) / 별명 중 하나 + 프로필 사진·링크 표시 여부 + * - 글에 실제로 보일 모습을 아래에 미리 보여 줌 + */ +const PublishAuthorFields = ({ + identity, + value, + onChange, +}: PublishAuthorFieldsProps) => { + const { t } = useLingui(); + const nicknameId = useId(); + const problemId = useId(); + const problem = getNicknameProblem(value); + const preview = resolvePostAuthor(identity, { + mode: value.mode, + nickname: normalizeAuthorNickname(value.nickname), + showProfile: value.showProfile, + }); + const options: Array<{ + mode: AuthorDisplayMode; + label: string; + hint?: string; + }> = [ + { mode: 'name', label: t`GitHub 이름`, hint: identity.name }, + ...(identity.githubLogin + ? [ + { + mode: 'login' as const, + label: t`GitHub 아이디`, + hint: identity.githubLogin, + }, + ] + : []), + { mode: 'nickname', label: t`별명` }, + ]; + + return ( +
+ + 작성자 표시 + + {options.map((option) => ( + + ))} + {value.mode === 'nickname' && ( +
+ + + onChange({ ...value, nickname: event.target.value }) + } + placeholder={t`글에 보일 별명 (${AUTHOR_NICKNAME_MAX_LENGTH}자 이내)`} + aria-invalid={problem === 'invalid'} + aria-describedby={problem ? problemId : undefined} + className={`h-9 w-full rounded border bg-white px-3 text-[13px] leading-[normal] text-ink outline-none placeholder:text-ink-subtle ${ + problem === 'invalid' + ? 'border-danger' + : 'border-line focus:border-brand' + }`} + /> + {problem === 'invalid' && ( +

+ + 별명은 {AUTHOR_NICKNAME_MAX_LENGTH}자 이내로, 보이지 않는 문자 + 없이 입력해 주세요 + +

+ )} + {problem === 'empty' && ( +

+ 별명을 입력해야 게시할 수 있습니다 +

+ )} +
+ )} + +
+ + 글에는 이렇게 보여요 + + + {preview.image && ( + + )} + + {problem ? t`(별명)` : preview.name} + + + + {preview.profileUrl ? ( + 이름을 누르면 GitHub 프로필이 열립니다 + ) : ( + GitHub 프로필로 연결되지 않습니다 + )} + +
+
+ ); +}; + +export default PublishAuthorFields; diff --git a/components/studio/publish-dialog.tsx b/components/studio/publish-dialog.tsx index 688a6b2..316fc01 100644 --- a/components/studio/publish-dialog.tsx +++ b/components/studio/publish-dialog.tsx @@ -5,11 +5,19 @@ import { msg } from '@lingui/core/macro'; import type { MessageDescriptor } from '@lingui/core'; import { Plural, Trans, useLingui } from '@lingui/react/macro'; import DialogFrame from '@/components/shared/dialog-frame'; +import PublishAuthorFields from '@/components/studio/publish-author-fields'; import { BRAND_BUTTON_CLASS, OUTLINE_BUTTON_CLASS, } from '@/components/studio/studio-styles'; import type { PostVisibility } from '@/lib/db/schema'; +import { + getNicknameProblem, + normalizeAuthorNickname, + toAuthorDisplayDraft, + type AuthorDisplaySettings, +} from '@/lib/posts/author-display'; +import type { PublishAuthor } from '@/lib/studio/queries'; // 게시 창 안에 보이는 실패 사유 (서버 응답과 요청 실패) export type PublishFailure = @@ -52,6 +60,8 @@ interface PublishDialogProps { isRepublish: boolean; // 처음 선택돼 있을 공개 범위 (다시 게시면 현재 값) initialVisibility: PostVisibility; + // 작성자 표시 미리보기용 GitHub 정보와 처음 선택돼 있을 설정 + author: PublishAuthor; // 비공개 저장소의 초안이면 코드가 공개된다는 경고를 보임 isPrivateRepository: boolean; // 본문에 남은 빈칸 노드 수 (채웠든 아니든 하나라도 있으면 게시할 수 없음) @@ -60,17 +70,21 @@ interface PublishDialogProps { hasNoTitle: boolean; failure: PublishFailure | null; isPending: boolean; - onSubmit: (visibility: PostVisibility) => void; + onSubmit: ( + visibility: PostVisibility, + authorDisplay: AuthorDisplaySettings, + ) => void; onClose: () => void; } /** - * 게시 확인 창: 공개 범위 선택, 비공개 저장소 경고, 게시할 수 없는 사유 표시 - * - 열 때마다 새로 마운트되어 공개 범위 선택이 초기화됨 + * 게시 확인 창: 공개 범위·작성자 표시 선택, 비공개 저장소 경고, 게시할 수 없는 사유 표시 + * - 열 때마다 새로 마운트되어 선택이 초기화됨 */ const PublishDialog = ({ isRepublish, initialVisibility, + author, isPrivateRepository, blankCount, hasNoTitle, @@ -81,7 +95,12 @@ const PublishDialog = ({ }: PublishDialogProps) => { const { t, i18n } = useLingui(); const [visibility, setVisibility] = useState(initialVisibility); + const [authorDraft, setAuthorDraft] = useState(() => + toAuthorDisplayDraft(author.initial), + ); const hasBlanks = blankCount > 0; + const hasNicknameProblem = getNicknameProblem(authorDraft) !== null; + const cannotSubmit = hasBlanks || hasNoTitle || hasNicknameProblem; const reason: PublishFailure | null = failure ?? (!hasBlanks && hasNoTitle ? 'no_title' : null); @@ -95,8 +114,15 @@ const PublishDialog = ({ onSubmit={(event) => { event.preventDefault(); - if (!isPending && !hasBlanks && !hasNoTitle) { - onSubmit(visibility); + if (!isPending && !cannotSubmit) { + onSubmit(visibility, { + mode: authorDraft.mode, + nickname: + authorDraft.mode === 'nickname' + ? normalizeAuthorNickname(authorDraft.nickname) + : null, + showProfile: authorDraft.showProfile, + }); } }} className="flex flex-col gap-6" @@ -135,6 +161,11 @@ const PublishDialog = ({ ))} + {isPrivateRepository && (

비공개 저장소의 코드가 본문에 그대로 공개됩니다 @@ -169,7 +200,7 @@ const PublishDialog = ({