@happydesigns/ui 0.13.5
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 +94 -0
- package/app/app.config.ts +169 -0
- package/app/assets/css/main.css +14 -0
- package/app/components/article/ArticleGrid.vue +158 -0
- package/app/components/article/ArticleGridDate.vue +16 -0
- package/app/components/article/ArticleHeaderBody.vue +20 -0
- package/app/components/article/ArticleHeadlineMeta.vue +26 -0
- package/app/components/article/ArticleList.vue +95 -0
- package/app/components/article/ArticlePage.vue +16 -0
- package/app/components/content/Carousel.vue +11 -0
- package/app/components/content/Snippet.vue +31 -0
- package/app/components/footer/FooterButtons.vue +13 -0
- package/app/components/footer/FooterColumnHeading.vue +5 -0
- package/app/components/footer/FooterColumns.vue +105 -0
- package/app/components/footer/FooterCopyright.vue +29 -0
- package/app/components/traits/Authors.vue +20 -0
- package/app/components/traits/BackButton.vue +26 -0
- package/app/components/traits/Category.vue +9 -0
- package/app/components/traits/CopyButton.vue +39 -0
- package/app/components/traits/Dates.vue +20 -0
- package/app/components/traits/Links.vue +17 -0
- package/app/components/traits/Location.vue +20 -0
- package/app/components/traits/Separator.vue +26 -0
- package/app/components/traits/SeparatorButtons.vue +56 -0
- package/app/components/traits/Surround.vue +60 -0
- package/app/components/traits/Toc.vue +16 -0
- package/app/composables/useArticleList.ts +156 -0
- package/app/composables/useCategoryBadge.ts +27 -0
- package/app/composables/useClipboard.ts +26 -0
- package/app/composables/usePageContent.ts +31 -0
- package/app/composables/usePageSeo.ts +30 -0
- package/app/layouts/article.vue +128 -0
- package/app/layouts/content.vue +67 -0
- package/app/layouts/default.vue +12 -0
- package/app/types/config.ts +6 -0
- package/app/utils/formatDate.ts +26 -0
- package/app/utils/formatDateTime.ts +28 -0
- package/app/utils/resolvePageHeader.ts +16 -0
- package/app/utils/resolveUsers.ts +16 -0
- package/content.config.ts +6 -0
- package/nuxt.config.ts +80 -0
- package/package.json +60 -0
- package/schemas/collections.ts +46 -0
- package/schemas/index.ts +2 -0
- package/schemas/traits.ts +90 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T extends FooterColumnLink">
|
|
2
|
+
import type { FooterColumn, FooterColumnLink, FooterColumnsProps, FooterColumnsSlots } from '@nuxt/ui'
|
|
3
|
+
import { useAppConfig } from '#imports'
|
|
4
|
+
import { tv } from 'tailwind-variants'
|
|
5
|
+
|
|
6
|
+
interface HFooterColumnProps<T extends FooterColumnLink> extends /* @vue-ignore */ FooterColumnsProps<T> {
|
|
7
|
+
lgCols?: number
|
|
8
|
+
xlCols?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const props = defineProps<HFooterColumnProps<T>>()
|
|
12
|
+
const slots = defineSlots<FooterColumnsSlots<T>>()
|
|
13
|
+
const appConfig = useAppConfig()
|
|
14
|
+
|
|
15
|
+
const footerColumns: FooterColumn<T>[] = props.columns
|
|
16
|
+
?? (appConfig?.app?.links?.footer as FooterColumn<T>[] | undefined)
|
|
17
|
+
?? []
|
|
18
|
+
|
|
19
|
+
const leftCount = slots.left ? slots.left({}).length : 0
|
|
20
|
+
const centerCount = footerColumns?.length ?? 0
|
|
21
|
+
const rightCount = slots.right ? slots.right({}).length : 0
|
|
22
|
+
|
|
23
|
+
const lgCount = Math.max(leftCount, centerCount, rightCount)
|
|
24
|
+
const totalCount = leftCount + centerCount + rightCount
|
|
25
|
+
|
|
26
|
+
const ui = tv({
|
|
27
|
+
extend: tv({
|
|
28
|
+
extend: tv({ slots: {
|
|
29
|
+
root: 'footer-cols-root all:grid grid-flow-row gap-y-12 gap-x-8',
|
|
30
|
+
left: 'footer-cols-left',
|
|
31
|
+
center: 'footer-cols-center',
|
|
32
|
+
right: 'footer-cols-right',
|
|
33
|
+
} }),
|
|
34
|
+
slots: appConfig.ui?.footerColumns?.slots || {},
|
|
35
|
+
}),
|
|
36
|
+
slots: props.ui || {},
|
|
37
|
+
})()
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<template>
|
|
41
|
+
<UFooterColumns
|
|
42
|
+
v-bind="props" :columns="footerColumns" :ui="{
|
|
43
|
+
root: ui.root?.() ?? '',
|
|
44
|
+
left: ui.left?.() ?? '',
|
|
45
|
+
center: ui.center?.() ?? '',
|
|
46
|
+
right: ui.right?.() ?? '',
|
|
47
|
+
}"
|
|
48
|
+
:style="{
|
|
49
|
+
'--cols-sm': 1,
|
|
50
|
+
'--cols-lg': props.lgCols ?? lgCount,
|
|
51
|
+
'--cols-xl': props.xlCols ?? totalCount,
|
|
52
|
+
'--span-left': leftCount,
|
|
53
|
+
'--span-center': centerCount,
|
|
54
|
+
'--span-right': rightCount,
|
|
55
|
+
}"
|
|
56
|
+
>
|
|
57
|
+
<template v-if="leftCount > 0" #left>
|
|
58
|
+
<slot name="left" />
|
|
59
|
+
</template>
|
|
60
|
+
<template v-if="rightCount > 0" #right>
|
|
61
|
+
<slot name="right" />
|
|
62
|
+
</template>
|
|
63
|
+
</UFooterColumns>
|
|
64
|
+
</template>
|
|
65
|
+
|
|
66
|
+
<style>
|
|
67
|
+
@import "tailwindcss" source("../..");
|
|
68
|
+
|
|
69
|
+
.footer-cols-left {
|
|
70
|
+
grid-column: span var(--span-left);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.footer-cols-center {
|
|
74
|
+
grid-column: span var(--span-center);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.footer-cols-right {
|
|
78
|
+
grid-column: span var(--span-right);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.footer-cols-left,
|
|
82
|
+
.footer-cols-center,
|
|
83
|
+
.footer-cols-right {
|
|
84
|
+
display: contents;
|
|
85
|
+
}
|
|
86
|
+
.footer-cols-root {
|
|
87
|
+
grid-template-columns: repeat(var(--cols-sm), minmax(0, 1fr));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@media (min-width: theme(--breakpoint-lg)) {
|
|
91
|
+
.footer-cols-root {
|
|
92
|
+
grid-template-columns: repeat(var(--cols-lg), minmax(0, 1fr));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@media (min-width: theme(--breakpoint-xl)) {
|
|
97
|
+
.footer-cols-root {
|
|
98
|
+
grid-template-columns: repeat(var(--cols-xl), minmax(0, 1fr));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.footer-cols-root p:last-child {
|
|
103
|
+
margin-bottom: 0;
|
|
104
|
+
}
|
|
105
|
+
</style>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
const props = defineProps<{
|
|
3
|
+
copyrightYear?: number
|
|
4
|
+
copyrightHolder?: string
|
|
5
|
+
copyrightHomepage?: string
|
|
6
|
+
}>()
|
|
7
|
+
|
|
8
|
+
const appConfig = useAppConfig()
|
|
9
|
+
|
|
10
|
+
const copyrightYear = props.copyrightYear ?? new Date().getFullYear()
|
|
11
|
+
const copyrightHolder = props.copyrightHolder ?? appConfig.app?.meta?.copyright?.copyrightHolder ?? ''
|
|
12
|
+
const copyrightHomepage = props.copyrightHomepage ?? appConfig.app?.meta?.copyright?.copyrightHomepage ?? ''
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<div>
|
|
17
|
+
<template v-if="$slots.copyright">
|
|
18
|
+
<slot name="copyright" :copyright-year :copyright-homepage :copyright-holder />
|
|
19
|
+
</template>
|
|
20
|
+
<template v-else>
|
|
21
|
+
<p class="text-muted text-sm">
|
|
22
|
+
Copyright © {{ copyrightYear }}
|
|
23
|
+
<ULink :to="copyrightHomepage" target="_blank">
|
|
24
|
+
{{ copyrightHolder }}
|
|
25
|
+
</ULink>
|
|
26
|
+
</p>
|
|
27
|
+
</template>
|
|
28
|
+
</div>
|
|
29
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
const props = defineProps<{
|
|
3
|
+
authors?: string[]
|
|
4
|
+
target?: string
|
|
5
|
+
}>()
|
|
6
|
+
|
|
7
|
+
const { config } = useVariant('user')
|
|
8
|
+
|
|
9
|
+
const userProps = computed(() => ({ ...(config.value.user ?? {}), ...(props.target ? { target: props.target } : {}) }))
|
|
10
|
+
|
|
11
|
+
const resolvedAuthors = await resolveUsers(props.authors || [], userProps.value)
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<template>
|
|
15
|
+
<UUser
|
|
16
|
+
v-for="(author, index) in resolvedAuthors"
|
|
17
|
+
:key="index"
|
|
18
|
+
v-bind="author"
|
|
19
|
+
/>
|
|
20
|
+
</template>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { RouteLocationRaw } from 'vue-router'
|
|
3
|
+
|
|
4
|
+
const props = defineProps<{
|
|
5
|
+
to?: RouteLocationRaw
|
|
6
|
+
icon?: string
|
|
7
|
+
label?: string
|
|
8
|
+
}>()
|
|
9
|
+
|
|
10
|
+
const { config } = useVariant('backButton')
|
|
11
|
+
|
|
12
|
+
const resolvedIcon = computed(() => props.icon ?? config.value.backButton?.icon)
|
|
13
|
+
const resolvedLabel = computed(() => props.label ?? config.value.backButton?.label)
|
|
14
|
+
const resolvedTo = computed(() => props.to ?? config.value.backButton?.to)
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<UButton
|
|
19
|
+
color="primary"
|
|
20
|
+
variant="ghost"
|
|
21
|
+
:icon="resolvedIcon"
|
|
22
|
+
:to="resolvedTo"
|
|
23
|
+
>
|
|
24
|
+
{{ resolvedLabel }}
|
|
25
|
+
</UButton>
|
|
26
|
+
</template>
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
const { config } = useVariant('copyButton')
|
|
11
|
+
|
|
12
|
+
const resolvedIcon = computed(() => props.icon ?? config.value.copyButton?.icon)
|
|
13
|
+
const resolvedLabel = computed(() => props.label ?? config.value.copyButton?.label)
|
|
14
|
+
const resolvedSuccessIcon = computed(() => props.successIcon ?? config.value.copyButton?.successIcon)
|
|
15
|
+
const resolvedSuccessLabel = computed(() => props.successLabel ?? config.value.copyButton?.successLabel)
|
|
16
|
+
|
|
17
|
+
const { copy } = useClipboard()
|
|
18
|
+
const url = useRequestURL()
|
|
19
|
+
const route = useRoute()
|
|
20
|
+
|
|
21
|
+
function copyLink() {
|
|
22
|
+
copy(`${url.origin}${props.path ?? route.path}`, {
|
|
23
|
+
id: 'article-copy-link',
|
|
24
|
+
title: resolvedSuccessLabel.value,
|
|
25
|
+
icon: resolvedSuccessIcon.value,
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<UButton
|
|
32
|
+
:icon="resolvedIcon"
|
|
33
|
+
variant="ghost"
|
|
34
|
+
color="neutral"
|
|
35
|
+
@click="copyLink"
|
|
36
|
+
>
|
|
37
|
+
{{ resolvedLabel }}
|
|
38
|
+
</UButton>
|
|
39
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import formatDate from '~/utils/formatDate'
|
|
3
|
+
|
|
4
|
+
defineProps<{
|
|
5
|
+
date?: string
|
|
6
|
+
dateEnd?: string
|
|
7
|
+
}>()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<div class="all:flex items-center space-x-2">
|
|
12
|
+
<UIcon name="i-lucide-calendar" class="size-4" />
|
|
13
|
+
<time>
|
|
14
|
+
{{ formatDate(date) }}
|
|
15
|
+
<template v-if="dateEnd && date !== dateEnd">
|
|
16
|
+
- {{ formatDate(dateEnd) }}
|
|
17
|
+
</template>
|
|
18
|
+
</time>
|
|
19
|
+
</div>
|
|
20
|
+
</template>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { ButtonProps } from '@nuxt/ui'
|
|
3
|
+
|
|
4
|
+
defineProps<{
|
|
5
|
+
links?: ButtonProps[]
|
|
6
|
+
}>()
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<UButton
|
|
11
|
+
v-for="(link, index) in links"
|
|
12
|
+
:key="index"
|
|
13
|
+
variant="subtle"
|
|
14
|
+
size="sm"
|
|
15
|
+
v-bind="link"
|
|
16
|
+
/>
|
|
17
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps<{
|
|
3
|
+
location?: { url?: string, name?: string }
|
|
4
|
+
}>()
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<template>
|
|
8
|
+
<div class="all:flex items-center space-x-2">
|
|
9
|
+
<UIcon name="i-lucide-map-pin" class="size-4" />
|
|
10
|
+
<NuxtLink
|
|
11
|
+
v-if="location?.url"
|
|
12
|
+
:to="location.url"
|
|
13
|
+
target="_blank"
|
|
14
|
+
class="hover:text-primary transition-colors underline decoration-dotted underline-offset-4"
|
|
15
|
+
>
|
|
16
|
+
{{ location.name }}
|
|
17
|
+
</NuxtLink>
|
|
18
|
+
<span v-else>{{ location?.name }}</span>
|
|
19
|
+
</div>
|
|
20
|
+
</template>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { ActionButton } from '~/types/config'
|
|
3
|
+
|
|
4
|
+
const props = defineProps<{
|
|
5
|
+
stem?: string
|
|
6
|
+
extension?: string
|
|
7
|
+
buttons?: ActionButton[]
|
|
8
|
+
separator?: string
|
|
9
|
+
}>()
|
|
10
|
+
|
|
11
|
+
const { config } = useVariant('separator')
|
|
12
|
+
|
|
13
|
+
const resolvedButtons = computed(() => props.buttons ?? config.value.separator?.buttons ?? [])
|
|
14
|
+
const resolvedSeparator = computed(() => props.separator ?? config.value.separator?.separator)
|
|
15
|
+
|
|
16
|
+
const hasButtons = computed(() => resolvedButtons.value.length > 0)
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<USeparator v-if="!hasButtons" class="mt-8" />
|
|
21
|
+
<USeparator v-else class="mt-8">
|
|
22
|
+
<div class="all:flex items-center gap-2 text-sm text-muted">
|
|
23
|
+
<HSeparatorButtons :stem="stem" :extension="extension" :buttons="resolvedButtons" :separator="resolvedSeparator" />
|
|
24
|
+
</div>
|
|
25
|
+
</USeparator>
|
|
26
|
+
</template>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { ActionButton } from '~/types/config'
|
|
3
|
+
|
|
4
|
+
const props = defineProps<{
|
|
5
|
+
stem?: string
|
|
6
|
+
extension?: string
|
|
7
|
+
buttons?: ActionButton[]
|
|
8
|
+
separator?: string
|
|
9
|
+
}>()
|
|
10
|
+
|
|
11
|
+
const { config } = useVariant('separator')
|
|
12
|
+
|
|
13
|
+
const resolvedButtons = computed(() => props.buttons ?? config.value.separator?.buttons ?? [])
|
|
14
|
+
const resolvedSeparator = computed(() => props.separator ?? config.value.separator?.separator)
|
|
15
|
+
|
|
16
|
+
const appConfig = useAppConfig()
|
|
17
|
+
|
|
18
|
+
const editLink = computed(() => {
|
|
19
|
+
const { repo, branch, dir } = appConfig.app.meta.github || {}
|
|
20
|
+
if (!repo || !props.stem)
|
|
21
|
+
return null
|
|
22
|
+
|
|
23
|
+
const extension = props.extension || 'md'
|
|
24
|
+
return `https://github.com/${repo}/edit/${branch}/${dir}/${props.stem}.${extension}`
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const reportLink = computed(() => {
|
|
28
|
+
const repo = appConfig.app.meta.github?.repo
|
|
29
|
+
return repo ? `https://github.com/${repo}/issues/new` : null
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const buttons = computed(() =>
|
|
33
|
+
resolvedButtons.value.flatMap((btn) => {
|
|
34
|
+
let to = btn.to
|
|
35
|
+
if (btn.type === 'github-edit')
|
|
36
|
+
to = editLink.value ?? undefined
|
|
37
|
+
else if (btn.type === 'report-github-issue')
|
|
38
|
+
to = reportLink.value ?? undefined
|
|
39
|
+
return to ? [{ ...btn, to }] : []
|
|
40
|
+
}),
|
|
41
|
+
)
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<template>
|
|
45
|
+
<template v-for="(btn, index) in buttons" :key="index">
|
|
46
|
+
<template v-if="index > 0">
|
|
47
|
+
{{ resolvedSeparator }}
|
|
48
|
+
</template>
|
|
49
|
+
<UButton
|
|
50
|
+
variant="link"
|
|
51
|
+
color="neutral"
|
|
52
|
+
:ui="{ leadingIcon: 'size-4' }"
|
|
53
|
+
v-bind="btn"
|
|
54
|
+
/>
|
|
55
|
+
</template>
|
|
56
|
+
</template>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script setup lang="ts" generic="C extends keyof PageCollections = 'article'">
|
|
2
|
+
import type { PageCollections } from '@nuxt/content'
|
|
3
|
+
|
|
4
|
+
const props = withDefaults(defineProps<{
|
|
5
|
+
collection?: C
|
|
6
|
+
show?: boolean
|
|
7
|
+
prevIcon?: string
|
|
8
|
+
nextIcon?: string
|
|
9
|
+
fields?: string[]
|
|
10
|
+
where?: any[]
|
|
11
|
+
order?: { field: string, direction: 'ASC' | 'DESC' } | false
|
|
12
|
+
}>(), {
|
|
13
|
+
order: undefined,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const { config } = useVariant(() => props.collection || 'article')
|
|
17
|
+
const vc = computed(() => config.value as any)
|
|
18
|
+
|
|
19
|
+
const resolvedShow = computed(() => props.show ?? vc.value.surround?.show)
|
|
20
|
+
const resolvedPrevIcon = computed(() => props.prevIcon ?? vc.value.surround?.prevIcon)
|
|
21
|
+
const resolvedNextIcon = computed(() => props.nextIcon ?? vc.value.surround?.nextIcon)
|
|
22
|
+
|
|
23
|
+
const route = useRoute()
|
|
24
|
+
|
|
25
|
+
const { data: surround } = await useAsyncData(
|
|
26
|
+
`surround-${String(props.collection || 'article')}-${route.path}`,
|
|
27
|
+
() => {
|
|
28
|
+
const colName = (props.collection || 'article') as any
|
|
29
|
+
const qc = vc.value.query || {}
|
|
30
|
+
|
|
31
|
+
const fields = (props.fields || qc.fields || ['title', 'description', 'status']) as any
|
|
32
|
+
const order = props.order !== undefined ? props.order : qc.order
|
|
33
|
+
const where = props.where || qc.where || [{ field: 'status', operator: '=', value: 'published' }]
|
|
34
|
+
|
|
35
|
+
let query = queryCollectionItemSurroundings(colName, route.path, { fields })
|
|
36
|
+
|
|
37
|
+
if (where && Array.isArray(where)) {
|
|
38
|
+
where.forEach((filter) => {
|
|
39
|
+
query = query.where(filter.field as any, filter.operator, filter.value)
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (order) {
|
|
44
|
+
query = query.order(order.field as any, order.direction)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return query
|
|
48
|
+
},
|
|
49
|
+
)
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<template>
|
|
53
|
+
<div v-if="resolvedShow && surround?.length" class="mt-12">
|
|
54
|
+
<UContentSurround
|
|
55
|
+
:surround="surround"
|
|
56
|
+
:prev-icon="resolvedPrevIcon"
|
|
57
|
+
:next-icon="resolvedNextIcon"
|
|
58
|
+
/>
|
|
59
|
+
</div>
|
|
60
|
+
</template>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
const props = defineProps<{
|
|
3
|
+
links?: any[]
|
|
4
|
+
title?: string
|
|
5
|
+
}>()
|
|
6
|
+
|
|
7
|
+
const appConfig = useAppConfig()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<UContentToc
|
|
12
|
+
v-if="links?.length"
|
|
13
|
+
:links="links"
|
|
14
|
+
:title="title || appConfig.app.toc?.title"
|
|
15
|
+
/>
|
|
16
|
+
</template>
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { Collections, PageCollections, SQLOperator } from '@nuxt/content'
|
|
2
|
+
import type { BadgeProps } from '@nuxt/ui'
|
|
3
|
+
import type { MaybeRefOrGetter } from 'vue'
|
|
4
|
+
import { computed, toValue } from 'vue'
|
|
5
|
+
|
|
6
|
+
export interface ArticleFilter {
|
|
7
|
+
field: string
|
|
8
|
+
operator: SQLOperator
|
|
9
|
+
value?: any
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface UseArticleListOptions<C extends keyof PageCollections = 'article'> {
|
|
13
|
+
page?: MaybeRefOrGetter<number | undefined>
|
|
14
|
+
itemsPerPage?: MaybeRefOrGetter<number | undefined>
|
|
15
|
+
category?: MaybeRefOrGetter<string | undefined>
|
|
16
|
+
/** The label used for the 'All' category to avoid filtering by it */
|
|
17
|
+
labelAll?: MaybeRefOrGetter<string | undefined>
|
|
18
|
+
collection?: MaybeRefOrGetter<C | undefined>
|
|
19
|
+
/** Additional custom filters */
|
|
20
|
+
where?: MaybeRefOrGetter<ArticleFilter[] | undefined>
|
|
21
|
+
/** Field to sort by. Set to false to disable default sorting. Defaults to { field: 'date', direction: 'DESC' }. */
|
|
22
|
+
sort?: MaybeRefOrGetter<{ field: string, direction: 'ASC' | 'DESC' } | false | undefined>
|
|
23
|
+
/** Status to filter by. Set to false to disable default status filtering. Defaults to 'published'. */
|
|
24
|
+
status?: MaybeRefOrGetter<string | false | undefined>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Composable to fetch a paginated and filtered list of articles or any other collection.
|
|
29
|
+
* Includes automatic resolution of authors and category badges.
|
|
30
|
+
*/
|
|
31
|
+
export function useArticleList<C extends keyof PageCollections = 'article'>(options: UseArticleListOptions<C> = {}) {
|
|
32
|
+
const collection = computed(() => (toValue(options.collection) || ('article' as C)) as C)
|
|
33
|
+
|
|
34
|
+
const { config } = useVariant(collection)
|
|
35
|
+
|
|
36
|
+
const page = computed(() => toValue(options.page) || 1)
|
|
37
|
+
const itemsPerPage = computed(() => toValue(options.itemsPerPage) || config.value.list?.itemsPerPage || 12)
|
|
38
|
+
const category = computed(() => toValue(options.category))
|
|
39
|
+
const labelAll = computed(() => toValue(options.labelAll) || config.value.list?.labelAll || 'All')
|
|
40
|
+
|
|
41
|
+
const queryDefaults = computed(() => config.value.query || {})
|
|
42
|
+
|
|
43
|
+
const where = computed(() => {
|
|
44
|
+
const w = toValue(options.where)
|
|
45
|
+
if (w)
|
|
46
|
+
return w
|
|
47
|
+
|
|
48
|
+
// Fallback to config where but filter out status if handled separately
|
|
49
|
+
return queryDefaults.value.where?.filter(f => f.field !== 'status') || []
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const sort = computed(() => {
|
|
53
|
+
const s = toValue(options.sort)
|
|
54
|
+
if (s !== undefined)
|
|
55
|
+
return s
|
|
56
|
+
|
|
57
|
+
return queryDefaults.value.order
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const status = computed(() => {
|
|
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 = queryDefaults.value.where?.find(f => f.field === 'status')
|
|
70
|
+
return statusFilter?.value || 'published'
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
// 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)}-${status.value}`)
|
|
75
|
+
|
|
76
|
+
return useAsyncData(queryKey, async () => {
|
|
77
|
+
// We cast the query to a version that includes the standard article fields
|
|
78
|
+
// This avoids 'any' while still allowing the query to work with generic collections
|
|
79
|
+
type ArticleItem = Collections[C] & Collections['article']
|
|
80
|
+
type ArticleQueryBuilder = ReturnType<typeof queryCollection<'article'>>
|
|
81
|
+
|
|
82
|
+
const getDataQuery = () => {
|
|
83
|
+
let query = queryCollection(collection.value) as unknown as ArticleQueryBuilder
|
|
84
|
+
|
|
85
|
+
if (status.value) {
|
|
86
|
+
query = query.where('status', '=', status.value)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (category.value && category.value !== labelAll.value) {
|
|
90
|
+
query = query.where('category', '=', category.value)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Apply additional filters
|
|
94
|
+
if (where.value && Array.isArray(where.value)) {
|
|
95
|
+
where.value.forEach((filter) => {
|
|
96
|
+
query = query.where(filter.field as any, filter.operator, filter.value)
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
return query
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let finalQuery = getDataQuery()
|
|
103
|
+
|
|
104
|
+
if (sort.value) {
|
|
105
|
+
finalQuery = finalQuery.order(sort.value.field as any, sort.value.direction)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const articles = await finalQuery
|
|
109
|
+
.skip((page.value - 1) * itemsPerPage.value)
|
|
110
|
+
.limit(itemsPerPage.value)
|
|
111
|
+
.all() as ArticleItem[]
|
|
112
|
+
|
|
113
|
+
// Resolve details for each article
|
|
114
|
+
const resolved = await Promise.all(articles.map(async (article) => {
|
|
115
|
+
// Resolve Category Badge directly
|
|
116
|
+
const categoryKey = article.category
|
|
117
|
+
let resolvedBadge: BadgeProps | undefined
|
|
118
|
+
|
|
119
|
+
if (categoryKey) {
|
|
120
|
+
const categories = config.value.categories || {}
|
|
121
|
+
if (categoryKey in categories) {
|
|
122
|
+
resolvedBadge = categories[categoryKey] as BadgeProps
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
resolvedBadge = {
|
|
126
|
+
label: categoryKey,
|
|
127
|
+
color: 'primary',
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Resolve Authors
|
|
133
|
+
let resolvedAuthors: Awaited<ReturnType<typeof resolveUsers>> = []
|
|
134
|
+
if (article.authors?.length) {
|
|
135
|
+
const userProps = config.value.user ?? {}
|
|
136
|
+
resolvedAuthors = await resolveUsers(article.authors, userProps)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
...article,
|
|
141
|
+
resolvedBadge,
|
|
142
|
+
resolvedAuthors,
|
|
143
|
+
}
|
|
144
|
+
}))
|
|
145
|
+
|
|
146
|
+
// Total count for pagination
|
|
147
|
+
const total = await getDataQuery().count() as number
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
articles: resolved,
|
|
151
|
+
total,
|
|
152
|
+
}
|
|
153
|
+
}, {
|
|
154
|
+
keepPreviousData: true,
|
|
155
|
+
})
|
|
156
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a category badge reactively using the global application configuration.
|
|
3
|
+
*
|
|
4
|
+
* @param category - The reactive category string to resolve.
|
|
5
|
+
* @param collection - The collection to resolve categories for. Defaults to 'article'.
|
|
6
|
+
* @returns A computed property containing the resolved badge configuration.
|
|
7
|
+
*/
|
|
8
|
+
export function useCategoryBadge(
|
|
9
|
+
category: MaybeRefOrGetter<string | undefined | null>,
|
|
10
|
+
collection: MaybeRefOrGetter<string> = 'article',
|
|
11
|
+
) {
|
|
12
|
+
const { config } = useVariant(collection)
|
|
13
|
+
|
|
14
|
+
return computed(() => {
|
|
15
|
+
const categoryKey = toValue(category)
|
|
16
|
+
const categories = config.value.categories
|
|
17
|
+
|
|
18
|
+
if (categoryKey && categories && categoryKey in categories) {
|
|
19
|
+
return categories[categoryKey]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
label: categoryKey ?? '',
|
|
24
|
+
color: 'primary',
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ToastProps } from '#ui/types'
|
|
2
|
+
import { useClipboard as _useClipboard } from '@vueuse/core'
|
|
3
|
+
|
|
4
|
+
export function useClipboard() {
|
|
5
|
+
const { copy: _copy, copied } = _useClipboard()
|
|
6
|
+
|
|
7
|
+
const toast = useToast()
|
|
8
|
+
|
|
9
|
+
const copy = (source: string, options?: Partial<ToastProps> & { id?: string | number }) => {
|
|
10
|
+
_copy(source)
|
|
11
|
+
if (options) {
|
|
12
|
+
// Check if toast with this ID already exists to prevent spam
|
|
13
|
+
if (options.id && toast.toasts.value.some(t => t.id === options.id)) {
|
|
14
|
+
toast.update(options.id, options)
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
toast.add(options as any)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
copy,
|
|
24
|
+
copied,
|
|
25
|
+
}
|
|
26
|
+
}
|