1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Override a site space customization settings |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | organizationId: string, |
12 | siteId: string, |
13 | siteSpaceId: string, |
14 | body: { |
15 | title?: string; |
16 | styling?: { |
17 | theme?: "clean" | "muted" | "bold" | "gradient"; |
18 | primaryColor?: { 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 | tint?: { color: { light: string; dark: string } }; |
24 | corners?: "straight" | "rounded" | "circular"; |
25 | depth?: "subtle" | "flat"; |
26 | links?: "default" | "accent"; |
27 | icons?: "regular" | "solid" | "duotone" | "light" | "thin"; |
28 | sidebar?: { |
29 | background?: "default" | "filled"; |
30 | list?: "default" | "pill" | "line"; |
31 | }; |
32 | search?: "subtle" | "prominent"; |
33 | background?: "plain" | "match"; |
34 | }; |
35 | internationalization?: { |
36 | locale: |
37 | | "en" |
38 | | "fr" |
39 | | "es" |
40 | | "zh" |
41 | | "ja" |
42 | | "de" |
43 | | "nl" |
44 | | "no" |
45 | | "pt-br" |
46 | | "ru"; |
47 | }; |
48 | favicon?: |
49 | | {} |
50 | | { icon: { light: string; dark: string } } |
51 | | { emoji: string }; |
52 | announcement?: { |
53 | enabled: false | true; |
54 | message: string; |
55 | link?: { |
56 | title: string; |
57 | to: |
58 | | { kind: "file"; file: string } |
59 | | { kind: "url"; url: string } |
60 | | { kind: "page"; page: string; space?: string } |
61 | | { kind: "anchor"; anchor: string; space?: string; page?: string } |
62 | | { kind: "user"; user: string } |
63 | | { kind: "collection"; collection: string } |
64 | | { kind: "space"; space: string } |
65 | | { |
66 | kind: "reusable-content"; |
67 | reusableContent: string; |
68 | space?: string; |
69 | } |
70 | | { kind: "openapi"; spec: string }; |
71 | }; |
72 | style: "info" | "warning" | "danger" | "success"; |
73 | }; |
74 | header?: { |
75 | preset?: "bold" | "default" | "contrast" | "custom" | "none"; |
76 | logo?: { light: string; dark: string }; |
77 | backgroundColor?: { light: string; dark: string }; |
78 | linkColor?: { light: string; dark: string }; |
79 | links?: { |
80 | title: string; |
81 | style?: "link" | "button-primary" | "button-secondary"; |
82 | to: |
83 | | { kind: "file"; file: string } |
84 | | { kind: "url"; url: string } |
85 | | { kind: "page"; page: string; space?: string } |
86 | | { kind: "anchor"; anchor: string; space?: string; page?: string } |
87 | | { kind: "user"; user: string } |
88 | | { kind: "collection"; collection: string } |
89 | | { kind: "space"; space: string } |
90 | | { |
91 | kind: "reusable-content"; |
92 | reusableContent: string; |
93 | space?: string; |
94 | } |
95 | | { kind: "openapi"; spec: string }; |
96 | links: { |
97 | title: string; |
98 | to: |
99 | | { kind: "file"; file: string } |
100 | | { kind: "url"; url: string } |
101 | | { kind: "page"; page: string; space?: string } |
102 | | { kind: "anchor"; anchor: string; space?: string; page?: string } |
103 | | { kind: "user"; user: string } |
104 | | { kind: "collection"; collection: string } |
105 | | { kind: "space"; space: string } |
106 | | { |
107 | kind: "reusable-content"; |
108 | reusableContent: string; |
109 | space?: string; |
110 | } |
111 | | { kind: "openapi"; spec: string }; |
112 | }[]; |
113 | condition?: string; |
114 | }[]; |
115 | }; |
116 | footer?: { |
117 | logo?: { light: string; dark: string }; |
118 | groups?: { |
119 | title: string; |
120 | links: { |
121 | title: string; |
122 | to: |
123 | | { kind: "file"; file: string } |
124 | | { kind: "url"; url: string } |
125 | | { kind: "page"; page: string; space?: string } |
126 | | { kind: "anchor"; anchor: string; space?: string; page?: string } |
127 | | { kind: "user"; user: string } |
128 | | { kind: "collection"; collection: string } |
129 | | { kind: "space"; space: string } |
130 | | { |
131 | kind: "reusable-content"; |
132 | reusableContent: string; |
133 | space?: string; |
134 | } |
135 | | { kind: "openapi"; spec: string }; |
136 | }[]; |
137 | }[]; |
138 | copyright?: string; |
139 | }; |
140 | themes?: { default?: "light" | "dark"; toggeable?: false | true }; |
141 | pdf?: { enabled: false | true }; |
142 | feedback?: { enabled: false | true }; |
143 | git?: { showEditLink: false | true }; |
144 | externalLinks?: { target: "self" | "blank" }; |
145 | pagination?: { enabled: false | true }; |
146 | trademark?: { enabled: false | true }; |
147 | privacyPolicy?: { url?: string }; |
148 | socialPreview?: { url?: string }; |
149 | }, |
150 | ) { |
151 | const url = new URL( |
152 | `https://api.gitbook.com/v1/orgs/${organizationId}/sites/${siteId}/site-spaces/${siteSpaceId}/customization`, |
153 | ); |
154 |
|
155 | const response = await fetch(url, { |
156 | method: "PATCH", |
157 | headers: { |
158 | "Content-Type": "application/json", |
159 | Authorization: "Bearer " + auth.token, |
160 | }, |
161 | body: JSON.stringify(body), |
162 | }); |
163 | if (!response.ok) { |
164 | const text = await response.text(); |
165 | throw new Error(`${response.status} ${text}`); |
166 | } |
167 | return await response.json(); |
168 | } |
169 |
|