|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { ContentNavigationItem } from '@nuxt/content'; |
| 3 | +
|
| 4 | +const props = defineProps<{ |
| 5 | + slug: string; |
| 6 | +}>(); |
| 7 | +
|
| 8 | +const navigation = inject('navigation') as Ref<ContentNavigationItem[]> | undefined; |
| 9 | +
|
| 10 | +const frameworkLabel = computed(() => { |
| 11 | + const node = findNavNode(navigation?.value, `/frameworks/${props.slug}`); |
| 12 | + return node?.title ?? props.slug; |
| 13 | +}); |
| 14 | +
|
| 15 | +const { data: guides } = await useAsyncData(`framework-${props.slug}-guides`, () => |
| 16 | + queryCollection('content') |
| 17 | + .where('path', 'LIKE', `/frameworks/${props.slug}/%`) |
| 18 | + .where('path', 'NOT LIKE', '%/.navigation') |
| 19 | + .where('stem', 'NOT LIKE', '%/index') |
| 20 | + .select('title', 'description', 'path', 'navigation', 'section', 'stem') |
| 21 | + .order('stem', 'ASC') |
| 22 | + .all(), |
| 23 | +); |
| 24 | +
|
| 25 | +const { data: tutorials } = await useAsyncData(`framework-${props.slug}-tutorials`, () => |
| 26 | + queryCollection('content') |
| 27 | + .where('path', 'LIKE', '/tutorials/%') |
| 28 | + .select('title', 'description', 'path', 'technologies') |
| 29 | + .all(), |
| 30 | +); |
| 31 | +
|
| 32 | +type LinkItem = { |
| 33 | + title: string; |
| 34 | + description?: string; |
| 35 | + path: string; |
| 36 | +}; |
| 37 | +
|
| 38 | +const guideTitle = (g: { title: string; navigation?: unknown }) => { |
| 39 | + if (g.navigation && typeof g.navigation === 'object' && 'title' in g.navigation) { |
| 40 | + const navTitle = (g.navigation as { title?: string }).title; |
| 41 | + if (navTitle) return navTitle; |
| 42 | + } |
| 43 | + return g.title; |
| 44 | +}; |
| 45 | +
|
| 46 | +const visibleGuides = computed(() => (guides.value ?? []) |
| 47 | + .filter(g => g.navigation !== false)); |
| 48 | +
|
| 49 | +const startHere = computed<LinkItem[]>(() => |
| 50 | + visibleGuides.value |
| 51 | + .filter(g => g.section === 'start-here') |
| 52 | + .map(g => ({ title: guideTitle(g), description: g.description, path: g.path }))); |
| 53 | +
|
| 54 | +const moreGuides = computed<LinkItem[]>(() => |
| 55 | + visibleGuides.value |
| 56 | + .filter(g => g.section !== 'start-here') |
| 57 | + .map(g => ({ title: guideTitle(g), description: g.description, path: g.path }))); |
| 58 | +
|
| 59 | +const matchingTutorials = computed<LinkItem[]>(() => (tutorials.value ?? []) |
| 60 | + .filter(t => Array.isArray(t.technologies) && t.technologies.includes(props.slug)) |
| 61 | + .sort((a, b) => a.title.localeCompare(b.title)) |
| 62 | + .map(t => ({ title: t.title, description: t.description, path: t.path }))); |
| 63 | +</script> |
| 64 | + |
| 65 | +<template> |
| 66 | + <div class="not-prose space-y-10"> |
| 67 | + <section v-if="startHere.length"> |
| 68 | + <ProseH2 id="start-here"> |
| 69 | + Start Here |
| 70 | + </ProseH2> |
| 71 | + <FrameworkLinkList :items="startHere" /> |
| 72 | + </section> |
| 73 | + |
| 74 | + <section v-if="moreGuides.length"> |
| 75 | + <ProseH2 id="guides"> |
| 76 | + Guides |
| 77 | + </ProseH2> |
| 78 | + <FrameworkLinkList :items="moreGuides" /> |
| 79 | + </section> |
| 80 | + |
| 81 | + <section v-if="matchingTutorials.length"> |
| 82 | + <ProseH2 id="framework-tutorials"> |
| 83 | + {{ frameworkLabel }} Tutorials |
| 84 | + </ProseH2> |
| 85 | + <FrameworkLinkList :items="matchingTutorials" /> |
| 86 | + </section> |
| 87 | + </div> |
| 88 | +</template> |
0 commit comments