mirror of https://github.com/YunYouJun/valaxy
fix: inject default labels for custom code block icon
This commit is contained in:
parent
7e4632f1b8
commit
54f9be61ee
|
@ -164,9 +164,33 @@ export async function ViteValaxyPlugins(
|
||||||
|
|
||||||
let cachedGroupIconsCSS: string | null = null
|
let cachedGroupIconsCSS: string | null = null
|
||||||
|
|
||||||
// Create a custom plugin that intercepts the virtual CSS generation
|
// Helper function to generate group icons CSS with collected titles
|
||||||
|
const generateGroupIconsCSS = (id: string) => {
|
||||||
|
const codeBlockTitles = getGlobalTitleCollector()
|
||||||
|
|
||||||
|
const originalPlugin = groupIconVitePlugin({
|
||||||
|
customIcon: {
|
||||||
|
...builtinCustomIcon,
|
||||||
|
...valaxyConfig.groupIcons?.customIcon,
|
||||||
|
},
|
||||||
|
defaultLabels: [
|
||||||
|
...valaxyConfig.groupIcons?.defaultLabels || [],
|
||||||
|
...Object.keys(builtinCustomIcon),
|
||||||
|
...Object.keys(valaxyConfig.groupIcons?.customIcon || {}),
|
||||||
|
...Array.from(codeBlockTitles),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
if (originalPlugin && typeof originalPlugin === 'object' && 'load' in originalPlugin) {
|
||||||
|
return (originalPlugin as any).load(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
// For issue #578 and #573
|
||||||
const dynamicGroupIconPlugin: PluginOption = {
|
const dynamicGroupIconPlugin: PluginOption = {
|
||||||
name: 'vitepress-plugin-group-icons',
|
name: 'post-process-add-group-icons',
|
||||||
enforce: 'post' as const,
|
enforce: 'post' as const,
|
||||||
|
|
||||||
configureServer(server: ViteDevServer) {
|
configureServer(server: ViteDevServer) {
|
||||||
|
@ -201,29 +225,7 @@ export async function ViteValaxyPlugins(
|
||||||
}
|
}
|
||||||
|
|
||||||
// For dev mode or initial build, generate with current titles
|
// For dev mode or initial build, generate with current titles
|
||||||
const codeBlockTitles = getGlobalTitleCollector()
|
return generateGroupIconsCSS(id)
|
||||||
|
|
||||||
// Create the original plugin with dynamic titles
|
|
||||||
const originalPlugin = groupIconVitePlugin({
|
|
||||||
customIcon: {
|
|
||||||
...builtinCustomIcon,
|
|
||||||
...valaxyConfig.groupIcons?.customIcon,
|
|
||||||
},
|
|
||||||
defaultLabels: [
|
|
||||||
...valaxyConfig.groupIcons?.defaultLabels || [],
|
|
||||||
...Object.keys(builtinCustomIcon),
|
|
||||||
...Object.keys(valaxyConfig.groupIcons?.customIcon || {}),
|
|
||||||
...Array.from(codeBlockTitles),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
// Call the original plugin's load method
|
|
||||||
if (originalPlugin && typeof originalPlugin === 'object' && 'load' in originalPlugin) {
|
|
||||||
const css = (originalPlugin as any).load(id)
|
|
||||||
return css
|
|
||||||
}
|
|
||||||
|
|
||||||
return ''
|
|
||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
},
|
},
|
||||||
|
@ -232,26 +234,8 @@ export async function ViteValaxyPlugins(
|
||||||
generateBundle() {
|
generateBundle() {
|
||||||
if (this.meta.rollupVersion) { // Build mode only
|
if (this.meta.rollupVersion) { // Build mode only
|
||||||
// At this point, all markdown files should have been processed
|
// At this point, all markdown files should have been processed
|
||||||
const codeBlockTitles = getGlobalTitleCollector()
|
// Generate and cache the final CSS with all collected titles
|
||||||
|
cachedGroupIconsCSS = generateGroupIconsCSS('\0virtual:group-icons.css')
|
||||||
// Generate the final CSS with all collected titles
|
|
||||||
const originalPlugin = groupIconVitePlugin({
|
|
||||||
customIcon: {
|
|
||||||
...builtinCustomIcon,
|
|
||||||
...valaxyConfig.groupIcons?.customIcon,
|
|
||||||
},
|
|
||||||
defaultLabels: [
|
|
||||||
...valaxyConfig.groupIcons?.defaultLabels || [],
|
|
||||||
...Object.keys(builtinCustomIcon),
|
|
||||||
...Object.keys(valaxyConfig.groupIcons?.customIcon || {}),
|
|
||||||
...Array.from(codeBlockTitles),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
// Cache the final CSS
|
|
||||||
if (originalPlugin && typeof originalPlugin === 'object' && 'load' in originalPlugin) {
|
|
||||||
cachedGroupIconsCSS = (originalPlugin as any).load('\0virtual:group-icons.css')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue