@happydesigns/ui 0.16.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -53
- package/app/app.config.ts +138 -165
- package/app/app.vue +0 -2
- package/app/assets/css/styles.css +38 -0
- package/app/components/Carousel.vue +33 -0
- package/app/components/{content/Snippet.vue → Snippet.vue} +6 -2
- package/app/components/article/ArticleGridDate.vue +19 -16
- package/app/components/article/ArticleHeaderBody.vue +26 -20
- package/app/components/article/ArticleHeadlineMeta.vue +37 -26
- package/app/components/article/ArticleList.vue +1 -1
- package/app/components/article/ArticlePage.vue +1 -1
- package/app/components/footer/FooterColumns.vue +60 -101
- package/app/components/search/ContentSearch.client.vue +59 -0
- package/app/components/studio/StudioLoginButton.client.vue +11 -3
- package/app/components/traits/Category.vue +1 -1
- package/app/components/traits/CopyButton.vue +40 -32
- package/app/components/traits/Links.vue +21 -17
- package/app/components/traits/Surround.vue +5 -6
- package/app/components/traits/Toc.vue +18 -16
- package/app/composables/useArticleList.ts +29 -27
- package/app/composables/useClipboard.ts +48 -26
- package/app/composables/useContentSearchData.ts +42 -0
- package/app/composables/useNavigationLinks.ts +40 -0
- package/app/composables/usePageContent.ts +1 -3
- package/app/composables/usePageSeo.ts +7 -15
- package/app/internal/pageLayout.ts +7 -0
- package/app/layouts/article.vue +137 -120
- package/app/layouts/content.vue +63 -59
- package/app/types/config.ts +91 -13
- package/app/utils/createContentSearchLoader.ts +45 -0
- package/app/utils/formatDate.ts +1 -1
- package/app/utils/formatDateTime.ts +1 -1
- package/app/utils/isNavigationTargetActive.ts +12 -0
- package/app/utils/resolveUsers.ts +56 -42
- package/nuxt.config.ts +1 -13
- package/package.json +35 -10
- package/schemas/collections.ts +4 -0
- package/schemas/indexes.ts +10 -0
- package/server/api/navigation.json.get.ts +11 -0
- package/server/api/search.json.get.ts +11 -0
- package/server/utils/contentSearch.ts +67 -0
- package/shared/types/app-config.d.ts +23 -0
- package/app/assets/css/main.css +0 -14
- package/app/components/content/Carousel.vue +0 -11
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import type { PageCollections } from '@nuxt/content'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { PageCollections } from '@nuxt/content'
|
|
3
|
+
|
|
4
|
+
interface HeadlineMetaPage {
|
|
5
|
+
path?: string
|
|
6
|
+
category?: string
|
|
7
|
+
date?: string
|
|
8
|
+
dateEnd?: string
|
|
9
|
+
location?: {
|
|
10
|
+
name?: string
|
|
11
|
+
url?: string
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const props = defineProps<{
|
|
16
|
+
page?: HeadlineMetaPage
|
|
17
|
+
collection?: keyof PageCollections
|
|
18
|
+
}>()
|
|
19
|
+
|
|
20
|
+
const { has } = useVariant(() => props.collection || 'article')
|
|
21
|
+
|
|
22
|
+
const showCategory = computed(() => has('category').value && Boolean(props.page?.category))
|
|
23
|
+
const showDates = computed(() => has('dates').value && Boolean(props.page?.date))
|
|
24
|
+
const showLocation = computed(() => has('location').value && Boolean(props.page?.location?.name))
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div class="all:flex flex-wrap items-center gap-x-3 gap-y-2 text-muted">
|
|
29
|
+
<HCategory v-if="showCategory" :category="page?.category" />
|
|
30
|
+
|
|
31
|
+
<span v-if="showCategory && showDates" class="all:hidden sm:inline opacity-50">·</span>
|
|
32
|
+
<HDates v-if="showDates" :date="page?.date" :date-end="page?.dateEnd" />
|
|
33
|
+
|
|
34
|
+
<span v-if="(showCategory || showDates) && showLocation" class="all:hidden sm:inline opacity-50">·</span>
|
|
35
|
+
<HLocation v-if="showLocation" :location="page?.location" />
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|
|
@@ -56,7 +56,7 @@ const categories = computed(() => {
|
|
|
56
56
|
|
|
57
57
|
<template>
|
|
58
58
|
<div class="all:flex flex-col gap-8">
|
|
59
|
-
<div v-if="!props.category" class="border-b border-
|
|
59
|
+
<div v-if="!props.category" class="border-b border-default">
|
|
60
60
|
<UNavigationMenu
|
|
61
61
|
:items="categories"
|
|
62
62
|
highlight
|
|
@@ -1,101 +1,60 @@
|
|
|
1
|
-
<script setup lang="ts" generic="T extends FooterColumnLink">
|
|
2
|
-
import type { FooterColumn, FooterColumnLink, FooterColumnsProps, FooterColumnsSlots, SlotClass } from '@nuxt/ui'
|
|
3
|
-
import { useAppConfig } from '#imports'
|
|
4
|
-
|
|
5
|
-
interface HFooterColumnProps<T extends FooterColumnLink> extends /* @vue-ignore */ FooterColumnsProps<T> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
function withLayoutClass(base: string, override?: SlotClass): SlotClass {
|
|
26
|
-
if (typeof override === 'function')
|
|
27
|
-
return defaults => [base, override(defaults)]
|
|
28
|
-
|
|
29
|
-
return [base, override]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const ui = computed(() => ({
|
|
33
|
-
...props.ui,
|
|
34
|
-
root: withLayoutClass('footer-cols-root all:grid grid-flow-row gap-y-12 gap-x-8', props.ui?.root),
|
|
35
|
-
left: withLayoutClass('footer-cols-left', props.ui?.left),
|
|
36
|
-
center: withLayoutClass('footer-cols-center', props.ui?.center),
|
|
37
|
-
right: withLayoutClass('footer-cols-right', props.ui?.right),
|
|
38
|
-
}))
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
>
|
|
53
|
-
<template v-if="
|
|
54
|
-
<slot name="left" />
|
|
55
|
-
</template>
|
|
56
|
-
<template v-if="
|
|
57
|
-
<slot name="right" />
|
|
58
|
-
</template>
|
|
59
|
-
</UFooterColumns>
|
|
60
|
-
</template>
|
|
61
|
-
|
|
62
|
-
<style>
|
|
63
|
-
@import "tailwindcss" source("../..");
|
|
64
|
-
|
|
65
|
-
.footer-cols-left {
|
|
66
|
-
grid-column: span var(--span-left);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
.footer-cols-center {
|
|
70
|
-
grid-column: span var(--span-center);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.footer-cols-right {
|
|
74
|
-
grid-column: span var(--span-right);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.footer-cols-left,
|
|
78
|
-
.footer-cols-center,
|
|
79
|
-
.footer-cols-right {
|
|
80
|
-
display: contents;
|
|
81
|
-
}
|
|
82
|
-
.footer-cols-root {
|
|
83
|
-
grid-template-columns: repeat(var(--cols-sm), minmax(0, 1fr));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
@media (min-width: theme(--breakpoint-lg)) {
|
|
87
|
-
.footer-cols-root {
|
|
88
|
-
grid-template-columns: repeat(var(--cols-lg), minmax(0, 1fr));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
@media (min-width: theme(--breakpoint-xl)) {
|
|
93
|
-
.footer-cols-root {
|
|
94
|
-
grid-template-columns: repeat(var(--cols-xl), minmax(0, 1fr));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
.footer-cols-root p:last-child {
|
|
99
|
-
margin-bottom: 0;
|
|
100
|
-
}
|
|
101
|
-
</style>
|
|
1
|
+
<script setup lang="ts" generic="T extends FooterColumnLink">
|
|
2
|
+
import type { FooterColumn, FooterColumnLink, FooterColumnsProps, FooterColumnsSlots, SlotClass } from '@nuxt/ui'
|
|
3
|
+
import { useAppConfig } from '#imports'
|
|
4
|
+
|
|
5
|
+
interface HFooterColumnProps<T extends FooterColumnLink> extends /* @vue-ignore */ FooterColumnsProps<T> {
|
|
6
|
+
/** Fixed column count from the lg breakpoint. Defaults to responsive auto-fit. */
|
|
7
|
+
lgCols?: number
|
|
8
|
+
/** Fixed column count from the xl breakpoint. Defaults to responsive auto-fit. */
|
|
9
|
+
xlCols?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const props = defineProps<HFooterColumnProps<T>>()
|
|
13
|
+
const slots = defineSlots<FooterColumnsSlots<T>>()
|
|
14
|
+
const appConfig = useAppConfig()
|
|
15
|
+
|
|
16
|
+
const footerColumns = computed<FooterColumn<T>[]>(() => (
|
|
17
|
+
props.columns
|
|
18
|
+
?? (appConfig.app.links.footer as FooterColumn<T>[] | undefined)
|
|
19
|
+
?? []
|
|
20
|
+
))
|
|
21
|
+
|
|
22
|
+
const hasLeft = Boolean(slots.left)
|
|
23
|
+
const hasRight = Boolean(slots.right)
|
|
24
|
+
|
|
25
|
+
function withLayoutClass(base: string, override?: SlotClass): SlotClass {
|
|
26
|
+
if (typeof override === 'function')
|
|
27
|
+
return defaults => [base, override(defaults)]
|
|
28
|
+
|
|
29
|
+
return [base, override]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const ui = computed(() => ({
|
|
33
|
+
...props.ui,
|
|
34
|
+
root: withLayoutClass('footer-cols-root all:grid grid-flow-row gap-y-12 gap-x-8', props.ui?.root),
|
|
35
|
+
left: withLayoutClass('footer-cols-left', props.ui?.left),
|
|
36
|
+
center: withLayoutClass('footer-cols-center', props.ui?.center),
|
|
37
|
+
right: withLayoutClass('footer-cols-right', props.ui?.right),
|
|
38
|
+
}))
|
|
39
|
+
|
|
40
|
+
const layoutStyle = computed(() => ({
|
|
41
|
+
...(props.lgCols === undefined ? {} : { '--cols-lg': props.lgCols }),
|
|
42
|
+
...(props.xlCols === undefined ? {} : { '--cols-xl': props.xlCols }),
|
|
43
|
+
}))
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<template>
|
|
47
|
+
<UFooterColumns
|
|
48
|
+
v-bind="props"
|
|
49
|
+
:columns="footerColumns"
|
|
50
|
+
:ui="ui"
|
|
51
|
+
:style="layoutStyle"
|
|
52
|
+
>
|
|
53
|
+
<template v-if="hasLeft" #left>
|
|
54
|
+
<slot name="left" />
|
|
55
|
+
</template>
|
|
56
|
+
<template v-if="hasRight" #right>
|
|
57
|
+
<slot name="right" />
|
|
58
|
+
</template>
|
|
59
|
+
</UFooterColumns>
|
|
60
|
+
</template>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { CommandPaletteGroup } from '@nuxt/ui'
|
|
3
|
+
|
|
4
|
+
const appConfig = useAppConfig()
|
|
5
|
+
const { open } = useContentSearch()
|
|
6
|
+
const search = computed(() => appConfig.app.search)
|
|
7
|
+
const searchTerm = ref('')
|
|
8
|
+
const { navigation, files, status, error, load } = useContentSearchData()
|
|
9
|
+
|
|
10
|
+
const groups = computed<CommandPaletteGroup[]>(() => {
|
|
11
|
+
const configuredGroups = search.value.groups ?? []
|
|
12
|
+
|
|
13
|
+
if (!error.value) {
|
|
14
|
+
return configuredGroups
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
id: 'search-error',
|
|
20
|
+
label: search.value.error?.title,
|
|
21
|
+
ignoreFilter: true,
|
|
22
|
+
items: [
|
|
23
|
+
{
|
|
24
|
+
label: search.value.error?.retryLabel,
|
|
25
|
+
description: search.value.error?.description,
|
|
26
|
+
icon: 'i-lucide-refresh-cw',
|
|
27
|
+
onSelect: () => void load(),
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
...configuredGroups,
|
|
32
|
+
]
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
watch(open, (isOpen) => {
|
|
36
|
+
if (isOpen) {
|
|
37
|
+
void load().then(() => {
|
|
38
|
+
if (error.value) {
|
|
39
|
+
console.error('Failed to load the search index.', error.value)
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}, { immediate: true })
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<template>
|
|
47
|
+
<UContentSearch
|
|
48
|
+
v-model:search-term="searchTerm"
|
|
49
|
+
:title="search.title"
|
|
50
|
+
:description="search.description"
|
|
51
|
+
:placeholder="search.placeholder"
|
|
52
|
+
:links="search.links"
|
|
53
|
+
:groups="groups"
|
|
54
|
+
:files="files"
|
|
55
|
+
:navigation="navigation"
|
|
56
|
+
:loading="status === 'pending'"
|
|
57
|
+
:fuse="{ resultLimit: search.resultLimit }"
|
|
58
|
+
/>
|
|
59
|
+
</template>
|
|
@@ -13,15 +13,23 @@ withDefaults(defineProps<{
|
|
|
13
13
|
icon: 'i-lucide-log-in',
|
|
14
14
|
})
|
|
15
15
|
|
|
16
|
-
interface StudioSession {
|
|
17
|
-
user?: StudioUser | null
|
|
16
|
+
interface StudioSession {
|
|
17
|
+
user?: StudioUser | null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface StudioRuntimeConfig {
|
|
21
|
+
dev?: boolean
|
|
22
|
+
route?: string
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
const runtimeConfig = useRuntimeConfig()
|
|
21
26
|
const sessionCheckCookie = useCookie<string | null>('studio-session-check')
|
|
22
27
|
const sessionUser = ref<StudioUser | null | undefined>()
|
|
23
28
|
|
|
24
|
-
const studio = computed(() =>
|
|
29
|
+
const studio = computed<StudioRuntimeConfig>(() => {
|
|
30
|
+
const config = runtimeConfig.public.studio
|
|
31
|
+
return config && typeof config === 'object' ? config as StudioRuntimeConfig : {}
|
|
32
|
+
})
|
|
25
33
|
const studioRoute = computed(() => studio.value.route || '/_studio')
|
|
26
34
|
|
|
27
35
|
onMounted(async () => {
|
|
@@ -1,32 +1,40 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
const props = defineProps<{
|
|
3
|
-
path?: string
|
|
4
|
-
icon?: string
|
|
5
|
-
label?: string
|
|
6
|
-
successIcon?: string
|
|
7
|
-
successLabel?: string
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
const props = defineProps<{
|
|
3
|
+
path?: string
|
|
4
|
+
icon?: string
|
|
5
|
+
label?: string
|
|
6
|
+
successIcon?: string
|
|
7
|
+
successLabel?: string
|
|
8
|
+
errorIcon?: string
|
|
9
|
+
errorLabel?: string
|
|
10
|
+
}>()
|
|
11
|
+
|
|
12
|
+
const { copy } = useClipboard()
|
|
13
|
+
const url = useRequestURL()
|
|
14
|
+
const route = useRoute()
|
|
15
|
+
|
|
16
|
+
async function copyLink() {
|
|
17
|
+
await copy(`${url.origin}${props.path ?? route.path}`, {
|
|
18
|
+
id: 'article-copy-link',
|
|
19
|
+
title: props.successLabel,
|
|
20
|
+
icon: props.successIcon,
|
|
21
|
+
error: {
|
|
22
|
+
id: 'article-copy-link-error',
|
|
23
|
+
title: props.errorLabel,
|
|
24
|
+
icon: props.errorIcon,
|
|
25
|
+
color: 'error',
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<template>
|
|
32
|
+
<UButton
|
|
33
|
+
:icon="icon"
|
|
34
|
+
variant="ghost"
|
|
35
|
+
color="neutral"
|
|
36
|
+
@click="copyLink"
|
|
37
|
+
>
|
|
38
|
+
{{ label }}
|
|
39
|
+
</UButton>
|
|
40
|
+
</template>
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
v-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { PageCollections } from '@nuxt/content'
|
|
3
|
+
import type { ButtonProps } from '@nuxt/ui'
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{
|
|
6
|
+
links?: PageCollections['event']['links']
|
|
7
|
+
}>()
|
|
8
|
+
|
|
9
|
+
// Nuxt Content preserves the inherited schema shape but widens a few DOM props to unknown.
|
|
10
|
+
const buttonLinks = computed(() => props.links as ButtonProps[] | undefined)
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<UButton
|
|
15
|
+
v-for="(link, index) in buttonLinks"
|
|
16
|
+
:key="index"
|
|
17
|
+
variant="subtle"
|
|
18
|
+
size="sm"
|
|
19
|
+
v-bind="link"
|
|
20
|
+
/>
|
|
21
|
+
</template>
|
|
@@ -11,28 +11,27 @@ const props = defineProps<{
|
|
|
11
11
|
}>()
|
|
12
12
|
|
|
13
13
|
const route = useRoute()
|
|
14
|
-
const collection = computed(() => props.collection
|
|
14
|
+
const collection = computed(() => props.collection)
|
|
15
15
|
const path = computed(() => route.path)
|
|
16
16
|
const key = computed(() => `surround-${String(collection.value)}-${path.value}`)
|
|
17
17
|
|
|
18
18
|
const { data: surround } = await useAsyncData(
|
|
19
19
|
key,
|
|
20
20
|
() => {
|
|
21
|
-
const colName = collection.value as any
|
|
22
21
|
const qc = props.query || {}
|
|
23
22
|
|
|
24
|
-
const fields = (qc.fields || ['title', 'description', 'published']) as
|
|
23
|
+
const fields = (qc.fields || ['title', 'description', 'published']) as Array<keyof PageCollections[C]>
|
|
25
24
|
const order = qc.order
|
|
26
25
|
const where = qc.where || [{ field: 'published', operator: '=', value: true }]
|
|
27
26
|
|
|
28
|
-
let query = queryCollectionItemSurroundings(
|
|
27
|
+
let query = queryCollectionItemSurroundings(collection.value, path.value, { fields })
|
|
29
28
|
|
|
30
29
|
where.forEach((filter) => {
|
|
31
|
-
query = query.where(filter.field
|
|
30
|
+
query = query.where(filter.field, filter.operator, filter.value)
|
|
32
31
|
})
|
|
33
32
|
|
|
34
33
|
if (order) {
|
|
35
|
-
query = query.order(order.field as
|
|
34
|
+
query = query.order(order.field as keyof PageCollections[C], order.direction)
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
return query
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { ContentTocLink } from '@nuxt/ui'
|
|
3
|
+
|
|
4
|
+
defineProps<{
|
|
5
|
+
links?: ContentTocLink[]
|
|
6
|
+
title?: string
|
|
7
|
+
}>()
|
|
8
|
+
|
|
9
|
+
const appConfig = useAppConfig()
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<UContentToc
|
|
14
|
+
v-if="links?.length"
|
|
15
|
+
:links="links"
|
|
16
|
+
:title="title || appConfig.app.toc?.title"
|
|
17
|
+
/>
|
|
18
|
+
</template>
|
|
@@ -6,7 +6,7 @@ import { computed, toValue } from 'vue'
|
|
|
6
6
|
export interface ArticleFilter {
|
|
7
7
|
field: string
|
|
8
8
|
operator: SQLOperator
|
|
9
|
-
value?:
|
|
9
|
+
value?: unknown
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface UseArticleListOptions<C extends keyof PageCollections = 'article'> {
|
|
@@ -63,13 +63,10 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
|
|
|
63
63
|
const queryKey = computed(() => `${String(collection.value)}-list-${page.value}-${itemsPerPage.value}-${category.value || 'all'}-${labelAll.value}-${JSON.stringify(where.value)}-${JSON.stringify(sort.value)}-${publishedOnly.value}`)
|
|
64
64
|
|
|
65
65
|
return useAsyncData(queryKey, async () => {
|
|
66
|
-
//
|
|
67
|
-
// This avoids 'any' while still allowing the query to work with generic collections
|
|
66
|
+
// The result keeps consumer collection fields together with the article fields used by the UI.
|
|
68
67
|
type ArticleItem = Collections[C] & Collections['article']
|
|
69
|
-
type ArticleQueryBuilder = ReturnType<typeof queryCollection<'article'>>
|
|
70
|
-
|
|
71
68
|
const getDataQuery = () => {
|
|
72
|
-
let query = queryCollection(collection.value)
|
|
69
|
+
let query = queryCollection(collection.value)
|
|
73
70
|
|
|
74
71
|
if (publishedOnly.value) {
|
|
75
72
|
query = query.where('published', '=', true)
|
|
@@ -82,7 +79,7 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
|
|
|
82
79
|
// Apply additional filters
|
|
83
80
|
if (where.value && Array.isArray(where.value)) {
|
|
84
81
|
where.value.forEach((filter) => {
|
|
85
|
-
query = query.where(filter.field
|
|
82
|
+
query = query.where(filter.field, filter.operator, filter.value)
|
|
86
83
|
})
|
|
87
84
|
}
|
|
88
85
|
return query
|
|
@@ -91,16 +88,25 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
|
|
|
91
88
|
let finalQuery = getDataQuery()
|
|
92
89
|
|
|
93
90
|
if (sort.value) {
|
|
94
|
-
finalQuery = finalQuery.order(sort.value.field as
|
|
91
|
+
finalQuery = finalQuery.order(sort.value.field as keyof Collections[C], sort.value.direction)
|
|
95
92
|
}
|
|
96
93
|
|
|
97
|
-
const articles = await
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
94
|
+
const [articles, total] = await Promise.all([
|
|
95
|
+
finalQuery
|
|
96
|
+
.skip((page.value - 1) * itemsPerPage.value)
|
|
97
|
+
.limit(itemsPerPage.value)
|
|
98
|
+
.all() as Promise<ArticleItem[]>,
|
|
99
|
+
getDataQuery().count() as Promise<number>,
|
|
100
|
+
])
|
|
101
|
+
|
|
102
|
+
const userProps = config.value.user ?? {}
|
|
103
|
+
const authorsByUsername = await resolveUserMap(
|
|
104
|
+
articles.flatMap(article => article.authors ?? []),
|
|
105
|
+
userProps,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
// Resolve display details without issuing additional collection queries.
|
|
109
|
+
const resolved = articles.map((article) => {
|
|
104
110
|
// Resolve Category Badge directly
|
|
105
111
|
const categoryKey = article.category
|
|
106
112
|
let resolvedBadge: BadgeProps | undefined
|
|
@@ -112,23 +118,19 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
|
|
|
112
118
|
}
|
|
113
119
|
}
|
|
114
120
|
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
// Preserve the author order declared in front matter.
|
|
122
|
+
const resolvedAuthors = (article.authors ?? []).flatMap((username) => {
|
|
123
|
+
const author = authorsByUsername.get(username)
|
|
124
|
+
return author ? [author] : []
|
|
125
|
+
})
|
|
126
|
+
|
|
122
127
|
return {
|
|
123
128
|
...article,
|
|
124
129
|
resolvedBadge,
|
|
125
130
|
resolvedAuthors,
|
|
126
131
|
}
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
// Total count for pagination
|
|
130
|
-
const total = await getDataQuery().count() as number
|
|
131
|
-
|
|
132
|
+
})
|
|
133
|
+
|
|
132
134
|
return {
|
|
133
135
|
articles: resolved,
|
|
134
136
|
total,
|