@happydesigns/ui 0.15.1 → 0.17.0
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 +64 -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/ArticleGrid.vue +4 -4
- 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 +5 -5
- 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 +6 -7
- package/app/components/traits/Toc.vue +18 -16
- package/app/composables/useArticleList.ts +37 -46
- 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 +4 -16
- package/package.json +17 -9
- package/schemas/collections.ts +4 -0
- package/schemas/indexes.ts +10 -0
- package/schemas/traits.ts +9 -4
- 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
|
@@ -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'> {
|
|
@@ -20,8 +20,8 @@ export interface UseArticleListOptions<C extends keyof PageCollections = 'articl
|
|
|
20
20
|
where?: MaybeRefOrGetter<ArticleFilter[] | undefined>
|
|
21
21
|
/** Field to sort by. Set to false to disable default sorting. Defaults to { field: 'date', direction: 'DESC' }. */
|
|
22
22
|
sort?: MaybeRefOrGetter<{ field: string, direction: 'ASC' | 'DESC' } | false | undefined>
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/** Whether to return only published entries. Defaults to true. */
|
|
24
|
+
publishedOnly?: MaybeRefOrGetter<boolean | undefined>
|
|
25
25
|
/** Whether the list should load lazily during client-side navigation. Defaults to false. */
|
|
26
26
|
lazy?: MaybeRefOrGetter<boolean | undefined>
|
|
27
27
|
}
|
|
@@ -45,8 +45,8 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
|
|
|
45
45
|
if (w)
|
|
46
46
|
return w
|
|
47
47
|
|
|
48
|
-
// Fallback to config where but filter out
|
|
49
|
-
return config.value.query?.where?.filter(f => f.field !== '
|
|
48
|
+
// Fallback to config where but filter out publication if handled separately
|
|
49
|
+
return config.value.query?.where?.filter(f => f.field !== 'published') || []
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
const sort = computed(() => {
|
|
@@ -57,33 +57,19 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
|
|
|
57
57
|
return config.value.query?.order
|
|
58
58
|
})
|
|
59
59
|
|
|
60
|
-
const
|
|
61
|
-
const s = toValue(options.status)
|
|
62
|
-
if (s === false)
|
|
63
|
-
return false
|
|
64
|
-
|
|
65
|
-
if (s)
|
|
66
|
-
return s
|
|
67
|
-
|
|
68
|
-
// Try to find status in config where
|
|
69
|
-
const statusFilter = config.value.query?.where?.find(f => f.field === 'status')
|
|
70
|
-
return statusFilter?.value || 'published'
|
|
71
|
-
})
|
|
60
|
+
const publishedOnly = computed(() => toValue(options.publishedOnly) ?? true)
|
|
72
61
|
|
|
73
62
|
// The key must be reactive and stable
|
|
74
|
-
const queryKey = computed(() => `${String(collection.value)}-list-${page.value}-${itemsPerPage.value}-${category.value || 'all'}-${labelAll.value}-${JSON.stringify(where.value)}-${JSON.stringify(sort.value)}-${
|
|
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}`)
|
|
75
64
|
|
|
76
65
|
return useAsyncData(queryKey, async () => {
|
|
77
|
-
//
|
|
78
|
-
// 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.
|
|
79
67
|
type ArticleItem = Collections[C] & Collections['article']
|
|
80
|
-
type ArticleQueryBuilder = ReturnType<typeof queryCollection<'article'>>
|
|
81
|
-
|
|
82
68
|
const getDataQuery = () => {
|
|
83
|
-
let query = queryCollection(collection.value)
|
|
69
|
+
let query = queryCollection(collection.value)
|
|
84
70
|
|
|
85
|
-
if (
|
|
86
|
-
query = query.where('
|
|
71
|
+
if (publishedOnly.value) {
|
|
72
|
+
query = query.where('published', '=', true)
|
|
87
73
|
}
|
|
88
74
|
|
|
89
75
|
if (category.value && category.value !== labelAll.value) {
|
|
@@ -93,7 +79,7 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
|
|
|
93
79
|
// Apply additional filters
|
|
94
80
|
if (where.value && Array.isArray(where.value)) {
|
|
95
81
|
where.value.forEach((filter) => {
|
|
96
|
-
query = query.where(filter.field
|
|
82
|
+
query = query.where(filter.field, filter.operator, filter.value)
|
|
97
83
|
})
|
|
98
84
|
}
|
|
99
85
|
return query
|
|
@@ -102,16 +88,25 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
|
|
|
102
88
|
let finalQuery = getDataQuery()
|
|
103
89
|
|
|
104
90
|
if (sort.value) {
|
|
105
|
-
finalQuery = finalQuery.order(sort.value.field as
|
|
91
|
+
finalQuery = finalQuery.order(sort.value.field as keyof Collections[C], sort.value.direction)
|
|
106
92
|
}
|
|
107
93
|
|
|
108
|
-
const articles = await
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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) => {
|
|
115
110
|
// Resolve Category Badge directly
|
|
116
111
|
const categoryKey = article.category
|
|
117
112
|
let resolvedBadge: BadgeProps | undefined
|
|
@@ -123,23 +118,19 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
|
|
|
123
118
|
}
|
|
124
119
|
}
|
|
125
120
|
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
|
|
133
127
|
return {
|
|
134
128
|
...article,
|
|
135
129
|
resolvedBadge,
|
|
136
130
|
resolvedAuthors,
|
|
137
131
|
}
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
// Total count for pagination
|
|
141
|
-
const total = await getDataQuery().count() as number
|
|
142
|
-
|
|
132
|
+
})
|
|
133
|
+
|
|
143
134
|
return {
|
|
144
135
|
articles: resolved,
|
|
145
136
|
total,
|
|
@@ -1,26 +1,48 @@
|
|
|
1
|
-
import type { ToastProps } from '#ui/types'
|
|
2
|
-
import { useClipboard as _useClipboard } from '@vueuse/core'
|
|
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
|
+
import type { ToastProps } from '#ui/types'
|
|
2
|
+
import { useClipboard as _useClipboard } from '@vueuse/core'
|
|
3
|
+
|
|
4
|
+
type ClipboardToast = Partial<ToastProps> & { id?: string | number }
|
|
5
|
+
|
|
6
|
+
export type ClipboardCopyOptions = ClipboardToast & {
|
|
7
|
+
error?: ClipboardToast
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useClipboard() {
|
|
11
|
+
const { copy: copyToClipboard, copied } = _useClipboard()
|
|
12
|
+
const toast = useToast()
|
|
13
|
+
|
|
14
|
+
function upsertToast(options: ClipboardToast) {
|
|
15
|
+
const { id, ...toastOptions } = options
|
|
16
|
+
|
|
17
|
+
if (id !== undefined && toast.toasts.value.some(toastItem => toastItem.id === id)) {
|
|
18
|
+
toast.update(id, toastOptions)
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
toast.add(id === undefined ? toastOptions : { ...toastOptions, id })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const copy = async (source: string, options?: ClipboardCopyOptions): Promise<boolean> => {
|
|
26
|
+
const { error: errorToast, ...successToast } = options ?? {}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
await copyToClipboard(source)
|
|
30
|
+
|
|
31
|
+
if (Object.keys(successToast).length > 0)
|
|
32
|
+
upsertToast(successToast)
|
|
33
|
+
|
|
34
|
+
return true
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
if (errorToast)
|
|
38
|
+
upsertToast(errorToast)
|
|
39
|
+
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
copy,
|
|
46
|
+
copied,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ContentNavigationItem } from '@nuxt/content'
|
|
2
|
+
import type { ContentSearchFile } from '@nuxt/ui'
|
|
3
|
+
import { createContentSearchLoader } from '../utils/createContentSearchLoader'
|
|
4
|
+
|
|
5
|
+
export interface ContentSearchDataLoaders {
|
|
6
|
+
navigation?: () => Promise<ContentNavigationItem[]>
|
|
7
|
+
files?: () => Promise<ContentSearchFile[]>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useContentSearchData(loaders: ContentSearchDataLoaders = {}) {
|
|
11
|
+
const navigation = shallowRef<ContentNavigationItem[]>([])
|
|
12
|
+
const files = shallowRef<ContentSearchFile[]>([])
|
|
13
|
+
const status = ref<'idle' | 'pending' | 'success' | 'error'>('idle')
|
|
14
|
+
const error = shallowRef<Error>()
|
|
15
|
+
|
|
16
|
+
const loader = createContentSearchLoader({
|
|
17
|
+
navigation: loaders.navigation ?? (() => $fetch<ContentNavigationItem[]>('/api/navigation.json')),
|
|
18
|
+
files: loaders.files ?? (() => $fetch<ContentSearchFile[]>('/api/search.json')),
|
|
19
|
+
}, {
|
|
20
|
+
pending: () => {
|
|
21
|
+
status.value = 'pending'
|
|
22
|
+
error.value = undefined
|
|
23
|
+
},
|
|
24
|
+
success: (loadedNavigation, loadedFiles) => {
|
|
25
|
+
navigation.value = loadedNavigation
|
|
26
|
+
files.value = loadedFiles
|
|
27
|
+
status.value = 'success'
|
|
28
|
+
},
|
|
29
|
+
error: (cause) => {
|
|
30
|
+
error.value = cause
|
|
31
|
+
status.value = 'error'
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
navigation,
|
|
37
|
+
files,
|
|
38
|
+
status,
|
|
39
|
+
error,
|
|
40
|
+
load: loader.load,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { FooterColumn, FooterColumnLink, NavigationMenuItem } from '@nuxt/ui'
|
|
2
|
+
import { createSharedComposable } from '@vueuse/core'
|
|
3
|
+
|
|
4
|
+
function withActiveState<T extends { to?: unknown, children?: T[] }>(items: T[], currentPath: string): T[] {
|
|
5
|
+
return items.map((item) => {
|
|
6
|
+
const children = item.children ? withActiveState(item.children, currentPath) : undefined
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
...item,
|
|
10
|
+
...(children ? { children } : {}),
|
|
11
|
+
active: isNavigationTargetActive(currentPath, item.to)
|
|
12
|
+
|| Boolean(children?.some(child => 'active' in child && child.active)),
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function _useHeaderLinks() {
|
|
18
|
+
const appConfig = useAppConfig()
|
|
19
|
+
const route = useRoute()
|
|
20
|
+
const headerLinks = computed(() => withActiveState(
|
|
21
|
+
(appConfig.app.links.header ?? []) as NavigationMenuItem[],
|
|
22
|
+
route.path,
|
|
23
|
+
))
|
|
24
|
+
|
|
25
|
+
return { headerLinks }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _useFooterLinks() {
|
|
29
|
+
const appConfig = useAppConfig()
|
|
30
|
+
const route = useRoute()
|
|
31
|
+
const footerLinks = computed(() => ((appConfig.app.links.footer ?? []) as FooterColumn[]).map(column => ({
|
|
32
|
+
...column,
|
|
33
|
+
children: withActiveState((column.children ?? []) as FooterColumnLink[], route.path),
|
|
34
|
+
})))
|
|
35
|
+
|
|
36
|
+
return { footerLinks }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const useHeaderLinks = import.meta.client ? createSharedComposable(_useHeaderLinks) : _useHeaderLinks
|
|
40
|
+
export const useFooterLinks = import.meta.client ? createSharedComposable(_useFooterLinks) : _useFooterLinks
|
|
@@ -25,7 +25,5 @@ export function usePageContent<C extends keyof PageCollections = 'page', B = obj
|
|
|
25
25
|
|
|
26
26
|
const handler = () => queryCollection(resolvedCollection.value as keyof PageCollections).path(resolvedPath.value).first()
|
|
27
27
|
|
|
28
|
-
return useAsyncData(key, handler,
|
|
29
|
-
watch: [resolvedPath, resolvedCollection],
|
|
30
|
-
}) as unknown as AsyncData<(PageCollections[C] & B) | null, Error | null>
|
|
28
|
+
return useAsyncData(key, handler) as unknown as AsyncData<(PageCollections[C] & B) | null, Error | null>
|
|
31
29
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { watchEffect } from 'vue'
|
|
2
|
-
|
|
3
1
|
interface SeoRelevantPageData {
|
|
4
2
|
seo?: {
|
|
5
3
|
title?: string
|
|
@@ -12,19 +10,13 @@ interface SeoRelevantPageData {
|
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
export function usePageSeo(page: Ref<SeoRelevantPageData | null | undefined>) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const title = page.value.seo?.title || page.value.title
|
|
18
|
-
const description = page.value.seo?.description || page.value.description
|
|
19
|
-
const ogTitle = page.value.seo?.ogTitle || title
|
|
20
|
-
const ogDescription = page.value.seo?.ogDescription || description
|
|
13
|
+
const title = () => page.value?.seo?.title || page.value?.title
|
|
14
|
+
const description = () => page.value?.seo?.description || page.value?.description
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
28
|
-
}
|
|
16
|
+
useSeoMeta({
|
|
17
|
+
title,
|
|
18
|
+
ogTitle: () => page.value?.seo?.ogTitle || title(),
|
|
19
|
+
description,
|
|
20
|
+
ogDescription: () => page.value?.seo?.ogDescription || description(),
|
|
29
21
|
})
|
|
30
22
|
}
|
package/app/layouts/article.vue
CHANGED
|
@@ -1,120 +1,137 @@
|
|
|
1
|
-
<script setup lang="ts" generic="C extends keyof PageCollections = 'article'">
|
|
2
|
-
import type { PageCollections } from '@nuxt/content'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
1
|
+
<script setup lang="ts" generic="C extends keyof PageCollections = 'article'">
|
|
2
|
+
import type { PageCollections } from '@nuxt/content'
|
|
3
|
+
import type { BreadcrumbItem } from '@nuxt/ui'
|
|
4
|
+
import { getPageLayoutUi } from '../internal/pageLayout'
|
|
5
|
+
|
|
6
|
+
const props = defineProps<{
|
|
7
|
+
path?: string
|
|
8
|
+
collection?: C
|
|
9
|
+
}>()
|
|
10
|
+
|
|
11
|
+
const route = useRoute()
|
|
12
|
+
const collection = computed(() => props.collection ?? 'article')
|
|
13
|
+
|
|
14
|
+
const { data: page } = await usePageContent({
|
|
15
|
+
path: () => props.path,
|
|
16
|
+
collection: () => collection.value,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const { config, has } = useVariant(collection)
|
|
20
|
+
const hasHeader = has('header')
|
|
21
|
+
const hasBackButton = has('backButton')
|
|
22
|
+
const hasCopyButton = has('copyButton')
|
|
23
|
+
const hasSeparator = has('separator')
|
|
24
|
+
const hasSurround = has('surround')
|
|
25
|
+
const hasToc = has('toc')
|
|
26
|
+
const tocEnabled = computed(() => !page.value || !('toc' in page.value) || page.value.toc !== false)
|
|
27
|
+
const renderToc = computed(() => hasToc.value
|
|
28
|
+
&& tocEnabled.value
|
|
29
|
+
&& Boolean(page.value?.body?.toc?.links?.length))
|
|
30
|
+
const pageUi = computed(() => getPageLayoutUi(renderToc.value))
|
|
31
|
+
|
|
32
|
+
if (!page.value) {
|
|
33
|
+
throw createError({
|
|
34
|
+
statusCode: 404,
|
|
35
|
+
statusMessage: `${collection.value} ${props.path || route.path} not found`,
|
|
36
|
+
fatal: true,
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
usePageSeo(page)
|
|
41
|
+
|
|
42
|
+
const header = computed(() => resolvePageHeader(page.value))
|
|
43
|
+
|
|
44
|
+
const breadcrumbsBase = computed(() => (config.value.breadcrumbs ?? []) as BreadcrumbItem[])
|
|
45
|
+
|
|
46
|
+
const breadcrumbItems = computed(() => {
|
|
47
|
+
const baseItems = breadcrumbsBase.value.map((item, index) => ({
|
|
48
|
+
...item,
|
|
49
|
+
...(index === breadcrumbsBase.value.length - 1
|
|
50
|
+
? { ui: { ...item.ui, separator: 'hidden sm:flex' } }
|
|
51
|
+
: {}),
|
|
52
|
+
}))
|
|
53
|
+
|
|
54
|
+
return [
|
|
55
|
+
...baseItems,
|
|
56
|
+
{
|
|
57
|
+
label: page.value?.title,
|
|
58
|
+
to: page.value?.path,
|
|
59
|
+
ui: { item: 'hidden sm:flex' },
|
|
60
|
+
},
|
|
61
|
+
]
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const backLink = computed(() => {
|
|
65
|
+
const lastBreadcrumb = breadcrumbsBase.value.at(-1)
|
|
66
|
+
|
|
67
|
+
if (!lastBreadcrumb && !config.value?.backButton)
|
|
68
|
+
return null
|
|
69
|
+
|
|
70
|
+
return { ...(lastBreadcrumb ?? {}), ...config.value?.backButton }
|
|
71
|
+
})
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
<template>
|
|
75
|
+
<UContainer v-if="page">
|
|
76
|
+
<UPageHeader
|
|
77
|
+
v-if="hasHeader && header"
|
|
78
|
+
v-bind="header"
|
|
79
|
+
:ui="{
|
|
80
|
+
headline: 'all:flex flex-col gap-y-8 items-start',
|
|
81
|
+
wrapper: 'lg:flex-row',
|
|
82
|
+
}"
|
|
83
|
+
>
|
|
84
|
+
<template #headline>
|
|
85
|
+
<UBreadcrumb
|
|
86
|
+
:ui="{ root: 'max-w-full' }"
|
|
87
|
+
:items="breadcrumbItems"
|
|
88
|
+
/>
|
|
89
|
+
<HArticleHeadlineMeta :page="page" :collection="collection" />
|
|
90
|
+
</template>
|
|
91
|
+
<HArticleHeaderBody :page="page" :collection="collection">
|
|
92
|
+
<slot name="header" />
|
|
93
|
+
</HArticleHeaderBody>
|
|
94
|
+
</UPageHeader>
|
|
95
|
+
|
|
96
|
+
<UPage :ui="pageUi">
|
|
97
|
+
<UPageBody>
|
|
98
|
+
<slot />
|
|
99
|
+
|
|
100
|
+
<div
|
|
101
|
+
v-if="hasBackButton || hasCopyButton"
|
|
102
|
+
class="all:flex items-center justify-between mt-12"
|
|
103
|
+
>
|
|
104
|
+
<HBackButton
|
|
105
|
+
v-if="hasBackButton && backLink"
|
|
106
|
+
v-bind="backLink"
|
|
107
|
+
/>
|
|
108
|
+
<div class="all:flex justify-end items-center gap-1.5 ml-auto">
|
|
109
|
+
<HCopyButton v-if="hasCopyButton" v-bind="config.copyButton" />
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
<HSeparator
|
|
114
|
+
v-if="hasSeparator"
|
|
115
|
+
:stem="page?.stem"
|
|
116
|
+
:extension="page?.extension"
|
|
117
|
+
v-bind="config.separator"
|
|
118
|
+
/>
|
|
119
|
+
|
|
120
|
+
<HSurround
|
|
121
|
+
v-if="hasSurround"
|
|
122
|
+
:collection="collection"
|
|
123
|
+
v-bind="config.surround"
|
|
124
|
+
:query="config.query"
|
|
125
|
+
/>
|
|
126
|
+
</UPageBody>
|
|
127
|
+
|
|
128
|
+
<template #right>
|
|
129
|
+
<HToc
|
|
130
|
+
v-if="renderToc"
|
|
131
|
+
:links="page?.body?.toc?.links"
|
|
132
|
+
:title="page?.body?.toc?.title"
|
|
133
|
+
/>
|
|
134
|
+
</template>
|
|
135
|
+
</UPage>
|
|
136
|
+
</UContainer>
|
|
137
|
+
</template>
|