From ae58219d71632a202dd1d0fdb16f285856dc2f29 Mon Sep 17 00:00:00 2001 From: everdimension Date: Tue, 22 Oct 2024 16:25:43 +0300 Subject: [PATCH 1/2] Improve docs for base url for public assets Current docs seem to be very vague. The only thing they mention is this comment: ``` // if base is set, use /base/favicon.ico ``` I had know idea if this meant that I need to manually add the base prefix and how I would do it, or whether I have to specifically create a `/base` directory within my `/docs` folder Since there are many issues where people are confused about this (https://github.com/vuejs/vitepress/issues/1500, https://github.com/vuejs/vitepress/issues/3869, https://github.com/vuejs/vitepress/issues/1815, https://github.com/vuejs/vitepress/issues/827), I think this explanation belongs to the docs --- docs/en/reference/site-config.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/en/reference/site-config.md b/docs/en/reference/site-config.md index 8cf5e264..161f2598 100644 --- a/docs/en/reference/site-config.md +++ b/docs/en/reference/site-config.md @@ -229,6 +229,24 @@ export default { */ ``` +If you're using [base](./site-config#base), the file will be built to `/your-base-url/favicon.ico`, but the rendered link tag will still point to `/favicon.icon`. +Currently, you have to handle this manually. Your site config needs to explicitly specify the base url: + +```ts +export default { + head: [['link', { rel: 'icon', href: '/your-base-url/favicon.ico' }]] +} +``` + +If, for example, you don't know your base prefix ahead of time (for example, you're passing the `--base` option [during build](./cli#options-1)), one way to access it would be to also pass +it as an env variable and use it in the config file: + +```ts +export default { + head: [['link', { rel: 'icon', href: `${process.env.BASE}/favicon.ico` }]] +} +``` + #### Example: Adding Google Fonts ```ts From b7eefabc3a7404464e08f1fdbad0eb31b6ab827e Mon Sep 17 00:00:00 2001 From: everdimension Date: Tue, 22 Oct 2024 18:00:47 +0300 Subject: [PATCH 2/2] reword --- docs/en/reference/site-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/site-config.md b/docs/en/reference/site-config.md index 161f2598..fd7a0939 100644 --- a/docs/en/reference/site-config.md +++ b/docs/en/reference/site-config.md @@ -229,7 +229,7 @@ export default { */ ``` -If you're using [base](./site-config#base), the file will be built to `/your-base-url/favicon.ico`, but the rendered link tag will still point to `/favicon.icon`. +If you're using [base](./site-config#base), the file will be available at `/your-base-url/favicon.ico`, but the rendered link tag will still point to `/favicon.icon`. Currently, you have to handle this manually. Your site config needs to explicitly specify the base url: ```ts