Guidedog 설명서 1.0.0-beta.16
언어
이 페이지의 내용
Guidedog / 문서 1.0.0-beta.16

프로젝트 테마 만들기

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

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

Guidedog 1.0.0-beta.9 이상을 사용합니다. orbit이 들어갈 디렉터리에서 다음을 실행하세요:

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

생성된 orbit/_templates/book.typ의 이름을 같은 디렉터리의 base-book.typ으로 바꿉니다. 생성된 theme.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
    theme.typ              # Shared PDF theme generated by quickstart.
    discussion.typ         # Discussion layout generated by quickstart.
    article.typ            # Standalone article layout generated by quickstart.
    base-book.typ          # Generated by quickstart; renamed, not replaced.
    book.typ
    palette.typ
  _static/
    guidedog.css           # Generated by quickstart.
    guidedog.js            # Generated by quickstart.
    typography.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입니다. templates_path를 바꿔도 이 위치는 바뀌지 않습니다.

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는 필요 없습니다. 배경 테마가 바뀌는 곳에 고정된 글자색만 쓰지 마세요.

_static/typography.js는 데스크톱 영어 문단을 Knuth-Plass 줄바꿈과 Liang 하이픈 알고리즘으로 최적화하며, JavaScript가 꺼져 있거나 좁은 화면에서는 guidedog.css가 text-wrap: pretty로 깔끔하게 대체됩니다(읽기 위한 조판 참고).

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

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
// guidedog: margin-x = 31mm

// 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를 스타일 함수 안으로 넘겨야 그 규칙이 적용 범위 안에 유지됩니다. 웹 스타일시트는 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 기본 템플릿을 복사해 두었으므로 테마는 그 자체로 완결됩니다. Guidedog을 업그레이드할 때는 임시 quickstart 프로젝트를 만들어 그 템플릿을 저장해 둔 기본 템플릿과 비교합니다. 필요한 변경만 반영한 뒤 모든 대상을 다시 빌드합니다. 내장 HTML 레이아웃도 바뀔 수 있습니다. 완전한 레이아웃을 하나 더 두는 것보다 작은 블록 재정의가 유지하기 쉽습니다. 모든 변수와 블록은 템플릿 문서를 참고하세요.

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