mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-21 02:50:11 +08:00
9408e7eb76
* feat(docs): document add changelog page - Add changelog and markdown component for changelog.md - Add changelog page - Add some locale for change log - Fix a bug that caused ToC not working * Add minimal width to changelog selector * Add width to changelog selector * fix selector width issue
72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
import {
|
|
isActive,
|
|
normalize,
|
|
endingSlashRE,
|
|
isExternal,
|
|
} from 'vitepress/dist/client/theme-default/utils'
|
|
|
|
import type { Route } from 'vitepress'
|
|
|
|
export * from 'vitepress/dist/client/theme-default/utils'
|
|
|
|
export const throttleAndDebounce = (fn: () => any, delay: number) => {
|
|
let timeout: ReturnType<typeof setTimeout>
|
|
let called = false
|
|
return () => {
|
|
if (timeout) {
|
|
clearTimeout(timeout)
|
|
}
|
|
if (!called) {
|
|
fn()
|
|
called = true
|
|
setTimeout(() => {
|
|
called = false
|
|
}, delay)
|
|
} else {
|
|
timeout = setTimeout(fn, delay)
|
|
}
|
|
}
|
|
}
|
|
|
|
// When match === true, meaning `path` is a string for build regex
|
|
export const isActiveLink = (
|
|
route: Route,
|
|
pathPattern: string,
|
|
match?: boolean
|
|
) => {
|
|
if (!match) return isActive(route, pathPattern)
|
|
const regex = new RegExp(pathPattern)
|
|
|
|
return regex.test(normalize(`/${route.data.relativePath}`))
|
|
}
|
|
|
|
export function createGitHubUrl(
|
|
docsRepo: string,
|
|
docsDir: string,
|
|
docsBranch: string,
|
|
path: string,
|
|
folder = 'examples/',
|
|
ext = '.vue'
|
|
) {
|
|
const base = isExternal(docsRepo)
|
|
? docsRepo
|
|
: `https://github.com/${docsRepo}`
|
|
return `${base.replace(endingSlashRE, '')}/edit/${docsBranch}/${
|
|
docsDir ? `${docsDir.replace(endingSlashRE, '')}/` : ''
|
|
}${folder || ''}${path}${ext || ''}`
|
|
}
|
|
|
|
export const isServer = typeof window === 'undefined'
|
|
|
|
export function createCrowdinUrl(targetLang: string) {
|
|
let translateLang = ''
|
|
// for zh-CN zh-HK zh-TW, maybe later we will have cases like Chinese lang
|
|
// for now we just keep it as simple as possible.
|
|
if (targetLang.startsWith('zh-')) {
|
|
translateLang = targetLang.split('-').join('').toLocaleLowerCase()
|
|
} else {
|
|
translateLang = targetLang.split('-').shift().toLocaleLowerCase()
|
|
}
|
|
return `https://crowdin.com/translate/element-plus/all/en-${translateLang}`
|
|
}
|