Skip to content

Commit b6e9804

Browse files
committed
Merge branch 'document-appearance-customization' into document-theme-settings
2 parents d4f5684 + 8628480 commit b6e9804

12 files changed

+204
-0
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

Sources/DocCDocumentation/DocCDocumentation.docc/DocC Documentation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ DocC syntax — called _documentation markup_ — is a custom variant of Markdow
2929
### Distribution
3030

3131
- <doc:distributing-documentation-to-other-developers>
32+
- <doc:customizing-your-documentation-appearance>
3233

3334
### Documentation Types
3435

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
# Customizing Your Documentation Appearance
2+
3+
Customize the look and feel of your documentation webpages.
4+
5+
## Overview
6+
7+
By default, rendered documentation webpages produced by DocC come with a default
8+
visual styling. If you wish, you may make adjustments to this styling by adding
9+
an optional `theme-settings.json` file to the root of your documentation catalog
10+
with some configuration. This file is used to customize various things like
11+
colors and fonts. You can even make changes to the way that specific elements
12+
appear, like buttons, code listings, and asides. Additionally, some metadata for
13+
the website can be configured in this file, and it can also be used to opt in or
14+
opt out of certain default rendering behavior.
15+
16+
If you're curious about the full capabilities of the `theme-settings.json` file,
17+
you can check out the latest Open API specification for the it [here][1], which
18+
documents all valid settings that could be present.
19+
20+
Let's walk through some basic examples of customizing the appearance of
21+
documentation now.
22+
23+
### Colors
24+
25+
DocC-Render utilizes [CSS custom properties][2] (CSS variables) to define the
26+
various colors that are used throughout the HTML elements of rendered
27+
documentation. Any key/value in the `theme.color` object of
28+
`theme-settings.json` will either update an existing color property used in the
29+
renderer or add a new one that could be referenced by existing ones.
30+
31+
**Example**
32+
33+
As a simple example, the following configuration would update the background
34+
fill color for the "documentation intro" element to `"rebeccapurple"` by
35+
changing the value of the CSS property to `--color-documentation-intro-fill:
36+
"rebeccapurple"`.
37+
38+
```json
39+
{
40+
"theme": {
41+
"color": {
42+
"documentation-intro-fill": "rebeccapurple"
43+
}
44+
}
45+
}
46+
```
47+
48+
![A screenshot of the documentation intro element with a purple background color](theme-screenshot-01.png)
49+
50+
**Example**
51+
52+
Note that any valid CSS color value could be used. Here is a more advanced
53+
example which demonstrates how specialized dark and light versions of the main
54+
background fill and nav colors could be defined as varying lightness percentages
55+
of a green hue.
56+
57+
```json
58+
{
59+
"theme": {
60+
"color": {
61+
"hue-green": "120",
62+
"fill": {
63+
"dark": "hsl(var(--color-hue-green), 100%, 10%)",
64+
"light": "hsl(var(--color-hue-green), 100%, 90%)"
65+
},
66+
"fill-secondary": {
67+
"dark": "hsl(var(--color-hue-green), 100%, 20%)",
68+
"light": "hsl(var(--color-hue-green), 100%, 80%)"
69+
},
70+
"nav-solid-background": "var(--color-fill)"
71+
}
72+
}
73+
}
74+
```
75+
76+
![A screenshot of the green page background in dark mode](theme-screenshot-02.png)
77+
78+
![A screenshot of the green page background in light mode](theme-screenshot-03.png)
79+
80+
As a general rule, the default color properties provided by DocC-Render assumes
81+
a naming convention where "fill" colors are used for backgrounds and "figure"
82+
colors are used for foreground colors, like text.
83+
84+
> Tip:
85+
> For a more complete example of a fully customized documentation website, you
86+
> can check out [this fork][3] of the DocC documentation that is using this
87+
> [theme-settings.json file][4].
88+
89+
### Fonts
90+
91+
By default, there are two main fonts used by DocC-Render: one for monospaced
92+
text in code voice and another for all other text content. With
93+
`theme-settings.json`, you can customize the CSS `font-family` lists for these
94+
however you choose.
95+
96+
**Example**
97+
98+
```json
99+
{
100+
"theme": {
101+
"typography": {
102+
"html-font": "\"Comic Sans MS\", \"Comic Sans\", cursive",
103+
"html-font-mono": "\"Courier New\", Courier, monospace"
104+
}
105+
}
106+
}
107+
```
108+
109+
![A screenshot of a documentation page with custom fonts](theme-screenshot-04)
110+
111+
### Borders
112+
113+
Another aspect of the renderer that you may wish to modify is the way that it
114+
applies border to certain elements. With `theme-settings.json`, you can change
115+
the default border radius for all elements and also individually update the
116+
border styles for asides, buttons, code listings, and tutorial steps.
117+
118+
**Example**
119+
120+
```json
121+
{
122+
"theme": {
123+
"aside": {
124+
"border-radius": "6px",
125+
"border-style": "double",
126+
"border-width": "3px"
127+
},
128+
"border-radius": "0",
129+
"button": {
130+
"border-radius": "8px",
131+
"border-style": "solid",
132+
"border-width": "2px"
133+
},
134+
"code": {
135+
"border-radius": "2px",
136+
"border-style": "dashed",
137+
"border-width": "2px"
138+
},
139+
"tutorial-step": {
140+
"border-radius": "12px"
141+
}
142+
}
143+
}
144+
```
145+
146+
![A screenshot of a tutorial page with custom button
147+
borders](theme-screenshot-05.png)
148+
149+
![A screenshot of tutorial steps with custom borders](theme-screenshot-06.png)
150+
151+
![A screenshot of a documentation page with custom code listing and aside border
152+
styles](theme-screenshot-07.png)
153+
154+
### Metadata
155+
156+
You can specify some text that will be used in the HTML `<title>` element for
157+
all webpages in `theme-settings.json` in place of the default "Documentation"
158+
text.
159+
160+
**Example**
161+
162+
```json
163+
{
164+
"meta": {
165+
"title": "Custom Title",
166+
}
167+
}
168+
```
169+
170+
With that configuration, the title of this page would change from "Customizing
171+
Your Documentation Appearance | Documentation" to "Customizing Your Documentation
172+
Appearance | **Custom Title**".
173+
174+
### Feature Flags
175+
176+
From time to time, there may be instances of various experimental UI features
177+
that can be enabled or disabled using `theme-settings.json`.
178+
179+
**Example**
180+
181+
As of the time of writing this, there is only one available "quick navigation"
182+
feature that is disabled by default and can be enabled with the following
183+
configuration. Note that this flag may be dropped in the future and new ones may
184+
be added as necessary for other features.
185+
186+
```json
187+
{
188+
"features": {
189+
"docs": {
190+
"quickNavigation": {
191+
"enable": true
192+
}
193+
}
194+
}
195+
}
196+
```
197+
198+
[1]: https://github.com/apple/swift-docc/blob/main/Sources/SwiftDocC/SwiftDocC.docc/Resources/ThemeSettings.spec.json
199+
[2]: https://drafts.csswg.org/css-variables/
200+
[3]: https://mportiz08.github.io/swift-docc/documentation/docc
201+
[4]: https://mportiz08.github.io/swift-docc/theme-settings.json
202+
203+
<!-- Copyright (c) 2021 Apple Inc and the Swift Project authors. All Rights Reserved. -->

0 commit comments

Comments
 (0)