fix(docs): restore official visual hierarchy and component previews
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user