/
navbar.ts
70 lines (62 loc) · 1.54 KB
/
navbar.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type { Plugin } from 'vite'
export default function NavbarFix(): Plugin {
return {
name: 'vitepress-sidebar-logo-fix',
enforce: 'pre',
transform(code, id) {
if (id.includes('VPNavBarTitle.vue') && !id.endsWith('.css') && !id.includes('&setup=')) {
return `
<script setup lang="ts">
import { useData } from 'vitepress'
import { useSidebar } from '../composables/sidebar'
const { site, theme } = useData()
const { hasSidebar } = useSidebar()
</script>
<template>
<div class="VPNavBarTitle" :class="{ 'has-sidebar': hasSidebar }">
<a class="title" :href="site.base">
Vite Plugin 
<img dark-logo class="logo" src="/icon_dark.svg" alt="Vite PWA Plugin dark logo" width="50" height="50">
<img light-logo class="logo" src="/icon_light.svg" alt="Vite PWA Plugin light logo" width="50" height="50">
</a>
</div>
</template>
<style scoped>
.VPNavBarTitle {
flex-shrink: 0;
border-bottom: 1px solid transparent;
}
@media (min-width: 960px) {
.VPNavBarTitle.has-sidebar {
margin-right: 32px;
width: calc(var(--vp-sidebar-width) - 64px);
border-bottom-color: var(--vp-c-divider-light);
background-color: var(--vp-c-bg-alt);
}
}
.title {
display: flex;
align-items: center;
width: 100%;
height: var(--vp-nav-height);
font-size: 1.3rem;
line-height: 2rem;
font-weight: 600;
color: var(--vp-c-text-1);
transition: opacity 0.25s;
}
@media (min-width: 960px) {
.title {
flex-shrink: 0;
}
}
.logo {
width: 50px;
height: 50px;
}
</style>
`
}
},
}
}