diff --git a/.gitignore b/.gitignore
index c720febdf0..8720c7bf73 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,3 +19,4 @@ packages/element-plus/version.ts
cypress/screenshots/*
cypress/videos/*
tmp
+docs/.vitepress/cache
diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config/index.mts
similarity index 86%
rename from docs/.vitepress/config.mts
rename to docs/.vitepress/config/index.mts
index e1b9693920..88c42378c2 100644
--- a/docs/.vitepress/config.mts
+++ b/docs/.vitepress/config/index.mts
@@ -1,8 +1,13 @@
import consola from 'consola'
import { REPO_BRANCH, REPO_PATH } from '@element-plus/build-constants'
import { docsDirName } from '@element-plus/build-utils'
-import { languages } from './utils/lang'
-import { features, head, mdPlugin, nav, sidebars } from './config'
+import { languages } from '../utils/lang'
+import { features } from './features'
+import { head } from './head'
+import { nav } from './nav'
+import { mdPlugin } from './plugins'
+import { sidebars } from './sidebars'
+
import type { UserConfig } from 'vitepress'
const buildTransformers = () => {
@@ -41,7 +46,7 @@ languages.forEach((lang) => {
}
})
-export const config: UserConfig = {
+const config: UserConfig = {
title: 'Element Plus',
description: 'A Vue 3 based component library for designers and developers',
lastUpdated: true,
@@ -53,7 +58,6 @@ export const config: UserConfig = {
editLinks: true,
editLinkText: 'Edit this page on GitHub',
- lastUpdated: 'Last Updated',
logo: '/images/element-plus-logo.svg',
logoSmall: '/images/element-plus-logo-small.svg',
@@ -75,12 +79,10 @@ export const config: UserConfig = {
vue: {
template: {
- ssr: true,
compilerOptions: {
directiveTransforms: buildTransformers(),
},
},
},
}
-
export default config
diff --git a/docs/.vitepress/config/index.ts b/docs/.vitepress/config/index.ts
deleted file mode 100644
index ff1b2f98a5..0000000000
--- a/docs/.vitepress/config/index.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-export * from './analytics'
-export * from './features'
-export * from './head'
-export * from './nav'
-export * from './plugins'
-export * from './sidebars'
-export * from './sponsors'
diff --git a/docs/.vitepress/config/plugins.ts b/docs/.vitepress/config/plugins.ts
index e32acc2e89..00272394e9 100644
--- a/docs/.vitepress/config/plugins.ts
+++ b/docs/.vitepress/config/plugins.ts
@@ -1,18 +1,16 @@
import path from 'path'
import fs from 'fs'
-import MarkdownIt from 'markdown-it'
import mdContainer from 'markdown-it-container'
import { docRoot } from '@element-plus/build-utils'
import externalLinkIcon from '../plugins/external-link-icon'
import tableWrapper from '../plugins/table-wrapper'
import tooltip from '../plugins/tooltip'
import tag from '../plugins/tag'
+import headers from '../plugins/headers'
import { ApiTableContainer } from '../plugins/api-table'
-import { highlight } from '../utils/highlight'
import type Token from 'markdown-it/lib/token'
import type Renderer from 'markdown-it/lib/renderer'
-
-const localMd = MarkdownIt().use(tag)
+import type MarkdownIt from 'markdown-it'
interface ContainerOpts {
marker?: string | undefined
@@ -27,6 +25,7 @@ interface ContainerOpts {
}
export const mdPlugin = (md: MarkdownIt) => {
+ md.use(headers)
md.use(externalLinkIcon)
md.use(tableWrapper)
md.use(tooltip)
@@ -53,10 +52,10 @@ export const mdPlugin = (md: MarkdownIt) => {
if (!source) throw new Error(`Incorrect source file: ${sourceFile}`)
return `
${code}
`
-}
-
-export const highlight = (str: string, lang: string) => {
- if (!lang) {
- return wrap(str, 'text')
- }
- lang = lang.toLowerCase()
- const rawLang = lang
- if (lang === 'vue' || lang === 'html') {
- lang = 'markup'
- }
- if (lang === 'md') {
- lang = 'markdown'
- }
- if (lang === 'ts') {
- lang = 'typescript'
- }
- if (lang === 'py') {
- lang = 'python'
- }
- if (!prism.languages[lang]) {
- try {
- loadLanguages([lang])
- } catch {
- // eslint-disable-next-line no-console
- consola.warn(
- chalk.yellow(
- `[vitepress] Syntax highlight for language "${lang}" is not supported.`
- )
- )
- }
- }
- if (prism.languages[lang]) {
- const code = prism.highlight(str, prism.languages[lang], lang)
- return wrap(code, rawLang)
- }
- return wrap(str, 'text')
-}
diff --git a/docs/.vitepress/vitepress/components/common/vp-link.vue b/docs/.vitepress/vitepress/components/common/vp-link.vue
index ac21a04ef4..c40d3f43d4 100644
--- a/docs/.vitepress/vitepress/components/common/vp-link.vue
+++ b/docs/.vitepress/vitepress/components/common/vp-link.vue
@@ -1,12 +1,10 @@
@@ -15,11 +13,11 @@ const isExternal = computed(() => props.href && /^[a-z]+:/i.test(props.href))
class="link-item"
:class="{ link: href }"
:href="href"
- :target="isExternal ? '_blank' : undefined"
- :rel="isExternal ? 'noopener noreferrer' : undefined"
+ :target="isExternal(href) ? '_blank' : undefined"
+ :rel="isExternal(href) ? 'noopener noreferrer' : undefined"
>