Guidedog 설명서 0.6.3
언어
이 페이지의 내용
Guidedog / 문서 0.6.3

프로젝트 테마 만들기

테마는 같은 내용을 웹과 책에서 읽기 좋게 만듭니다. 이 튜토리얼은 HTML 부분 템플릿·매크로와 모듈형 PDF 템플릿으로 Orbit의 시각적 구성을 통일합니다. 플러그인이나 컴파일러는 필요 없습니다.

1. 실제 프로젝트에서 시작하기

Guidedog 0.6.2 이상을 사용하고, orbit 디렉터리를 만들 부모 폴더에서 실행하세요.

guidedog quickstart orbit -q -p "Orbit Field Notes" -a "Orbit contributors" -v 1.0

생성한 orbit/_templates/book.typ 파일을 같은 위치의 base-book.typ 파일로 이름만 바꿉니다. 페이지 구성, 표지, 머리말, 목차, 코드 스타일과 최적화된 줄바꿈을 제공하므로 보관하세요.

conf.toml, index.rst, reading.rst 파일을 받습니다. 앞의 둘은 orbit 폴더에, 셋째는 orbit/chapters 폴더에 저장합니다. 완성할 구조는 다음과 같습니다.

orbit/
  conf.toml
  index.rst
  chapters/reading.rst
  _templates/
    layout.html
    macros/ui.html
    partials/edition.html
    base-book.typ          # Generated by quickstart; renamed, not replaced.
    book.typ
    palette.typ
  _static/
    guidedog.css           # Generated by quickstart.
    guidedog.js            # Generated by quickstart.
    theme.css

2. 설정 계약 정하기

받은 설정은 로컬 템플릿과 정적 파일 디렉터리를 지정합니다. html_css_files 설정은 기본 CSS 뒤에 스타일을 추가하고, html_context 설정은 Jinja에 값을 전달합니다. PDF 이름도 명시하여 쉽게 찾도록 합니다.

코드 3 orbit/conf.toml
project = "Orbit Field Notes"
author = "Orbit contributors"
version = "1.0"
release = "1.0"
language = "en"
root_doc = "index"
source_suffix = [".rst"]
exclude_patterns = ["_build", "README.md"]
templates_path = ["_templates"]
html_static_path = ["_static"]
html_css_files = ["theme.css"]
numfig = true
pdf_paper_size = "a4"

[html_theme_options]
accent = "#2658a0"

[html_context]
edition_label = "Field edition"

[[pdf_documents]]
root = "index"
file = "orbit-notes.pdf"
title = "Orbit Field Notes"
author = "Orbit contributors"

이 튜토리얼의 경로는 모두 프로젝트 파일입니다. HTML 템플릿은 templates_path 설정으로 찾습니다. PDF 진입점은 소스 아래의 _templates/book.typ 파일이며, 해당 설정을 바꿔도 이동하지 않습니다.

3. HTML 레이아웃 확장하기

layout.html 파일을 orbit/_templates/layout.html 경로에 저장하고 기존 파일 전체를 바꿉니다.

코드 4 orbit/_templates/layout.html
{% extends "!layout.html" %}
{% import "macros/ui.html" as ui %}

{% block extrahead %}
{{ super() }}
<meta name="theme-name" content="Orbit field notes">
{% endblock %}

{% block body %}
<p class="orbit-kicker">{{ ui.tag(edition_label) }}</p>
{{ super() }}
{% endblock %}

{% block footer %}
{{ super() }}
{% include "partials/edition.html" %}
{% endblock %}

!layout.html 표기는 내장 레이아웃을 고릅니다. ! 표시가 없으면 자기 자신을 상속하려 합니다. super() 호출은 부모 블록을 남깁니다. 탐색, 검색, 테마 조작, 접근성 랜드마크는 기본 레이아웃에 맡기고 라벨·메타데이터·판 정보를 더합니다.

테마는 표현을 바꾸고, 빌드 플러그인은 소스·완전한 HTML·생성 에셋을 바꿉니다. 템플릿으로 할 수 없는 작업에는 네이티브 플러그인 작성하기 문서를 참고하세요. 일반 레이아웃 변경에 네이티브 코드는 필요 없습니다.

4. 반복 마크업 모으기

orbit/_templates/macros 및 orbit/_templates/partials 폴더를 만들고, ui.html 및 edition.html 파일을 각각 저장합니다.

코드 5 orbit/_templates/macros/ui.html
{% macro tag(label) %}<span class="orbit-tag">{{ label|e }}</span>{% endmacro %}
코드 6 orbit/_templates/partials/edition.html
<p class="orbit-edition">
  <span>{{ project|e }} / {{ release|e }}</span>
  <a href="{{ pathto('chapters/reading') }}">Reading a measurement</a>
</p>

매크로는 명시적인 입력을 받고 부분 템플릿은 현재 페이지의 문맥을 씁니다. 일반 값은 |e 필터로 이스케이프합니다. 링크는 pathto 함수로 만드세요. chapters/reading.html 경로를 고정하면 중첩 페이지나 다른 빌더에서 깨집니다.

5. 독자의 테마에 맞추기

theme.css 파일을 orbit/_static/theme.css 경로에 저장합니다.

코드 7 orbit/_static/theme.css
/* Typography and measure are shared. Color follows the reader's chosen scheme. */
:root {
  --gd-measure: 43rem;
  --gd-radius: 4px;
  --gd-bg: #fdfbf6;
  --gd-bg-soft: #f3f0e7;
  --gd-text: #202c28;
  --gd-muted: #53605a;
}
:root[data-theme="dark"] {
  --gd-bg: #141c22; --gd-bg-soft: #1b2832;
  --gd-text: #eaf1f6; --gd-muted: #b0c0cb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --gd-bg: #141c22; --gd-bg-soft: #1b2832;
    --gd-text: #eaf1f6; --gd-muted: #b0c0cb;
  }
}
.gd-article { font-family: Georgia, "Noto Serif", serif; font-size: 1.12rem; }
.gd-article p { line-height: 1.7; hyphens: auto; text-wrap: pretty; }
.gd-article :is(h1, h2, h3) { font-weight: 700; hyphens: none; text-wrap: balance; }
.gd-article h1 { font-size: clamp(2.4rem, 5vw, 3.6rem); letter-spacing: -.025em; }
.gd-header { border-top: 3px solid var(--gd-link); }
.orbit-kicker { margin-bottom: 1rem; }
.orbit-tag {
  display: inline-block; padding: .2rem .65rem;
  font: 700 .75rem/1.5 var(--gd-sans); letter-spacing: .08em;
  border: 1px solid var(--gd-link); border-radius: 3px; color: var(--gd-link);
}
.orbit-edition {
  display: flex; flex-wrap: wrap; gap: .5rem 1rem; justify-content: space-between;
  font: .85rem/1.6 var(--gd-sans); color: var(--gd-muted);
}
img.graphviz-adaptive { display: block; margin: 1.5rem auto; padding: 1rem; }
@media print {
  :root { color-scheme: light; --gd-bg: #fff; --gd-text: #202c28; --gd-muted: #53605a; }
  .orbit-tag { color: #202c28; border-color: currentColor; }
  .gd-article p { orphans: 3; widows: 3; }
}

처음에는 밝은 모드입니다. 기존 조작부가 밝게·어둡게·시스템을 선택하고 기억합니다. 명시적인 다크 규칙과 시스템 미디어 쿼리에서 같은 변수를 쓰고, 글자 구성과 간격은 공유합니다. JavaScript를 더 넣을 필요 없습니다. 배경이 바뀌는 곳에 고정된 글자색만 쓰지 마세요.

브라우저 하이픈 처리는 페이지 언어를 따르지만 Typst의 문단 최적화와 같지는 않습니다. 매뉴얼의 선택적 영문 웹 최적화는 읽기 위한 조판 문서를 참고하세요. 이 예제는 브라우저 기본 조판을 씁니다.

현재 빌드에서는 :class: graphviz-adaptive 옵션이 있는 그림이 선택한 모드를 따릅니다. 일반 그림은 원래 색을 보존하며, 이전 호스트도 같은 DOT를 밝은 팔레트로 그립니다. 노드 의미와 인쇄 방식은 개념을 설명하는 다이어그램 문서를 참고하세요.

6. PDF 책 템플릿 감싸기

palette.typ 및 book.typ 파일을 orbit/_templates 폴더에 저장합니다. 새 파일이며 옆의 base-book.typ 파일은 남깁니다.

코드 8 orbit/_templates/palette.typ
#let palette = (
  accent: rgb("#2658a0"),
  size: 11pt,
  serif: ("Libertinus Serif", "New Computer Modern"),
  sans: ("Libertinus Sans", "DejaVu Sans", "Libertinus Serif"),
)
코드 9 orbit/_templates/book.typ
#import "base-book.typ": book as base-book
#import "palette.typ": palette

// Keep the host's parameters explicit. The final positional argument is content.
#let book(
  title: "", author: "", version: "", date: "", lang: "en", paper: "a4",
  numbering: false, logo: none, copyright: "", version-label: "Version", body,
) = base-book(
  title: title, author: author, version: version, date: date, lang: lang,
  paper: paper, numbering: numbering, logo: logo, copyright: copyright,
  version-label: version-label, accent: palette.accent, size: palette.size,
  serif: palette.serif, sans: palette.sans, page-ref: n => [p. #n], body,
)

호스트는 book 함수에 메타데이터와 장의 내용을 전달합니다. 래퍼는 이를 생성한 기본 템플릿에 넘기고 팔레트를 지정합니다. body 내용을 스타일 함수에 전달해야 규칙이 본문에 적용됩니다. 웹 CSS는 PDF에, Typst 템플릿은 HTML에 영향을 주지 않습니다.

기본 템플릿이 언어별 하이픈 처리와 최적화된 줄바꿈을 담당합니다. 래퍼는 이를 유지하면서 웹과 같은 파란 강조색과 문서 참조의 페이지 번호를 더합니다. PDF는 항상 밝은 인쇄용 팔레트를 사용합니다.

7. 두 형식 빌드하고 살펴보기

1단계와 같은 부모 디렉터리에서 실행합니다.

guidedog build html orbit -W
guidedog build pdf orbit -W
guidedog build dirhtml orbit -W
guidedog build singlehtml orbit -W
guidedog serve orbit

serve 명령의 주소를 열고 첫 화면뿐 아니라 장과 검색 페이지도 확인합니다. 밝게·어둡게·시스템 모드와 좁은 화면을 시험하세요. 키보드로 탐색과 검색을 이용하고, 바닥글을 수정해 저장한 뒤 새로 고치세요. 의존 페이지가 다시 빌드됩니다.

PDF 리더에서 orbit/_build/pdf/orbit-notes-en.pdf 파일을 엽니다. 설정 이름에는 언어 접미사가 붙습니다. 목차, 장 첫머리, 수식, 표, 코드, 그림에 잘림·과한 간격·누락 글자가 없는지 확인합니다. 다른 출력은 _build/html, _build/dirhtml, _build/singlehtml 아래에 있습니다. 서버는 Ctrl+C 로 멈춥니다.

8. 테마 재사용과 유지보수

guidedog quickstart 명령으로 다른 프로젝트를 만들고 완성한 _templates 디렉터리와 _static/theme.css 파일을 복사합니다. 설정에 html_css_files = ["theme.css"], 강조색, edition_label 값을 더하세요. 바닥글 링크는 새 프로젝트의 실제 문서로 바꾸고, 새 프로젝트의 메타데이터와 소스는 유지합니다.

PDF 기본 템플릿도 복사하므로 테마는 독립적으로 동작합니다. 업그레이드할 때 임시 quickstart 프로젝트를 만들어 저장해 둔 기본 템플릿과 비교하세요. 필요한 변경을 반영하고 모든 형식을 다시 빌드합니다. 내장 HTML도 바뀔 수 있으므로 전체 복사본보다 작은 블록 재정의가 관리하기 쉽습니다. 계약은 템플릿 문서를 참고하세요.

base-book.typ 파일이 없으면 1단계의 이름 변경을 확인합니다. 라벨이 비면 html_context 안의 edition_label 값을, CSS가 없으면 html_static_path 및 html_css_files 설정을 확인하세요. 관련 없는 설정을 바꾸기 전에 진단의 파일·행·수정 방법을 읽으세요.