@happydesigns/ui 0.19.3 → 0.20.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 +17 -0
- package/{app → content/app}/components/ContentPage.vue +54 -54
- package/{app → content/app}/components/Snippet.vue +1 -1
- package/{app → content/app}/components/article/ArticleGrid.vue +1 -1
- package/{app → content/app}/components/article/ArticleGridDate.vue +19 -19
- package/{app → content/app}/components/article/ArticleHeaderBody.vue +1 -1
- package/{app → content/app}/components/article/ArticleHeadlineMeta.vue +1 -1
- package/{app → content/app}/components/article/ArticleList.vue +1 -1
- package/{app → content/app}/components/article/ArticlePage.vue +1 -1
- package/{app → content/app}/components/search/ContentSearch.client.vue +59 -59
- package/{app → content/app}/components/studio/StudioLoginButton.client.vue +78 -78
- package/{app → content/app}/components/traits/Surround.vue +2 -2
- package/{app → content/app}/composables/useArticleList.ts +1 -1
- package/{app → content/app}/composables/useContentSearchData.ts +42 -42
- package/{app → content/app}/composables/usePageContent.ts +1 -1
- package/{app → content/app}/layouts/article.vue +20 -20
- package/{app → content/app}/layouts/content.vue +21 -21
- package/{app → content/app}/utils/resolveUsers.ts +1 -1
- package/content/nuxt.config.ts +7 -0
- package/{server → content/server}/api/navigation.json.get.ts +11 -11
- package/{server → content/server}/api/search.json.get.ts +11 -11
- package/{server → content/server}/utils/contentSearch.ts +2 -2
- package/nuxt.config.ts +25 -28
- package/package.json +4 -2
- /package/{app → content/app}/components/traits/Authors.vue +0 -0
- /package/{app → content/app}/composables/useArticleListQuery.ts +0 -0
package/README.md
CHANGED
|
@@ -41,6 +41,23 @@ pnpm exec nuxt prepare
|
|
|
41
41
|
|
|
42
42
|
## Content collections
|
|
43
43
|
|
|
44
|
+
Applications using Nuxt Content extend `@happydesigns/ui/content` instead of
|
|
45
|
+
`@happydesigns/ui`. This optional layer includes article/content layouts,
|
|
46
|
+
`HContentPage`, `HSnippet`, content search, author lookup, navigation endpoints,
|
|
47
|
+
and Nuxt Studio (disabled unless configured by the application).
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
export default defineNuxtConfig({
|
|
51
|
+
extends: ['@happydesigns/ui/content'],
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Migration from 0.19.x:** change the layer entry point above if your application
|
|
56
|
+
uses these features. The base entry point now registers only Nuxt UI and variants;
|
|
57
|
+
Comark applications can keep it without initializing Nuxt Content or Studio.
|
|
58
|
+
The dependencies remain installed for the optional layer, but are not activated
|
|
59
|
+
by the base layer.
|
|
60
|
+
|
|
44
61
|
The layer exports reusable schema profiles, but it does not register collection names, sources, or route prefixes for an application. Define those locally in the consumer's `content.config.ts`:
|
|
45
62
|
|
|
46
63
|
```ts
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
<script setup lang="ts" generic="C extends PageCollectionName = 'page'">
|
|
2
|
-
import type { PageCollectionItemBase } from '@nuxt/content'
|
|
3
|
-
import type { PageCollectionName } from '
|
|
4
|
-
|
|
5
|
-
defineOptions({ inheritAttrs: false })
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
collection = 'page' as C,
|
|
9
|
-
path,
|
|
10
|
-
page: suppliedPage,
|
|
11
|
-
} = defineProps<{
|
|
12
|
-
/** Consumer-owned page collection. */
|
|
13
|
-
collection?: C
|
|
14
|
-
/** Route path override. The current route path is used by default. */
|
|
15
|
-
path?: string
|
|
16
|
-
/** Already resolved document, useful when a route needs project-specific side effects. */
|
|
17
|
-
page?: PageCollectionItemBase | null
|
|
18
|
-
}>()
|
|
19
|
-
|
|
20
|
-
const fetched = suppliedPage === undefined
|
|
21
|
-
? await usePageContent<C>({
|
|
22
|
-
collection: () => collection,
|
|
23
|
-
path: () => path,
|
|
24
|
-
})
|
|
25
|
-
: undefined
|
|
26
|
-
|
|
27
|
-
const page = computed(() => suppliedPage === undefined ? fetched?.data.value : suppliedPage)
|
|
28
|
-
|
|
29
|
-
if (!page.value) {
|
|
30
|
-
throw createError({
|
|
31
|
-
statusCode: 404,
|
|
32
|
-
statusMessage: `${collection} ${path || useRoute().path} not found`,
|
|
33
|
-
fatal: true,
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
</script>
|
|
37
|
-
|
|
38
|
-
<template>
|
|
39
|
-
<NuxtLayout
|
|
40
|
-
v-if="page"
|
|
41
|
-
name="content"
|
|
42
|
-
:collection="collection"
|
|
43
|
-
:path="path"
|
|
44
|
-
:page="page"
|
|
45
|
-
>
|
|
46
|
-
<slot :page="page">
|
|
47
|
-
<ContentRenderer
|
|
48
|
-
:value="page"
|
|
49
|
-
class="h-content"
|
|
50
|
-
v-bind="$attrs"
|
|
51
|
-
/>
|
|
52
|
-
</slot>
|
|
53
|
-
</NuxtLayout>
|
|
54
|
-
</template>
|
|
1
|
+
<script setup lang="ts" generic="C extends PageCollectionName = 'page'">
|
|
2
|
+
import type { PageCollectionItemBase } from '@nuxt/content'
|
|
3
|
+
import type { PageCollectionName } from '../../../app/types/content'
|
|
4
|
+
|
|
5
|
+
defineOptions({ inheritAttrs: false })
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
collection = 'page' as C,
|
|
9
|
+
path,
|
|
10
|
+
page: suppliedPage,
|
|
11
|
+
} = defineProps<{
|
|
12
|
+
/** Consumer-owned page collection. */
|
|
13
|
+
collection?: C
|
|
14
|
+
/** Route path override. The current route path is used by default. */
|
|
15
|
+
path?: string
|
|
16
|
+
/** Already resolved document, useful when a route needs project-specific side effects. */
|
|
17
|
+
page?: PageCollectionItemBase | null
|
|
18
|
+
}>()
|
|
19
|
+
|
|
20
|
+
const fetched = suppliedPage === undefined
|
|
21
|
+
? await usePageContent<C>({
|
|
22
|
+
collection: () => collection,
|
|
23
|
+
path: () => path,
|
|
24
|
+
})
|
|
25
|
+
: undefined
|
|
26
|
+
|
|
27
|
+
const page = computed(() => suppliedPage === undefined ? fetched?.data.value : suppliedPage)
|
|
28
|
+
|
|
29
|
+
if (!page.value) {
|
|
30
|
+
throw createError({
|
|
31
|
+
statusCode: 404,
|
|
32
|
+
statusMessage: `${collection} ${path || useRoute().path} not found`,
|
|
33
|
+
fatal: true,
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<template>
|
|
39
|
+
<NuxtLayout
|
|
40
|
+
v-if="page"
|
|
41
|
+
name="content"
|
|
42
|
+
:collection="collection"
|
|
43
|
+
:path="path"
|
|
44
|
+
:page="page"
|
|
45
|
+
>
|
|
46
|
+
<slot :page="page">
|
|
47
|
+
<ContentRenderer
|
|
48
|
+
:value="page"
|
|
49
|
+
class="h-content"
|
|
50
|
+
v-bind="$attrs"
|
|
51
|
+
/>
|
|
52
|
+
</slot>
|
|
53
|
+
</NuxtLayout>
|
|
54
|
+
</template>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { PageCollections } from '@nuxt/content'
|
|
3
3
|
import type { Component } from 'vue'
|
|
4
|
-
import type { PageCollectionName } from '
|
|
4
|
+
import type { PageCollectionName } from '../../../app/types/content'
|
|
5
5
|
|
|
6
6
|
const props = withDefaults(defineProps<{
|
|
7
7
|
path: string
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts" generic="C extends PageCollectionName = 'article'">
|
|
2
|
+
import type { PageCollectionName } from '../../../../app/types/content'
|
|
2
3
|
import type { ArticleFilter } from '../../composables/useArticleList'
|
|
3
|
-
import type { PageCollectionName } from '../../types/content'
|
|
4
4
|
|
|
5
5
|
const props = withDefaults(defineProps<{
|
|
6
6
|
/** Optional fixed category to filter by */
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import formatDate from '
|
|
3
|
-
|
|
4
|
-
defineProps<{
|
|
5
|
-
article: {
|
|
6
|
-
date?: string
|
|
7
|
-
dateEnd?: string
|
|
8
|
-
}
|
|
9
|
-
}>()
|
|
10
|
-
</script>
|
|
11
|
-
|
|
12
|
-
<template>
|
|
13
|
-
<time v-if="article.date" class="text-xs text-muted">
|
|
14
|
-
{{ formatDate(article.date) }}
|
|
15
|
-
<template v-if="article.dateEnd && article.date !== article.dateEnd">
|
|
16
|
-
- {{ formatDate(article.dateEnd) }}
|
|
17
|
-
</template>
|
|
18
|
-
</time>
|
|
19
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import formatDate from '../../../../app/utils/formatDate'
|
|
3
|
+
|
|
4
|
+
defineProps<{
|
|
5
|
+
article: {
|
|
6
|
+
date?: string
|
|
7
|
+
dateEnd?: string
|
|
8
|
+
}
|
|
9
|
+
}>()
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<time v-if="article.date" class="text-xs text-muted">
|
|
14
|
+
{{ formatDate(article.date) }}
|
|
15
|
+
<template v-if="article.dateEnd && article.date !== article.dateEnd">
|
|
16
|
+
- {{ formatDate(article.dateEnd) }}
|
|
17
|
+
</template>
|
|
18
|
+
</time>
|
|
19
|
+
</template>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts" generic="C extends PageCollectionName = 'article'">
|
|
2
|
+
import type { PageCollectionName } from '../../../../app/types/content'
|
|
2
3
|
import type { ArticleFilter } from '../../composables/useArticleList'
|
|
3
|
-
import type { PageCollectionName } from '../../types/content'
|
|
4
4
|
import { useArticleListQuery } from '../../composables/useArticleListQuery'
|
|
5
5
|
|
|
6
6
|
const props = withDefaults(defineProps<{
|
|
@@ -1,59 +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>
|
|
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>
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import type { StudioUser } from 'nuxt-studio/app'
|
|
3
|
-
|
|
4
|
-
withDefaults(defineProps<{
|
|
5
|
-
/** Accessible label for the icon-only button. */
|
|
6
|
-
ariaLabel?: string
|
|
7
|
-
/** Icon rendered by the underlying UButton. */
|
|
8
|
-
icon?: string
|
|
9
|
-
/** Optional visible button label. */
|
|
10
|
-
label?: string
|
|
11
|
-
}>(), {
|
|
12
|
-
ariaLabel: 'Open Nuxt Studio',
|
|
13
|
-
icon: 'i-lucide-log-in',
|
|
14
|
-
})
|
|
15
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { StudioUser } from 'nuxt-studio/app'
|
|
3
|
+
|
|
4
|
+
withDefaults(defineProps<{
|
|
5
|
+
/** Accessible label for the icon-only button. */
|
|
6
|
+
ariaLabel?: string
|
|
7
|
+
/** Icon rendered by the underlying UButton. */
|
|
8
|
+
icon?: string
|
|
9
|
+
/** Optional visible button label. */
|
|
10
|
+
label?: string
|
|
11
|
+
}>(), {
|
|
12
|
+
ariaLabel: 'Open Nuxt Studio',
|
|
13
|
+
icon: 'i-lucide-log-in',
|
|
14
|
+
})
|
|
15
|
+
|
|
16
16
|
interface StudioSession {
|
|
17
17
|
user?: StudioUser | null
|
|
18
18
|
}
|
|
@@ -20,69 +20,69 @@ interface StudioSession {
|
|
|
20
20
|
interface StudioRuntimeConfig {
|
|
21
21
|
dev?: boolean
|
|
22
22
|
route?: string
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const runtimeConfig = useRuntimeConfig()
|
|
26
|
-
const sessionCheckCookie = useCookie<string | null>('studio-session-check')
|
|
27
|
-
const sessionUser = ref<StudioUser | null | undefined>()
|
|
28
|
-
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const runtimeConfig = useRuntimeConfig()
|
|
26
|
+
const sessionCheckCookie = useCookie<string | null>('studio-session-check')
|
|
27
|
+
const sessionUser = ref<StudioUser | null | undefined>()
|
|
28
|
+
|
|
29
29
|
const studio = computed<StudioRuntimeConfig>(() => {
|
|
30
30
|
const config = runtimeConfig.public.studio
|
|
31
31
|
return config && typeof config === 'object' ? config as StudioRuntimeConfig : {}
|
|
32
|
-
})
|
|
33
|
-
const studioRoute = computed(() => studio.value.route || '/_studio')
|
|
34
|
-
|
|
35
|
-
onMounted(async () => {
|
|
36
|
-
if (studio.value.dev) {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (String(sessionCheckCookie.value) !== 'true') {
|
|
41
|
-
sessionUser.value = null
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
const session = await $fetch('/__nuxt_studio/auth/session') as StudioSession
|
|
47
|
-
sessionUser.value = session.user ?? null
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
sessionUser.value = null
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!sessionUser.value?.email) {
|
|
54
|
-
sessionCheckCookie.value = null
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
const isLoggedIn = computed(() => {
|
|
59
|
-
if (studio.value.dev) {
|
|
60
|
-
return true
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (String(sessionCheckCookie.value) !== 'true') {
|
|
64
|
-
return false
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (sessionUser.value === undefined) {
|
|
68
|
-
return true
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return Boolean(sessionUser.value?.email)
|
|
72
|
-
})
|
|
73
|
-
</script>
|
|
74
|
-
|
|
75
|
-
<template>
|
|
76
|
-
<UButton
|
|
77
|
-
v-if="!isLoggedIn"
|
|
78
|
-
:to="studioRoute"
|
|
79
|
-
external
|
|
80
|
-
:aria-label="ariaLabel"
|
|
81
|
-
:icon="icon"
|
|
82
|
-
:label="label"
|
|
83
|
-
color="neutral"
|
|
84
|
-
variant="outline"
|
|
85
|
-
size="sm"
|
|
86
|
-
class="fixed bottom-2 left-2 z-50 print:hidden"
|
|
87
|
-
/>
|
|
88
|
-
</template>
|
|
32
|
+
})
|
|
33
|
+
const studioRoute = computed(() => studio.value.route || '/_studio')
|
|
34
|
+
|
|
35
|
+
onMounted(async () => {
|
|
36
|
+
if (studio.value.dev) {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (String(sessionCheckCookie.value) !== 'true') {
|
|
41
|
+
sessionUser.value = null
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const session = await $fetch('/__nuxt_studio/auth/session') as StudioSession
|
|
47
|
+
sessionUser.value = session.user ?? null
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
sessionUser.value = null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!sessionUser.value?.email) {
|
|
54
|
+
sessionCheckCookie.value = null
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const isLoggedIn = computed(() => {
|
|
59
|
+
if (studio.value.dev) {
|
|
60
|
+
return true
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (String(sessionCheckCookie.value) !== 'true') {
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (sessionUser.value === undefined) {
|
|
68
|
+
return true
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return Boolean(sessionUser.value?.email)
|
|
72
|
+
})
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<template>
|
|
76
|
+
<UButton
|
|
77
|
+
v-if="!isLoggedIn"
|
|
78
|
+
:to="studioRoute"
|
|
79
|
+
external
|
|
80
|
+
:aria-label="ariaLabel"
|
|
81
|
+
:icon="icon"
|
|
82
|
+
:label="label"
|
|
83
|
+
color="neutral"
|
|
84
|
+
variant="outline"
|
|
85
|
+
size="sm"
|
|
86
|
+
class="fixed bottom-2 left-2 z-50 print:hidden"
|
|
87
|
+
/>
|
|
88
|
+
</template>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts" generic="C extends PageCollectionName">
|
|
2
2
|
import type { PageCollections } from '@nuxt/content'
|
|
3
|
-
import type { QueryConfig } from '
|
|
4
|
-
import type { PageCollectionName } from '
|
|
3
|
+
import type { QueryConfig } from '../../../../app/types/config'
|
|
4
|
+
import type { PageCollectionName } from '../../../../app/types/content'
|
|
5
5
|
|
|
6
6
|
type PageField = Extract<keyof PageCollections[keyof PageCollections], string>
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CollectionQueryBuilder, Collections, PageCollectionItemBase, PageCollections, SQLOperator } from '@nuxt/content'
|
|
2
2
|
import type { BadgeProps } from '@nuxt/ui'
|
|
3
3
|
import type { MaybeRefOrGetter } from 'vue'
|
|
4
|
-
import type { PageCollectionName } from '
|
|
4
|
+
import type { PageCollectionName } from '../../../app/types/content'
|
|
5
5
|
import { computed, toValue } from 'vue'
|
|
6
6
|
|
|
7
7
|
export interface ArticleFilter {
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import type { ContentNavigationItem } from '@nuxt/content'
|
|
2
|
-
import type { ContentSearchFile } from '@nuxt/ui'
|
|
3
|
-
import { createContentSearchLoader } from '
|
|
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
|
-
}
|
|
1
|
+
import type { ContentNavigationItem } from '@nuxt/content'
|
|
2
|
+
import type { ContentSearchFile } from '@nuxt/ui'
|
|
3
|
+
import { createContentSearchLoader } from '../../../app/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
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PageCollectionItemBase, PageCollections } from '@nuxt/content'
|
|
2
2
|
import type { AsyncData } from 'nuxt/app'
|
|
3
3
|
import type { MaybeRefOrGetter } from 'vue'
|
|
4
|
-
import type { PageCollectionName } from '
|
|
4
|
+
import type { PageCollectionName } from '../../../app/types/content'
|
|
5
5
|
import { computed, toValue } from 'vue'
|
|
6
6
|
|
|
7
7
|
type PageForCollection<C extends PageCollectionName> = PageCollectionItemBase
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
<script setup lang="ts" generic="C extends PageCollectionName = 'article'">
|
|
2
2
|
import type { BreadcrumbItem } from '@nuxt/ui'
|
|
3
|
-
import type { PageCollectionName } from '
|
|
3
|
+
import type { PageCollectionName } from '../../../app/types/content'
|
|
4
4
|
|
|
5
|
-
const props = defineProps<{
|
|
6
|
-
path?: string
|
|
7
|
-
collection?: C
|
|
8
|
-
}>()
|
|
9
|
-
|
|
10
|
-
const route = useRoute()
|
|
11
|
-
const collection = computed(() => props.collection ?? 'article')
|
|
12
|
-
const surroundCollection = computed<PageCollectionName>(() => collection.value)
|
|
5
|
+
const props = defineProps<{
|
|
6
|
+
path?: string
|
|
7
|
+
collection?: C
|
|
8
|
+
}>()
|
|
9
|
+
|
|
10
|
+
const route = useRoute()
|
|
11
|
+
const collection = computed(() => props.collection ?? 'article')
|
|
12
|
+
const surroundCollection = computed<PageCollectionName>(() => collection.value)
|
|
13
13
|
|
|
14
14
|
const { data: page } = await usePageContent({
|
|
15
15
|
path: () => props.path,
|
|
@@ -40,10 +40,10 @@ const header = computed(() => resolvePageHeader(page.value))
|
|
|
40
40
|
|
|
41
41
|
const breadcrumbsBase = computed(() => (config.value.breadcrumbs ?? []) as BreadcrumbItem[])
|
|
42
42
|
|
|
43
|
-
const currentBreadcrumb = computed<BreadcrumbItem>(() => ({
|
|
44
|
-
label: page.value?.title,
|
|
45
|
-
to: page.value?.path,
|
|
46
|
-
}))
|
|
43
|
+
const currentBreadcrumb = computed<BreadcrumbItem>(() => ({
|
|
44
|
+
label: page.value?.title,
|
|
45
|
+
to: page.value?.path,
|
|
46
|
+
}))
|
|
47
47
|
|
|
48
48
|
const backLink = computed(() => {
|
|
49
49
|
const lastBreadcrumb = breadcrumbsBase.value.at(-1)
|
|
@@ -66,10 +66,10 @@ const backLink = computed(() => {
|
|
|
66
66
|
}"
|
|
67
67
|
>
|
|
68
68
|
<template #headline>
|
|
69
|
-
<HBreadcrumbs
|
|
70
|
-
:items="breadcrumbsBase"
|
|
71
|
-
:current="currentBreadcrumb"
|
|
72
|
-
/>
|
|
69
|
+
<HBreadcrumbs
|
|
70
|
+
:items="breadcrumbsBase"
|
|
71
|
+
:current="currentBreadcrumb"
|
|
72
|
+
/>
|
|
73
73
|
<HArticleHeadlineMeta :page="page" :collection="collection" />
|
|
74
74
|
</template>
|
|
75
75
|
<HArticleHeaderBody :page="page" :collection="collection">
|
|
@@ -101,9 +101,9 @@ const backLink = computed(() => {
|
|
|
101
101
|
v-bind="config.separator"
|
|
102
102
|
/>
|
|
103
103
|
|
|
104
|
-
<HSurround
|
|
105
|
-
v-if="hasSurround"
|
|
106
|
-
:collection="surroundCollection"
|
|
104
|
+
<HSurround
|
|
105
|
+
v-if="hasSurround"
|
|
106
|
+
:collection="surroundCollection"
|
|
107
107
|
v-bind="config.surround"
|
|
108
108
|
:query="config.query"
|
|
109
109
|
/>
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
<script setup lang="ts" generic="C extends PageCollectionName = 'page'">
|
|
2
|
-
import type { PageCollectionItemBase } from '@nuxt/content'
|
|
3
|
-
import type { PageCollectionName } from '
|
|
1
|
+
<script setup lang="ts" generic="C extends PageCollectionName = 'page'">
|
|
2
|
+
import type { PageCollectionItemBase } from '@nuxt/content'
|
|
3
|
+
import type { PageCollectionName } from '../../../app/types/content'
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
path,
|
|
7
|
-
collection = 'page' as C,
|
|
8
|
-
page: suppliedPage,
|
|
9
|
-
} = defineProps<{
|
|
10
|
-
path?: string
|
|
11
|
-
collection?: C
|
|
12
|
-
page?: PageCollectionItemBase | null
|
|
13
|
-
}>()
|
|
5
|
+
const {
|
|
6
|
+
path,
|
|
7
|
+
collection = 'page' as C,
|
|
8
|
+
page: suppliedPage,
|
|
9
|
+
} = defineProps<{
|
|
10
|
+
path?: string
|
|
11
|
+
collection?: C
|
|
12
|
+
page?: PageCollectionItemBase | null
|
|
13
|
+
}>()
|
|
14
14
|
|
|
15
15
|
const appConfig = useAppConfig()
|
|
16
16
|
const route = useRoute()
|
|
17
17
|
|
|
18
|
-
const fetched = suppliedPage === undefined
|
|
19
|
-
? await usePageContent<C>({
|
|
20
|
-
path: () => path,
|
|
21
|
-
collection: () => collection,
|
|
22
|
-
})
|
|
23
|
-
: undefined
|
|
24
|
-
const page = computed(() => suppliedPage === undefined ? fetched?.data.value : suppliedPage)
|
|
18
|
+
const fetched = suppliedPage === undefined
|
|
19
|
+
? await usePageContent<C>({
|
|
20
|
+
path: () => path,
|
|
21
|
+
collection: () => collection,
|
|
22
|
+
})
|
|
23
|
+
: undefined
|
|
24
|
+
const page = computed(() => suppliedPage === undefined ? fetched?.data.value : suppliedPage)
|
|
25
25
|
|
|
26
26
|
const variant = computed(() => {
|
|
27
27
|
if (typeof route.meta.variant === 'string' && route.meta.variant) {
|
|
@@ -32,7 +32,7 @@ const variant = computed(() => {
|
|
|
32
32
|
return route.meta.layout
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
return collection as string
|
|
35
|
+
return collection as string
|
|
36
36
|
})
|
|
37
37
|
const { has } = useVariant(variant)
|
|
38
38
|
const hasHeader = has('header')
|
|
@@ -41,7 +41,7 @@ const hasToc = has('toc')
|
|
|
41
41
|
if (!page.value) {
|
|
42
42
|
throw createError({
|
|
43
43
|
statusCode: 404,
|
|
44
|
-
statusMessage: `${collection} ${path || route.path} not found`,
|
|
44
|
+
statusMessage: `${collection} ${path || route.path} not found`,
|
|
45
45
|
fatal: true,
|
|
46
46
|
})
|
|
47
47
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CollectionItemBase, CollectionQueryBuilder, Collections } from '@nuxt/content'
|
|
2
2
|
import type { UserProps } from '@nuxt/ui'
|
|
3
|
-
import type { CollectionName } from '
|
|
3
|
+
import type { CollectionName } from '../../../app/types/content'
|
|
4
4
|
|
|
5
5
|
interface UserRecord extends CollectionItemBase {
|
|
6
6
|
username: string
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { queryCollectionNavigation } from '@nuxt/content/server'
|
|
2
|
-
|
|
3
|
-
export default defineEventHandler(async (event) => {
|
|
4
|
-
setSearchCacheHeaders(event)
|
|
5
|
-
const entries = await Promise.all(getSearchCollections().map((config) => {
|
|
6
|
-
const query = queryCollectionNavigation(event, asPageCollection(config.name))
|
|
7
|
-
return applySearchCollectionConfig(query, config)
|
|
8
|
-
}))
|
|
9
|
-
|
|
10
|
-
return entries.flat()
|
|
11
|
-
})
|
|
1
|
+
import { queryCollectionNavigation } from '@nuxt/content/server'
|
|
2
|
+
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
setSearchCacheHeaders(event)
|
|
5
|
+
const entries = await Promise.all(getSearchCollections().map((config) => {
|
|
6
|
+
const query = queryCollectionNavigation(event, asPageCollection(config.name))
|
|
7
|
+
return applySearchCollectionConfig(query, config)
|
|
8
|
+
}))
|
|
9
|
+
|
|
10
|
+
return entries.flat()
|
|
11
|
+
})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { queryCollectionSearchSections } from '@nuxt/content/server'
|
|
2
|
-
|
|
3
|
-
export default defineEventHandler(async (event) => {
|
|
4
|
-
setSearchCacheHeaders(event)
|
|
5
|
-
const entries = await Promise.all(getSearchCollections().map((config) => {
|
|
6
|
-
const query = queryCollectionSearchSections(event, asPageCollection(config.name))
|
|
7
|
-
return applySearchCollectionConfig(query, config)
|
|
8
|
-
}))
|
|
9
|
-
|
|
10
|
-
return entries.flat()
|
|
11
|
-
})
|
|
1
|
+
import { queryCollectionSearchSections } from '@nuxt/content/server'
|
|
2
|
+
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
setSearchCacheHeaders(event)
|
|
5
|
+
const entries = await Promise.all(getSearchCollections().map((config) => {
|
|
6
|
+
const query = queryCollectionSearchSections(event, asPageCollection(config.name))
|
|
7
|
+
return applySearchCollectionConfig(query, config)
|
|
8
|
+
}))
|
|
9
|
+
|
|
10
|
+
return entries.flat()
|
|
11
|
+
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PageCollections, SQLOperator } from '@nuxt/content'
|
|
2
2
|
import type { H3Event } from 'h3'
|
|
3
|
-
import type { SearchCollectionConfig, SearchConfig } from '
|
|
4
|
-
import type { PageCollectionName } from '
|
|
3
|
+
import type { SearchCollectionConfig, SearchConfig } from '../../../app/types/config'
|
|
4
|
+
import type { PageCollectionName } from '../../../app/types/content'
|
|
5
5
|
|
|
6
6
|
interface ConfigurableSearchQuery {
|
|
7
7
|
where: (field: string, operator: SQLOperator, value?: unknown) => unknown
|
package/nuxt.config.ts
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
import { variantRegistry } from './schemas/variants'
|
|
2
|
-
|
|
3
|
-
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
4
|
-
export default defineNuxtConfig({
|
|
5
|
-
|
|
6
|
-
$meta: {
|
|
7
|
-
name: '@happydesigns/ui',
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
components: [
|
|
11
|
-
{ path: './components', pathPrefix: false, prefix: 'H' },
|
|
12
|
-
],
|
|
13
|
-
|
|
14
|
-
devtools: { enabled: true },
|
|
15
|
-
|
|
16
|
-
modules: [
|
|
17
|
-
'@happydesigns/nuxt-variants',
|
|
18
|
-
'@nuxt/ui',
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
studio: false,
|
|
28
|
-
})
|
|
1
|
+
import { variantRegistry } from './schemas/variants'
|
|
2
|
+
|
|
3
|
+
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
4
|
+
export default defineNuxtConfig({
|
|
5
|
+
|
|
6
|
+
$meta: {
|
|
7
|
+
name: '@happydesigns/ui',
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
components: [
|
|
11
|
+
{ path: './components', pathPrefix: false, prefix: 'H' },
|
|
12
|
+
],
|
|
13
|
+
|
|
14
|
+
devtools: { enabled: true },
|
|
15
|
+
|
|
16
|
+
modules: [
|
|
17
|
+
'@happydesigns/nuxt-variants',
|
|
18
|
+
'@nuxt/ui',
|
|
19
|
+
],
|
|
20
|
+
|
|
21
|
+
variants: {
|
|
22
|
+
registry: variantRegistry,
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
})
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happydesigns/ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.20.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"packageManager": "pnpm@11.11.0",
|
|
7
7
|
"description": "A reusable Nuxt foundation for content-driven happydesigns websites and applications.",
|
|
@@ -27,11 +27,13 @@
|
|
|
27
27
|
".": "./nuxt.config.ts",
|
|
28
28
|
"./schemas": "./schemas/index.ts",
|
|
29
29
|
"./styles.css": "./app/assets/css/styles.css",
|
|
30
|
-
"./types": "./app/types/config.ts"
|
|
30
|
+
"./types": "./app/types/config.ts",
|
|
31
|
+
"./content": "./content/nuxt.config.ts"
|
|
31
32
|
},
|
|
32
33
|
"main": "./nuxt.config.ts",
|
|
33
34
|
"files": [
|
|
34
35
|
"app",
|
|
36
|
+
"content",
|
|
35
37
|
"nuxt.config.ts",
|
|
36
38
|
"schemas",
|
|
37
39
|
"server",
|
|
File without changes
|
|
File without changes
|