Skip to content

Commit 16ea178

Browse files
committed
update post
1 parent 5b990c0 commit 16ea178

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

components/header.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { DialogTitle, DialogDescription } from "@radix-ui/react-dialog";
1919
import Link from "next/link";
2020
import { Command } from "cmdk";
2121
import { ScrollArea } from "@/components/ui/scroll-area";
22-
import { cn } from "@/lib/utils";
22+
import { cn, getImagePath } from "@/lib/utils";
2323
import { Badge } from "@/components/ui/badge";
2424
import { usePosts } from "@/contexts/posts-context";
2525
import { motion } from "framer-motion";
@@ -138,11 +138,12 @@ export default function Header() {
138138
transition={{ type: "spring", stiffness: 500, damping: 20 }}
139139
>
140140
<Image
141-
src="/lazydino-logo3.png"
141+
src={getImagePath("/lazydino-logo3.png")}
142142
alt="lazydino.dev"
143143
className="h-full w-full object-cover"
144144
width={80}
145145
height={80}
146+
unoptimized
146147
/>
147148
</motion.div>
148149
<span className="text-base sm:text-lg md:text-xl font-bold group-hover:text-primary transition-colors">

components/markdown-renderer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Badge } from "./ui/badge";
77
import { Element } from "hast";
88
import CodeBlock from "./code-block";
99
import { motion } from "framer-motion";
10+
import { getImagePath } from "@/lib/utils";
1011
import remarkCallout from "@r4ai/remark-callout";
1112

1213
export interface MarkdownRendererProps {
@@ -303,13 +304,14 @@ export default function MarkdownRenderer({
303304
>
304305
<div className="absolute inset-0 bg-gradient-to-tr from-primary/5 to-transparent z-0"></div>
305306
<Image
306-
src={src || ""}
307+
src={getImagePath(src || "")}
307308
alt={alt || ""}
308309
width={1200}
309310
height={630}
310311
className="w-full h-auto object-cover transition-transform duration-500 group-hover:scale-[1.03] relative z-10"
311312
sizes="(max-width: 640px) 95vw, (max-width: 768px) 85vw, (max-width: 1024px) 75vw, 50vw"
312313
loading="lazy"
314+
unoptimized
313315
/>
314316
</div>
315317
{alt && (

lib/utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@ export function cn(...inputs: ClassValue[]) {
66
return twMerge(clsx(inputs));
77
}
88

9+
/**
10+
* GitHub Pages와 로컬 개발 환경에서 이미지 경로를 올바르게 처리하는 유틸리티 함수
11+
*/
12+
export function getImagePath(src: string): string {
13+
// 이미 절대 URL인 경우 그대로 반환
14+
if (src.startsWith('http://') || src.startsWith('https://')) {
15+
return src;
16+
}
17+
18+
// 상대 경로인 경우 baseUrl 고려
19+
// process.env.NODE_ENV === 'production'이 정적 빌드 시에는 작동하지 않을 수 있으므로,
20+
// 실제 배포 환경인지 확인하는 방법 사용
21+
const baseUrl = process.env.NEXT_PUBLIC_BASE_PATH || '';
22+
23+
// 이미 슬래시로 시작하는 경로라면
24+
if (src.startsWith('/')) {
25+
return `${baseUrl}${src}`;
26+
}
27+
28+
// 상대 경로인 경우
29+
return `${baseUrl}/${src}`;
30+
}
31+
932
export interface FolderStructure {
1033
name: string;
1134
type: "folder" | "file";

next.config.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ import type { NextConfig } from "next";
33
const nextConfig: NextConfig = {
44
output: "export",
55
images: {
6-
domains: [
7-
"user-images.githubusercontent.com",
8-
"https://lazy-dinosaur.github.io/",
6+
unoptimized: true, // GitHub Pages에서 이미지 최적화를 비활성화
7+
domains: ["user-images.githubusercontent.com", "lazy-dinosaur.github.io"],
8+
remotePatterns: [
9+
{
10+
protocol: "https",
11+
hostname: "lazy-dinosaur.github.io",
12+
},
913
],
10-
formats: ["image/webp"],
11-
// Remove unoptimized: true to enable image optimization
1214
},
13-
trailingSlash: true, // 정적 서버 라우팅 호환성
14-
/* config options here */
15-
basePath: "",
15+
trailingSlash: true, // 정적 서버 라우팅 호환성
16+
assetPrefix: process.env.NODE_ENV === "production" ? "/my-blog" : "", // GitHub 저장소 이름으로 설정
17+
basePath: process.env.NODE_ENV === "production" ? "/my-blog" : "", // GitHub 저장소 이름으로 설정
1618
};
1719

1820
export default nextConfig;

0 commit comments

Comments
 (0)