diff --git a/src/client/theme-default/components/icons/VPIconAlignJustify.vue b/src/client/theme-default/components/icons/VPIconAlignJustify.vue
index 653dab13..46f45a94 100644
--- a/src/client/theme-default/components/icons/VPIconAlignJustify.vue
+++ b/src/client/theme-default/components/icons/VPIconAlignJustify.vue
@@ -1,8 +1,11 @@
+
+
-
diff --git a/src/client/theme-default/components/icons/VPIconAlignLeft.vue b/src/client/theme-default/components/icons/VPIconAlignLeft.vue
index 8dc84eae..90ad6c16 100644
--- a/src/client/theme-default/components/icons/VPIconAlignLeft.vue
+++ b/src/client/theme-default/components/icons/VPIconAlignLeft.vue
@@ -1,8 +1,11 @@
+
+
-
-
-
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconAlignRight.vue b/src/client/theme-default/components/icons/VPIconAlignRight.vue
index 16cbb3c7..74635d5f 100644
--- a/src/client/theme-default/components/icons/VPIconAlignRight.vue
+++ b/src/client/theme-default/components/icons/VPIconAlignRight.vue
@@ -1,8 +1,11 @@
+
+
-
-
-
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconArrowLeft.vue b/src/client/theme-default/components/icons/VPIconArrowLeft.vue
index 3f65b866..cf7fb4e9 100644
--- a/src/client/theme-default/components/icons/VPIconArrowLeft.vue
+++ b/src/client/theme-default/components/icons/VPIconArrowLeft.vue
@@ -1,7 +1,11 @@
+
+
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconArrowRight.vue b/src/client/theme-default/components/icons/VPIconArrowRight.vue
index ed89263f..2d6b6451 100644
--- a/src/client/theme-default/components/icons/VPIconArrowRight.vue
+++ b/src/client/theme-default/components/icons/VPIconArrowRight.vue
@@ -1,7 +1,11 @@
+
+
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconChevronDown.vue b/src/client/theme-default/components/icons/VPIconChevronDown.vue
index d72f4ee8..e5744e6c 100644
--- a/src/client/theme-default/components/icons/VPIconChevronDown.vue
+++ b/src/client/theme-default/components/icons/VPIconChevronDown.vue
@@ -1,5 +1,11 @@
+
+
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconChevronLeft.vue b/src/client/theme-default/components/icons/VPIconChevronLeft.vue
index 013eb7fd..5564685b 100644
--- a/src/client/theme-default/components/icons/VPIconChevronLeft.vue
+++ b/src/client/theme-default/components/icons/VPIconChevronLeft.vue
@@ -1,5 +1,11 @@
+
+
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconChevronRight.vue b/src/client/theme-default/components/icons/VPIconChevronRight.vue
index cf72418f..fd96f192 100644
--- a/src/client/theme-default/components/icons/VPIconChevronRight.vue
+++ b/src/client/theme-default/components/icons/VPIconChevronRight.vue
@@ -1,5 +1,11 @@
+
+
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconChevronUp.vue b/src/client/theme-default/components/icons/VPIconChevronUp.vue
index 0b6a873e..3b6e11be 100644
--- a/src/client/theme-default/components/icons/VPIconChevronUp.vue
+++ b/src/client/theme-default/components/icons/VPIconChevronUp.vue
@@ -1,5 +1,11 @@
+
+
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconEdit.vue b/src/client/theme-default/components/icons/VPIconEdit.vue
index f30a62dd..2c5d4296 100644
--- a/src/client/theme-default/components/icons/VPIconEdit.vue
+++ b/src/client/theme-default/components/icons/VPIconEdit.vue
@@ -1,6 +1,11 @@
+
+
-
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconHeart.vue b/src/client/theme-default/components/icons/VPIconHeart.vue
index d408828f..0906e8ae 100644
--- a/src/client/theme-default/components/icons/VPIconHeart.vue
+++ b/src/client/theme-default/components/icons/VPIconHeart.vue
@@ -1,5 +1,11 @@
+
+
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconLanguages.vue b/src/client/theme-default/components/icons/VPIconLanguages.vue
index 71a728fc..4b40f2c7 100644
--- a/src/client/theme-default/components/icons/VPIconLanguages.vue
+++ b/src/client/theme-default/components/icons/VPIconLanguages.vue
@@ -1,9 +1,11 @@
+
+
-
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconMinus.vue b/src/client/theme-default/components/icons/VPIconMinus.vue
index e0229195..0d8bc0a7 100644
--- a/src/client/theme-default/components/icons/VPIconMinus.vue
+++ b/src/client/theme-default/components/icons/VPIconMinus.vue
@@ -1,5 +1,11 @@
+
+
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconMinusSquare.vue b/src/client/theme-default/components/icons/VPIconMinusSquare.vue
index 266ae3da..e9b49e04 100644
--- a/src/client/theme-default/components/icons/VPIconMinusSquare.vue
+++ b/src/client/theme-default/components/icons/VPIconMinusSquare.vue
@@ -1,6 +1,11 @@
+
+
-
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconMoon.vue b/src/client/theme-default/components/icons/VPIconMoon.vue
index a9b205c6..5329c484 100644
--- a/src/client/theme-default/components/icons/VPIconMoon.vue
+++ b/src/client/theme-default/components/icons/VPIconMoon.vue
@@ -1,5 +1,10 @@
+
-
-
+
+
diff --git a/src/client/theme-default/components/icons/VPIconMoreHorizontal.vue b/src/client/theme-default/components/icons/VPIconMoreHorizontal.vue
index 6fa7fca2..737602cc 100644
--- a/src/client/theme-default/components/icons/VPIconMoreHorizontal.vue
+++ b/src/client/theme-default/components/icons/VPIconMoreHorizontal.vue
@@ -1,7 +1,12 @@
+
+
-
-
-
-
+
+
+
diff --git a/src/client/theme-default/components/icons/VPIconPlus.vue b/src/client/theme-default/components/icons/VPIconPlus.vue
index 74d9f695..61b3c229 100644
--- a/src/client/theme-default/components/icons/VPIconPlus.vue
+++ b/src/client/theme-default/components/icons/VPIconPlus.vue
@@ -1,5 +1,12 @@
+
+
-
-
+
+
+
diff --git a/src/client/theme-default/components/icons/VPIconPlusSquare.vue b/src/client/theme-default/components/icons/VPIconPlusSquare.vue
index 88e5b5cf..b502818f 100644
--- a/src/client/theme-default/components/icons/VPIconPlusSquare.vue
+++ b/src/client/theme-default/components/icons/VPIconPlusSquare.vue
@@ -1,6 +1,12 @@
+
+
-
-
-
+
+
+
diff --git a/src/client/theme-default/components/icons/VPIconSun.vue b/src/client/theme-default/components/icons/VPIconSun.vue
index 8ecb25ba..9fb4db15 100644
--- a/src/client/theme-default/components/icons/VPIconSun.vue
+++ b/src/client/theme-default/components/icons/VPIconSun.vue
@@ -1,13 +1,10 @@
+
-
-
-
-
-
-
-
-
-
-
+
+
diff --git a/src/node/plugin.ts b/src/node/plugin.ts
index a386fe2c..d5dfdc58 100644
--- a/src/node/plugin.ts
+++ b/src/node/plugin.ts
@@ -28,6 +28,7 @@ import { staticDataPlugin } from './plugins/staticDataPlugin'
import { webFontsPlugin } from './plugins/webFontsPlugin'
import { slash, type PageDataPayload } from './shared'
import { deserializeFunctions, serializeFunctions } from './utils/fnSerialize'
+import { svgSpritePlugin } from './plugins/svgSpritePlugin'
declare module 'vite' {
interface UserConfig {
@@ -444,6 +445,7 @@ export async function createVitePressPlugin(
...(userViteConfig?.plugins || []),
await localSearchPlugin(siteConfig),
staticDataPlugin,
+ svgSpritePlugin,
await dynamicRoutesPlugin(siteConfig)
]
}
diff --git a/src/node/plugins/svgSpritePlugin.ts b/src/node/plugins/svgSpritePlugin.ts
new file mode 100644
index 00000000..e20f14d5
--- /dev/null
+++ b/src/node/plugins/svgSpritePlugin.ts
@@ -0,0 +1,123 @@
+import type { Plugin } from 'vite'
+
+const svgSprite = `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+`
+
+// TODO: include social icons?
+const socialSvgSprite = `
+
+
+`
+
+const svgSpriteMap: Record = {
+ 'vp-icons-sprite.svg': svgSprite,
+ 'vp-icons-social-sprite.svg': socialSvgSprite
+}
+
+export const svgSpritePlugin: Plugin = {
+ name: 'vitepress:svg-sprite',
+ enforce: 'pre',
+ generateBundle(_options, bundle) {
+ Object.entries(svgSpriteMap).forEach(([fileName, source]) => {
+ bundle[fileName] = {
+ type: 'asset',
+ name: fileName,
+ source,
+ fileName,
+ needsCodeReference: true
+ }
+ })
+ },
+ configureServer(server) {
+ // TODO: review base path => SiteConfig
+ const base = server.config.base ?? '/'
+ server.middlewares.use((req, res, next) => {
+ const url = req.url
+ if (!url) {
+ return next()
+ }
+ const filename = new URL(url, 'http://localhost').pathname.replace(
+ base,
+ ''
+ )
+ const sprite = svgSpriteMap[filename]
+ if (!sprite) {
+ return next()
+ }
+
+ res.setHeader('Content-Type', 'image/svg+xml')
+ res.statusCode = 200
+ res.write(sprite, 'utf-8')
+ res.end()
+ })
+ }
+}