fix(docs): restore official visual hierarchy and component previews

This commit is contained in:
maoyingjie
2026-10-24 07:26:15 +08:00
parent 671a27646e
commit c2563e87a8
10 changed files with 177 additions and 83 deletions
+35 -9
View File
@@ -1,14 +1,20 @@
<script setup lang="ts">
import { computed } from "vue";
import { Card, CardTitle, CardDescription } from "@heroui-vue/components";
import { computed, ref } from "vue";
import { Card, Link } from "@heroui-vue/components";
import { withBase } from "vitepress";
import { IconArrowUpRight } from "@tabler/icons-vue";
import { searchIndex } from "virtual:docs-data";
import { componentItems } from "./navigation";
const props = defineProps<{ category: string }>();
const items = computed(() =>
componentItems.filter((item) => item.category === props.category),
);
const failed = ref(new Set<string>());
function imageName(title: string) {
return title.split(" ")[0].toLowerCase();
}
function thumbnail(title: string, theme: "light" | "dark") {
return `https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/related-components/${theme}-${imageName(title)}.png`;
}
function description(url: string) {
return (
searchIndex.find((entry) => entry.url === url && entry.section === "概览")
@@ -21,16 +27,36 @@ function description(url: string) {
<Card
v-for="item in items"
:key="item.url"
as="a"
:href="withBase(item.url)"
class="component-index-card"
variant="transparent"
>
<CardTitle>
<div class="component-index-preview" aria-hidden="true">
<template v-for="theme in ['light', 'dark'] as const" :key="theme">
<img
v-if="!failed.has(theme + item.url)"
:class="'component-thumbnail-' + theme"
:src="thumbnail(item.title, theme)"
alt=""
loading="lazy"
decoding="async"
width="874"
height="594"
@error="failed.add(theme + item.url)"
/>
<div
v-else
:class="
'component-thumbnail-' + theme + ' component-thumbnail-fallback'
"
>
<strong>{{ item.title.split(" ")[0] }}</strong>
<span>{{ description(item.url) }}</span>
</div>
</template>
</div>
<Link :href="withBase(item.url)" class="component-index-title">
{{ item.title }}
<IconArrowUpRight aria-hidden="true" :size="16" />
</CardTitle>
<CardDescription>{{ description(item.url) }}</CardDescription>
</Link>
</Card>
</div>
</template>