From 67ebd5713fa296c4910aa328722c7ec23ac1762e Mon Sep 17 00:00:00 2001 From: Jayden Date: Mon, 30 Nov 2026 13:41:59 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=ED=95=A0=20?= =?UTF-8?q?=EB=95=8C=20=EC=9E=91=EC=84=B1=EC=9E=90=20=ED=91=9C=EC=8B=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EA=B3=BC=20GitHub=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=20=EB=85=B8=EC=B6=9C=EC=9D=84=20=EA=B3=A0=EB=A5=BC=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EA=B2=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 게시 창에서 GitHub 이름 / GitHub 아이디 / 별명 중 표시 방식을 고르고, GitHub 프로필 사진·링크 표시를 켜고 끌 수 있음 - 설정은 글마다 저장하고, 처음 게시하는 글은 가장 최근에 게시한 글의 설정을 따름 - 글 상세, 검색용 정보(JSON-LD), OG 정보·이미지가 같은 표시 설정을 씀 - 별명은 30자 이내, 제어·폭 없는·방향 바꾸는 문자는 받지 않음 (DB 제약으로 별명 방식은 별명이 꼭 있어야 함) - 기존 글은 GitHub 이름과 프로필 사진·링크 표시를 그대로 유지 Co-Authored-By: Claude Opus 5.5 --- app/[lang]/posts/[postPath]/page.tsx | 8 +- components/studio/publish-actions.tsx | 14 +- components/studio/publish-author-fields.tsx | 171 ++ components/studio/publish-dialog.tsx | 43 +- drizzle/0030_nasty_lethal_legion.sql | 5 + drizzle/meta/0030_snapshot.json | 2781 +++++++++++++++++++ drizzle/meta/_journal.json | 7 + lib/actions/posts.ts | 20 +- lib/db/schema/post.ts | 30 +- lib/posts/author-display.test.ts | 175 ++ lib/posts/author-display.ts | 131 + lib/posts/metadata.test.ts | 2 +- lib/posts/queries.ts | 28 +- lib/studio/queries.ts | 109 +- locales/en.po | 109 +- locales/en.ts | 2 +- locales/ko.po | 109 +- locales/ko.ts | 2 +- 18 files changed, 3646 insertions(+), 100 deletions(-) create mode 100644 components/studio/publish-author-fields.tsx create mode 100644 drizzle/0030_nasty_lethal_legion.sql create mode 100644 drizzle/meta/0030_snapshot.json create mode 100644 lib/posts/author-display.test.ts create mode 100644 lib/posts/author-display.ts 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..f4cbcbb --- /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 type { AuthorDisplayMode } from '@/lib/db/schema'; +import { + AUTHOR_NICKNAME_MAX_LENGTH, + getNicknameProblem, + normalizeAuthorNickname, + resolvePostAuthor, + type AuthorDisplayDraft, + 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 = ({