perf: improve jump link for home page (#3551)

This commit is contained in:
zouhang 2021-09-22 22:37:35 +08:00 committed by GitHub
parent a887a9632e
commit b8cf646226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -1,4 +1,6 @@
/* eslint-disable */
const fs = require('fs')
const path = require('path')
const sidebars = require('./sidebars')
const nav = require('./nav')
const mdPlugin = require('./plugins')
@ -31,6 +33,8 @@ const buildTransformers = () => {
}
console.log(process.env.DOC_ENV)
const languages = fs.readdirSync(path.resolve(__dirname, './crowdin'))
module.exports = {
title: 'ElementPlus',
head: [
@ -84,6 +88,7 @@ module.exports = {
appId: '7DCTSU0WBW',
},
features,
langs: languages,
},
markdown: {

View File

@ -1,5 +1,6 @@
<script setup lang="ts">
import { useData } from 'vitepress'
import { useData, inBrowser } from 'vitepress'
import { computed } from 'vue'
import VPNavbarSearch from './navbar/vp-search.vue'
import VPNavbarMenu from './navbar/vp-menu.vue'
@ -17,13 +18,22 @@ defineEmits(['toggle'])
const themeEnabled = useFeatureFlag('theme')
const { theme } = useData()
const currentLink = computed(() => {
if (!inBrowser) return '/'
const existLangIndex = theme.value.langs.findIndex((lang) =>
window?.location?.pathname.startsWith(`/${lang}`)
)
return existLangIndex === -1 ? '/' : `/${theme.value.langs[existLangIndex]}/`
})
</script>
<template>
<div class="navbar-wrapper">
<div class="container">
<div class="logo-container">
<a href="/">
<a :href="currentLink">
<img
class="logo"
src="/images/element-plus-logo.svg"