@@ -155,17 +155,56 @@ export default {
155
155
156
156
Additional elements to render in the ` <head> ` tag in the page HTML. The user-added tags are rendered before the closing ` head ` tag, after VitePress tags.
157
157
158
+ ``` ts
159
+ type HeadConfig =
160
+ | [string , Record <string , string >]
161
+ | [string , Record <string , string >, string ]
162
+ ` ` `
163
+
164
+ #### Example: Adding a favicon
165
+
166
+ ` ` ` ts
167
+ export default {
168
+ head: [[' link' , { rel: ' icon' , href: ' /favicon.ico' }]]
169
+ } // put favicon.ico in public directory, if base is set, use /base/favicon.ico
170
+
171
+ /* Would render:
172
+ <link rel="icon" href="/favicon.ico">
173
+ */
174
+ ```
175
+
176
+ #### Example: Adding Google Fonts
177
+
158
178
``` ts
159
179
export default {
160
180
head: [
181
+ [
182
+ ' link' ,
183
+ { rel: ' preconnect' , href: ' https://fonts.googleapis.com' }
184
+ ],
161
185
[
162
186
' link' ,
163
187
{ rel: ' preconnect' , href: ' https://fonts.gstatic.com' , crossorigin: ' ' }
164
- // would render:
165
- //
166
- // <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
167
188
],
189
+ [
190
+ ' link' ,
191
+ { href: ' https://fonts.googleapis.com/css2?family=Roboto&display=swap' , rel: ' stylesheet' }
192
+ ]
193
+ ]
194
+ }
195
+
196
+ /* Would render:
197
+ <link rel="preconnect" href="https://fonts.googleapis.com">
198
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
199
+ <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
200
+ */
201
+ ```
202
+
203
+ #### Example: Registering a service worker
168
204
205
+ ``` ts
206
+ export default {
207
+ head: [
169
208
[
170
209
' script' ,
171
210
{ id: ' register-sw' },
@@ -174,24 +213,50 @@ export default {
174
213
navigator.serviceWorker.register('/sw.js')
175
214
}
176
215
})() `
177
- // would render:
178
- //
179
- // <script id="register-sw">
180
- // ;(() => {
181
- // if ('serviceWorker' in navigator) {
182
- // navigator.serviceWorker.register('/sw.js')
183
- // }
184
- // })()
185
- // </script>
186
216
]
187
217
]
188
218
}
219
+
220
+ /* Would render:
221
+ <script id="register-sw">
222
+ ;(() => {
223
+ if ('serviceWorker' in navigator) {
224
+ navigator.serviceWorker.register('/sw.js')
225
+ }
226
+ })()
227
+ </script>
228
+ */
189
229
```
190
230
231
+ #### Example: Using Google Analytics
232
+
191
233
``` ts
192
- type HeadConfig =
193
- | [string , Record <string , string >]
194
- | [string , Record <string , string >, string ]
234
+ export default {
235
+ head: [
236
+ [
237
+ ' script' ,
238
+ { async: ' ' , src: ' https://www.googletagmanager.com/gtag/js?id=TAG_ID' }
239
+ ],
240
+ [
241
+ ' script' ,
242
+ {},
243
+ ` window.dataLayer = window.dataLayer || [];
244
+ function gtag(){dataLayer.push(arguments);}
245
+ gtag('js', new Date());
246
+ gtag('config', 'TAG_ID'); `
247
+ ]
248
+ ]
249
+ }
250
+
251
+ /* Would render:
252
+ <script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
253
+ <script>
254
+ window.dataLayer = window.dataLayer || [];
255
+ function gtag(){dataLayer.push(arguments);}
256
+ gtag('js', new Date());
257
+ gtag('config', 'TAG_ID');
258
+ </script>
259
+ */
195
260
```
196
261
197
262
### lang
@@ -239,7 +304,7 @@ Enabling this may require additional configuration on your hosting platform. For
239
304
240
305
- Type: ` Record<string, string> `
241
306
242
- Defines custom directory <-> URL mappings. See [ Routing: Route Rewrites] ( ../guide/routing#route-rewrites ) for more details.
307
+ Defines custom directory & lt ; - & gt ; URL mappings. See [ Routing: Route Rewrites] ( ../guide/routing#route-rewrites ) for more details.
243
308
244
309
``` ts
245
310
export default {
0 commit comments