사이트 설정

이 페이지

사이트 설정은 사이트의 전역 구성값입니다: 제목, 태그라인, 로고, 소셜 링크, 표시 설정 등. 관리자는 관리 인터페이스에서 이를 관리하고, 템플릿에서 접근합니다.

설정 조회

getSiteSettings()로 모든 사이트 설정을 가져옵니다:

---
import { getSiteSettings } from "emdash";

const settings = await getSiteSettings();
---

<html lang="en">
  <head>
    <title>{settings.title}</title>
    {settings.favicon && (
      <link rel="icon" href={settings.favicon.url} />
    )}
  </head>
  <body>
    <header>
      {settings.logo ? (
        <img src={settings.logo.url} alt={settings.logo.alt || settings.title} />
      ) : (
        <span class="site-title">{settings.title}</span>
      )}
      {settings.tagline && <p class="tagline">{settings.tagline}</p>}
    </header>
    <slot />
  </body>
</html>

사용 가능한 설정

EmDash가 제공하는 핵심 설정:

interface SiteSettings {
	// 아이덴티티
	title: string;
	tagline?: string;
	logo?: MediaReference;
	favicon?: MediaReference;

	// URL
	url?: string;

	// 표시
	postsPerPage: number;
	dateFormat: string;
	timezone: string;

	// 소셜
	social?: {
		twitter?: string;
		github?: string;
		facebook?: string;
		instagram?: string;
		linkedin?: string;
		youtube?: string;
	};
}

interface MediaReference {
	mediaId: string;
	alt?: string;
	url?: string; // 확인된 URL(읽기 전용)
}

개별 설정 가져오기

getSiteSetting()으로 키별 단일 설정을 가져옵니다:

import { getSiteSetting } from "emdash";

const title = await getSiteSetting("title");
// 반환: "My Site" 또는 undefined

const logo = await getSiteSetting("logo");
// 반환: { mediaId: "...", url: "/_emdash/api/media/file/..." }

한두 개 값만 필요하고 전부 가져오고 싶지 않을 때 유용합니다.

컴포넌트에서 설정 사용

사이트 헤더

---
import { getSiteSettings, getMenu } from "emdash";

const settings = await getSiteSettings();
const menu = await getMenu("primary");
---

<header class="header">
  <a href="/" class="logo">
    {settings.logo ? (
      <img
        src={settings.logo.url}
        alt={settings.logo.alt || settings.title}
        width="150"
        height="50"
      />
    ) : (
      <span class="site-name">{settings.title}</span>
    )}
  </a>

  {menu && (
    <nav>
      {menu.items.map(item => (
        <a href={item.url}>{item.label}</a>
      ))}
    </nav>
  )}
</header>

소셜 링크

---
import { getSiteSetting } from "emdash";

const social = await getSiteSetting("social");

const platforms = [
  { key: "twitter", label: "Twitter", baseUrl: "https://twitter.com/" },
  { key: "github", label: "GitHub", baseUrl: "https://github.com/" },
  { key: "facebook", label: "Facebook", baseUrl: "https://facebook.com/" },
  { key: "instagram", label: "Instagram", baseUrl: "https://instagram.com/" },
  { key: "linkedin", label: "LinkedIn", baseUrl: "https://linkedin.com/in/" },
  { key: "youtube", label: "YouTube", baseUrl: "https://youtube.com/@" },
] as const;
---

{social && (
  <div class="social-links">
    {platforms.map(({ key, label, baseUrl }) => (
      social[key] && (
        <a
          href={baseUrl + social[key]}
          rel="noopener noreferrer"
          target="_blank"
          aria-label={label}
        >
          {label}
        </a>
      )
    ))}
  </div>
)}

SEO 메타 태그

---
import { getSiteSettings } from "emdash";

interface Props {
  title?: string;
  description?: string;
  image?: string;
}

const settings = await getSiteSettings();
const {
  title,
  description = settings.tagline,
  image,
} = Astro.props;

const documentTitle = title
  ? `${title} | ${settings.title}`
  : settings.title;
const ogTitle = title ?? settings.title;
---

<title>{documentTitle}</title>
{description && <meta name="description" content={description} />}

<!-- Open Graph -->
<meta property="og:title" content={ogTitle} />
{description && <meta property="og:description" content={description} />}
{image && <meta property="og:image" content={image} />}
{settings.url && <meta property="og:url" content={settings.url + Astro.url.pathname} />}

<!-- Twitter -->
{settings.social?.twitter && (
  <meta name="twitter:site" content={settings.social.twitter} />
)}
<meta name="twitter:card" content={image ? "summary_large_image" : "summary"} />

날짜 형식

dateFormattimezone 설정으로 일관된 날짜 표시:

---
import { getSiteSetting } from "emdash";

interface Props {
  date: string;
}

const { date } = Astro.props;
const dateFormat = await getSiteSetting("dateFormat") || "MMMM d, yyyy";
const timezone = await getSiteSetting("timezone") || "UTC";

// Intl.DateTimeFormat 또는 date-fns 같은 라이브러리로 형식 지정
const formatted = new Intl.DateTimeFormat("ko-KR", {
  timeZone: timezone,
  dateStyle: "long",
}).format(new Date(date));
---

<time datetime={date}>{formatted}</time>

관리 API

프로그래밍 방식으로 설정을 가져옵니다:

GET /_emdash/api/settings

응답:

{
	"title": "My EmDash Site",
	"tagline": "A modern CMS",
	"logo": {
		"mediaId": "med_123",
		"url": "/_emdash/api/media/file/abc123"
	},
	"postsPerPage": 10,
	"dateFormat": "MMMM d, yyyy",
	"timezone": "America/New_York",
	"social": {
		"twitter": "@handle",
		"github": "username"
	}
}

설정 업데이트(부분 업데이트 지원):

POST /_emdash/api/settings
Content-Type: application/json

{
  "title": "New Site Title",
  "tagline": "Updated tagline"
}

제공된 필드만 변경됩니다. 생략된 필드는 현재 값을 유지합니다.

미디어 참조

logofavicon 설정은 미디어 참조를 저장합니다. 읽을 때 EmDash가 url 속성을 자동으로 확인합니다:

const logo = await getSiteSetting("logo");
// {
//   mediaId: "med_123",
//   alt: "Site logo",
//   url: "/_emdash/api/media/file/abc123"
// }

API로 업데이트할 때는 mediaId만 제공합니다:

{
	"logo": {
		"mediaId": "med_456",
		"alt": "New logo"
	}
}

API 참조

getSiteSettings()

확인된 미디어 URL과 함께 모든 사이트 설정을 가져옵니다.

반환: Promise<Partial<SiteSettings>>

설정되지 않은 값은 undefined인 부분 객체를 반환합니다.

getSiteSetting(key)

키별로 단일 설정을 가져옵니다.

매개변수:

  • key — 설정 키 (예: "title", "logo", "social")

반환: Promise<SiteSettings[K] | undefined>

타입 안전: 반환 타입이 요청한 키와 일치합니다.