Astro 사이트 빌더
Astro 5를 사용하여 프로덕션 준비가 완료된 정적 웹사이트를 구축합니다. 포트폴리오, 전자책 플랫폼, 블로그, 마케팅 사이트 및 문서 사이트를 다룹니다.
사용 시기
- 사용자가 Astro 사이트, 포트폴리오 또는 블로그 구축을 요청하는 경우
- 사용자가 Cloudflare Pages에 배포하려는 경우
- 사용자가 사이드바 탐색 기능이 있는 전자책/문서 사이트를 필요로 하는 경우
- 사용자가 sitemap, 메타 태그, 구조화된 데이터를 포함한 SEO 최적화 정적 사이트를 원하는 경우
- 사용자가 "Astro", "Cloudflare Pages", "JAMstack 정적 사이트"를 언급하는 경우
빠른 시작
# 프로젝트 생성
npm create astro@latest my-site -- --template minimal
cd my-site
# 핵심 종속성 설치
npm install @astrojs/sitemap
# 빌드 및 미리보기
npm run build # dist/ 폴더에 출력
npm run preview # 로컬 미리보기 서버
프로젝트 구조
project/
├── astro.config.mjs
├── package.json
├── tsconfig.json
├── public/
│ ├── robots.txt
│ └── _headers # Cloudflare 보안 헤더
├── src/
│ ├── layouts/
│ │ ├── BaseLayout.astro # 사이트 전체 쉘 (헤더, 푸터, SEO)
│ │ └── EbookLayout.astro # 콘텐츠 레이아웃 (사이드바, 진행률 표시줄)
│ └── pages/
│ ├── index.astro # 홈페이지
│ ├── blog.astro
│ └── ebook/
│ ├── index.astro # 전자책 목록
│ └── video-editing/
│ └── index.astro # 단일 전자책 페이지
└── dist/ # 빌드 출력물 (이 폴더를 배포)
Astro 설정 (Cloudflare 최적화)
// astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
site: 'https://yourdomain.com',
integrations: [sitemap()],
prefetch: true,
build: {
inlineStylesheets: 'auto', // FCP 단축을 위해 중요 CSS 인라인화
},
});
SEO 패턴 (BaseLayout)
모든 페이지는 props를 통해 전체 SEO를 얻습니다.
---
export interface Props {
title: string;
description?: string;
canonical?: string;
image?: string;
type?: string; // 'website' | 'article'
}
---
<head>에 포함:
<title>(형식:페이지 제목 | 사이트 이름)<meta name="description"><link rel="canonical">- Open Graph 태그 (og:type, og:title, og:description, og:image, og:url)
- Twitter 카드 메타 태그
- JSON-LD 구조화된 데이터 (Person, Organization, Article 중 적절한 것)
<meta name="robots" content="index, follow">
EbookLayout 패턴
사이드바 탐색 기능이 있는 장문 콘텐츠용. 전체 CSS는 references/ebook-layout-css.md를 참조하세요.
기능
- 사이드바 탐색 — 고정 왼쪽 사이드바, 스크롤 위치에 따른 활성 상태 추적 기능이 있는 챕터 링크
- 진행률 표시줄 — 읽기 진행률(0-100%)을 표시하는 상단 고정 막대, 청록색에서 남색으로 그라데이션 채우기
- 맨 위로 버튼 — 오른쪽 하단 고정, 400px 스크롤 후 표시
- 작성자 크레딧 — 콘텐츠 하단에 아바타 원형 + 이름/역할
- 코드 블록 — 어두운 배경(
#1e293b), 상단 그라데이션 악센트 막대, 고정폭 글꼴, 가로 스크롤 - 표 — 그라데이션 헤더, 교차 행 색상, 호버 효과, 둥근 테두리
- 정보 상자 — 4가지 유형: 정보(파란색), 경고(호박색), 팁(초록색), 위험(빨간색), 각각 SVG 아이콘 포함
- 인쇄 스타일 — 사이드바/진행률 표시줄/탐색 숨김, 콘텐츠 확장, 페이지 나누기 규칙
- 반응형 — 3개의 중단점 (960px 사이드바 숨김, 600px 간결, 모바일 스택)
CSS 전략: <style slot="head">에 is:global 사용하기
EbookLayout CSS는 is:global을 사용해야 슬롯된 콘텐츠에 스타일이 적용됩니다:
<style slot="head" is:global>
/* 여기의 모든 클래스는 슬롯된 콘텐츠에 적용됩니다 */
.ebook-content h1 { ... }
.callout { ... }
.callout-info { ... }
</style>
is:global 없이 EbookLayout에서 정의된 .callout-info와 같은 클래스는 <EbookLayout>을 사용하는 페이지 컴포넌트의 요소에 적용되지 않습니다.
EbookLayout Props 인터페이스
export interface Props {
title: string;
description?: string;
chapters: { slug: string; title: string; number: number }[];
currentSlug: string;
ebookTitle: string;
ebookDescription?: string;
author?: string; // 기본값 'Ahmad Asri Zalmi'
}
콘텐츠 페이지 패턴
각 전자책 페이지는 챕터 배열을 정의하고 EbookLayout에 전달합니다:
---
import EbookLayout from '../../../layouts/EbookLayout.astro';
const chapters = [
{ slug: 'index', title: 'Pendahuluan', number: 1 },
{ slug: 'topic-a', title: 'Topic A', number: 2 },
];
---
<EbookLayout title="페이지 제목" description="SEO 설명" chapters={chapters}
currentSlug="ebook-slug" ebookTitle="전자책 제목" ebookDescription="부제" author="작성자 이름">
<h1 id="index">페이지 제목</h1>
<p class="ebook-subtitle">부제 텍스트</p>
<div class="ebook-meta">
<!-- SVG 사용자 아이콘 + 작성자 이름 + SVG 달력 아이콘 + 연도 -->
</div>
<!-- 챕터: h2의 id가 슬러그와 일치해야 함 -->
</EbookLayout>
제목/헤더 블록 (필수)
<h1 id="index">제목</h1>
<p class="ebook-subtitle">부제</p>
<div class="ebook-meta">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
<span>작성자 이름</span>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-left:0.5rem"><rect x="3" y="4" width="18" height="18" rx="2" ry="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>
<span>2026</span>
</div>
정보 상자 HTML (4가지 유형)
<!-- 정보 (파란색 #3b82f6) -->
<div class="callout callout-info">
<svg class="callout-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>
<div class="callout-content"><strong>제목</strong><p>내용.</p></div>
</div>
<!-- 경고 (주황색 #f59e0b) -->
<div class="callout callout-warning">
<svg class="callout-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
<div class="callout-content"><strong>제목</strong><p>내용.</p></div>
</div>
<!-- 팁 (초록색 #22c55e) -->
<div class="callout callout-tip">
<svg class="callout-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
<div class="callout-content"><strong>제목</strong><p>내용.</p></div>
</div>
<!-- 위험 (빨간색 #ef4444) -->
<div class="callout callout-danger">
<svg class="callout-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>
<div class="callout-content"><strong>제목</strong><p>내용.</p></div>
</div>
리소스 링크 섹션 (전자책 끝)
<div class="resource-links">
<h3>리소스 및 링크</h3>
<ul>
<li>
<a href="https://..." target="_blank" rel="noopener">링크 텍스트</a>
<span class="desc">짧은 설명</span>
</li>
</ul>
</div>
set:html을 사용한 코드 블록
프론트매터에서 코드 문자열을 정의하고 set:html로 렌더링합니다:
---
const code_example = `# 쉘 명령어
npm run build`;
---
<pre><code set:html={code_example}></code></pre>
사이드바 활성 상태 (JS)
const navLinks = document.querySelectorAll('[data-nav-link]');
const headings = [];
navLinks.forEach(link => {
const id = link.getAttribute('href').slice(1);
const el = document.getElementById(id);
if (el) headings.push({ el, link });
});
const updateActive = () => {
let active = headings[0];
for (const h of headings) {
if (h.el.getBoundingClientRect().top <= 100) active = h;
}
navLinks.forEach(l => l.classList.remove('active'));
if (active) active.link.classList.add('active');
};
window.addEventListener('scroll', updateActive, { passive: true });
정보 상자 HTML
<div class="callout callout-info">
<svg class="callout-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/>
</svg>
<div class="callout-content">
<strong>제목</strong>
<p>내용 텍스트.</p>
</div>
</div>
가져오기 경로 규칙
Astro는 Vite의 파일 기반 라우팅을 사용합니다. 가져오기 경로는 가져오는 파일을 기준으로 상대적입니다:
| 파일 위치 | 레이아웃 가져오기 위치 |
|---|---|
src/pages/index.astro | ../layouts/BaseLayout.astro |
src/pages/blog.astro | ../layouts/BaseLayout.astro |
src/pages/ebook/index.astro | ../../layouts/BaseLayout.astro |
src/pages/ebook/video-editing/index.astro | ../../../layouts/BaseLayout.astro |
src/의 디렉토리 깊이를 세어 ../ 세그먼트 수를 결정합니다.
Cloudflare Pages 배포
빌드 설정
| 설정 | 값 |
|---|---|
| 프레임워크 사전 설정 | Astro |
| 빌드 명령어 | npm run build |
| 빌드 출력 디렉토리 | dist |
| Node.js 버전 | 18+ (환경 변수 NODE_VERSION으로 설정) |
보안 헤더 (public/_headers)
/*
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=()
/assets/*
Cache-Control: public, max-age=31536000, immutable
리다이렉트 (public/_redirects)
/old-path /new-path 301
Wrangler CLI 배포 (직접 업로드)
# 먼저 빌드
npm run build
# Cloudflare Pages에 배포
CLOUDFLARE_API_TOKEN=cfut_xxx CLOUDFLARE_ACCOUNT_ID=xxx \
npx wrangler pages deploy dist --project-name=my-site --branch=main
# 미리보기 배포 (main이 아닌 브랜치)
npx wrangler pages deploy dist --project-name=my-site --branch=staging
독립 실행형 HTML 일관성
독립 실행형 HTML 전자책 파일이 public/ebook/에 있을 때(Astro 레이아웃을 우회), 공유 헤더, 사이드바, 색 구성표 및 작성자 설명을 수동으로 주입해야 합니다. 전체 패턴은 references/standalone-html-consistency.md를 참조하세요. 내용은 다음과 같습니다:
- 로고 + 탐색 기능이 있는 고정 헤더 주입 (충돌 방지를 위한 인라인 CSS)
- 고정 사이드바 위에 헤더를 추가할 때 사이드바
top/height조정 - 색 구성표 통일 (CSS 변수, rgba, 그라데이션 — 모두 업데이트해야 함)
- 맨 위로 버튼 주입 (CSS + HTML + JS)
- 패치 도구 JS 중첩 문제 (패치 후 항상 닫는 중괄호 확인)
- 작성자 설명 일관성 체크리스트
문제점
자세한 주의 사항은 references/astro5-pitfalls.md를 참조하세요. 요약:
- HTML 내 중괄호 —
{와}는 JSX 표현식입니다. 코드 블록에는set:html을 사용하세요. lightningcss가 번들되지 않음 — 별도로 설치하거나cssMinify: 'lightningcss'를 사용하지 마세요.- 가져오기 경로 깊이 — 디렉토리 구조와 정확히 일치해야 합니다.
- 이모지 없음 — 인라인 SVG 아이콘을 사용하세요 (전자책 생성기 스킬의 사용자 선호도).
set:html은 빈/자체 닫힘 요소 또는 슬롯에서만 사용 가능 —set:html을 사용할 때는 자식을 가질 수 없습니다.- Astro 스코프 CSS —
<style>의 클래스는 컴포넌트별로 스코프가 지정됩니다. 공유 클래스에는<style is:global>또는:global(.class)를 사용하세요. EbookLayout은 슬롯된 콘텐츠에 스타일이 적용되도록 반드시<style slot="head" is:global>을 사용해야 합니다. data-astro-cid스코프 불일치 — BaseLayout의.container클래스는 페이지 컴포넌트의 요소에 적용되지 않습니다. 전역 클래스 필요:.container,.btn,.section,.grid-*등.- JS 클래스 토글링 + 스코프 CSS = 무음 실패 — 동적으로 클래스를 추가/제거하는 JavaScript(예: IntersectionObserver가 스크롤 시
.fade-in추가)는 Astro의 스코프 선택자와 일치하지 않습니다. Astro는.fade-in을.fade-in[data-astro-cid-xxxx]로 스코프 지정하지만, JS는 일반.fade-in클래스를 추가합니다. 증상: 섹션이 영원히 보이지 않습니다(opacity:0). 수정: (a) 애니메이션 클래스에<style is:global>사용, (b) 스코프 스타일에서:global(.fade-in)사용, 또는 (c) CSS 애니메이션 클래스를 완전히 제거하고 콘텐츠를 즉시 렌더링합니다. 애니메이션이 중요하지 않은 SSR 사이트의 경우 옵션 (c)가 가장 간단합니다. 자세한 내용은references/astro5-pitfalls.md의 #9를 참조하세요. - 독립 실행형 HTML 사이드바 오프셋 — 독립 실행형 전자책 HTML 파일에 고정 헤더를 주입할 때 항상 고정 사이드바
top을0에서 헤더 높이(~56px)로 조정하고height: calc(100vh - 56px)로 설정하세요. 이 작업을 잊으면 사이드바 콘텐츠가 헤더 뒤에 숨겨집니다.
안티패턴
npm install lightningcss없이cssMinify: 'lightningcss'를 사용하지 마세요.<pre><code>블록 안에{variable}을 넣지 마세요 — Astro가 JSX로 구문 분석합니다.- 아이콘에 이모지를 사용하지 마세요 — 인라인 SVG를 사용하세요.
- SEO를 위해
robots.txt와 sitemap을 생략하지 마세요. - 모바일을 위해
<meta name="viewport">를 잊지 마세요. - 사이트 URL을 하드코딩하지 말고 설정에서
Astro.site를 사용하세요.