docs/.vitepress/theme/components/SidebarCard.vue

ba4f23d3bab9e2bb3b8efdb22317c8cc8f353ec5
wotaku/docs/.vitepress/theme/components/SidebarCard.vue history · blame · raw

64 lines · 1659 bytes

 1<!--
 2  All Rights Reserved
 3
 4  Copyright (c) 2025 taskylizard
 5
 6  All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
 7-->
 8<script setup lang="ts">
 9import { computed, watch } from 'vue'
10import { useData } from 'vitepress'
11import { useStorage } from '@vueuse/core'
12import { AccentColorStorageKey } from '../constants'
13
14const { isDark } = useData()
15const accentColor = useStorage(AccentColorStorageKey, 'ayanami')
16
17const accentImageMap: Record<string, string> = {
18  ayanami: 'rei',
19  asuka: 'asuka',
20  miku: 'miku',
21  inanis: 'ina',
22  amelia: 'ame',
23  baelz: 'bae',
24  irys: 'irys',
25  suisei: 'suisei',
26}
27
28const sidebarImage = computed(() => {
29  if (accentColor.value === 'fubuki') {
30    return isDark.value ? '/sidebar/fubuki.avif' : '/sidebar/kuro.avif'
31  }
32  const name = accentImageMap[accentColor.value] ?? 'rei'
33  return `/sidebar/${name}.avif`
34})
35
36if (typeof document !== 'undefined') {
37  watch(
38    sidebarImage,
39    (src) => {
40      document.documentElement.style.setProperty(
41        '--wk-sidebar-banner',
42        `url("${src}")`
43      )
44    },
45    { immediate: true }
46  )
47}
48</script>
49
50<template>
51  <div
52    class="sidebar-banner mt-2 overflow-hidden rounded-xl border-2 border-solid border-[#3d3d3d] relative z-0 max-md:border-2 max-md:border-[#3d3d3d]"
53  />
54</template>
55
56<style scoped>
57.sidebar-banner {
58  aspect-ratio: 3 / 1;
59  background-image: var(--wk-sidebar-banner, url('/sidebar/rei.avif'));
60  background-size: cover;
61  background-position: center;
62  pointer-events: none;
63}
64</style>