1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a site customization settings |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | organizationId: string, |
12 | siteId: string, |
13 | body: { |
14 | title?: string; |
15 | styling: { |
16 | theme: "clean" | "muted" | "bold" | "gradient"; |
17 | primaryColor: { light: string; dark: string }; |
18 | tint?: { color: { light: string; dark: string } }; |
19 | infoColor: { light: string; dark: string }; |
20 | successColor: { light: string; dark: string }; |
21 | warningColor: { light: string; dark: string }; |
22 | dangerColor: { light: string; dark: string }; |
23 | corners: "straight" | "rounded" | "circular"; |
24 | depth: "subtle" | "flat"; |
25 | links: "default" | "accent"; |
26 | font: |
27 | | "ABCFavorit" |
28 | | "Inter" |
29 | | "Roboto" |
30 | | "RobotoSlab" |
31 | | "OpenSans" |
32 | | "SourceSansPro" |
33 | | "Lato" |
34 | | "Ubuntu" |
35 | | "Raleway" |
36 | | "Merriweather" |
37 | | "Overpass" |
38 | | "NotoSans" |
39 | | "IBMPlexSerif" |
40 | | "Poppins" |
41 | | "FiraSans" |
42 | | { |
43 | id: string; |
44 | custom: false | true; |
45 | fontFamily: string; |
46 | fontFaces: { |
47 | weight: number; |
48 | sources: { url: string; format?: "woff2" | "woff" }[]; |
49 | }[]; |
50 | }; |
51 | monospaceFont: |
52 | | "FiraCode" |
53 | | "IBMPlexMono" |
54 | | "JetBrainsMono" |
55 | | "SourceCodePro" |
56 | | "RobotoMono" |
57 | | "SpaceMono" |
58 | | "DMMono" |
59 | | "Inconsolata" |
60 | | { |
61 | id: string; |
62 | custom: false | true; |
63 | fontFamily: string; |
64 | fontFaces: { |
65 | weight: number; |
66 | sources: { url: string; format?: "woff2" | "woff" }[]; |
67 | }[]; |
68 | }; |
69 | background: "plain" | "match"; |
70 | icons: "regular" | "solid" | "duotone" | "light" | "thin"; |
71 | sidebar: { |
72 | background: "default" | "filled"; |
73 | list: "default" | "pill" | "line"; |
74 | }; |
75 | search: "subtle" | "prominent"; |
76 | }; |
77 | internationalization: { |
78 | locale: |
79 | | "en" |
80 | | "fr" |
81 | | "es" |
82 | | "zh" |
83 | | "ja" |
84 | | "de" |
85 | | "nl" |
86 | | "no" |
87 | | "pt-br" |
88 | | "ru"; |
89 | }; |
90 | favicon: {} | { icon: { light: string; dark: string } } | { emoji: string }; |
91 | header: { |
92 | preset: "bold" | "default" | "contrast" | "custom" | "none"; |
93 | logo?: { light: string; dark: string }; |
94 | backgroundColor?: { light: string; dark: string }; |
95 | linkColor?: { light: string; dark: string }; |
96 | links: { |
97 | title: string; |
98 | style?: "link" | "button-primary" | "button-secondary"; |
99 | to: |
100 | | { kind: "file"; file: string } |
101 | | { kind: "url"; url: string } |
102 | | { kind: "page"; page: string; space?: string } |
103 | | { kind: "anchor"; anchor: string; space?: string; page?: string } |
104 | | { kind: "user"; user: string } |
105 | | { kind: "collection"; collection: string } |
106 | | { kind: "space"; space: string } |
107 | | { |
108 | kind: "reusable-content"; |
109 | reusableContent: string; |
110 | space?: string; |
111 | } |
112 | | { kind: "openapi"; spec: string }; |
113 | links: { |
114 | title: string; |
115 | to: |
116 | | { kind: "file"; file: string } |
117 | | { kind: "url"; url: string } |
118 | | { kind: "page"; page: string; space?: string } |
119 | | { kind: "anchor"; anchor: string; space?: string; page?: string } |
120 | | { kind: "user"; user: string } |
121 | | { kind: "collection"; collection: string } |
122 | | { kind: "space"; space: string } |
123 | | { |
124 | kind: "reusable-content"; |
125 | reusableContent: string; |
126 | space?: string; |
127 | } |
128 | | { kind: "openapi"; spec: string }; |
129 | }[]; |
130 | condition?: string; |
131 | }[]; |
132 | }; |
133 | footer: { |
134 | logo?: { light: string; dark: string }; |
135 | groups: { |
136 | title: string; |
137 | links: { |
138 | title: string; |
139 | to: |
140 | | { kind: "file"; file: string } |
141 | | { kind: "url"; url: string } |
142 | | { kind: "page"; page: string; space?: string } |
143 | | { kind: "anchor"; anchor: string; space?: string; page?: string } |
144 | | { kind: "user"; user: string } |
145 | | { kind: "collection"; collection: string } |
146 | | { kind: "space"; space: string } |
147 | | { |
148 | kind: "reusable-content"; |
149 | reusableContent: string; |
150 | space?: string; |
151 | } |
152 | | { kind: "openapi"; spec: string }; |
153 | }[]; |
154 | }[]; |
155 | copyright?: string; |
156 | }; |
157 | announcement?: { |
158 | enabled: false | true; |
159 | message: string; |
160 | link?: { |
161 | title: string; |
162 | to: |
163 | | { kind: "file"; file: string } |
164 | | { kind: "url"; url: string } |
165 | | { kind: "page"; page: string; space?: string } |
166 | | { kind: "anchor"; anchor: string; space?: string; page?: string } |
167 | | { kind: "user"; user: string } |
168 | | { kind: "collection"; collection: string } |
169 | | { kind: "space"; space: string } |
170 | | { |
171 | kind: "reusable-content"; |
172 | reusableContent: string; |
173 | space?: string; |
174 | } |
175 | | { kind: "openapi"; spec: string }; |
176 | }; |
177 | style: "info" | "warning" | "danger" | "success"; |
178 | }; |
179 | themes: { default: "light" | "dark"; toggeable: false | true }; |
180 | pdf: { enabled: false | true }; |
181 | feedback: { enabled: false | true }; |
182 | ai: { mode: "none" | "search" | "assistant" }; |
183 | advancedCustomization: { enabled: false | true }; |
184 | git: { showEditLink: false | true }; |
185 | pageActions: { externalAI: false | true; markdown: false | true }; |
186 | externalLinks: { target: "self" | "blank" }; |
187 | pagination: { enabled: false | true }; |
188 | trademark: { enabled: false | true }; |
189 | privacyPolicy: { url?: string }; |
190 | socialPreview: { url?: string }; |
191 | insights: { trackingCookie: false | true }; |
192 | }, |
193 | ) { |
194 | const url = new URL( |
195 | `https://api.gitbook.com/v1/orgs/${organizationId}/sites/${siteId}/customization`, |
196 | ); |
197 |
|
198 | const response = await fetch(url, { |
199 | method: "PUT", |
200 | headers: { |
201 | "Content-Type": "application/json", |
202 | Authorization: "Bearer " + auth.token, |
203 | }, |
204 | body: JSON.stringify(body), |
205 | }); |
206 | if (!response.ok) { |
207 | const text = await response.text(); |
208 | throw new Error(`${response.status} ${text}`); |
209 | } |
210 | return await response.json(); |
211 | } |
212 |
|