@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.
Files changed (46) hide show
  1. package/README.md +64 -53
  2. package/app/app.config.ts +138 -165
  3. package/app/app.vue +0 -2
  4. package/app/assets/css/styles.css +38 -0
  5. package/app/components/Carousel.vue +33 -0
  6. package/app/components/{content/Snippet.vue → Snippet.vue} +6 -2
  7. package/app/components/article/ArticleGrid.vue +4 -4
  8. package/app/components/article/ArticleGridDate.vue +19 -16
  9. package/app/components/article/ArticleHeaderBody.vue +26 -20
  10. package/app/components/article/ArticleHeadlineMeta.vue +37 -26
  11. package/app/components/article/ArticleList.vue +5 -5
  12. package/app/components/article/ArticlePage.vue +1 -1
  13. package/app/components/footer/FooterColumns.vue +60 -101
  14. package/app/components/search/ContentSearch.client.vue +59 -0
  15. package/app/components/studio/StudioLoginButton.client.vue +11 -3
  16. package/app/components/traits/Category.vue +1 -1
  17. package/app/components/traits/CopyButton.vue +40 -32
  18. package/app/components/traits/Links.vue +21 -17
  19. package/app/components/traits/Surround.vue +6 -7
  20. package/app/components/traits/Toc.vue +18 -16
  21. package/app/composables/useArticleList.ts +37 -46
  22. package/app/composables/useClipboard.ts +48 -26
  23. package/app/composables/useContentSearchData.ts +42 -0
  24. package/app/composables/useNavigationLinks.ts +40 -0
  25. package/app/composables/usePageContent.ts +1 -3
  26. package/app/composables/usePageSeo.ts +7 -15
  27. package/app/internal/pageLayout.ts +7 -0
  28. package/app/layouts/article.vue +137 -120
  29. package/app/layouts/content.vue +63 -59
  30. package/app/types/config.ts +91 -13
  31. package/app/utils/createContentSearchLoader.ts +45 -0
  32. package/app/utils/formatDate.ts +1 -1
  33. package/app/utils/formatDateTime.ts +1 -1
  34. package/app/utils/isNavigationTargetActive.ts +12 -0
  35. package/app/utils/resolveUsers.ts +56 -42
  36. package/nuxt.config.ts +4 -16
  37. package/package.json +17 -9
  38. package/schemas/collections.ts +4 -0
  39. package/schemas/indexes.ts +10 -0
  40. package/schemas/traits.ts +9 -4
  41. package/server/api/navigation.json.get.ts +11 -0
  42. package/server/api/search.json.get.ts +11 -0
  43. package/server/utils/contentSearch.ts +67 -0
  44. package/shared/types/app-config.d.ts +23 -0
  45. package/app/assets/css/main.css +0 -14
  46. package/app/components/content/Carousel.vue +0 -11
@@ -1,59 +1,63 @@
1
- <script setup lang="ts" generic="C extends 'page' = 'page'">
2
- import type { Collections } from '@nuxt/content'
3
-
4
- const {
5
- path,
6
- collection = 'page' as C,
7
- } = defineProps<{
8
- path?: string
9
- collection?: C
10
- }>()
11
-
12
- const appConfig = useAppConfig()
13
- const route = useRoute()
14
-
15
- const { data: page } = await usePageContent<C, Collections['page']>({
16
- path: () => path,
17
- collection: () => collection,
18
- })
19
-
20
- const { has } = useVariant(collection)
21
- const hasHeader = has('header')
22
- const hasToc = has('toc')
23
-
24
- if (!page.value) {
25
- throw createError({
26
- statusCode: 404,
27
- statusMessage: `${collection} ${path || route.path} not found`,
28
- fatal: true,
29
- })
30
- }
31
-
32
- usePageSeo(page)
33
-
34
- const renderToc = computed(() => hasToc.value && page.value?.toc !== false)
35
- const header = computed(() => resolvePageHeader(page.value))
36
- </script>
37
-
38
- <template>
39
- <UContainer v-if="page">
40
- <UPage>
41
- <UPageHeader
42
- v-if="hasHeader && header"
43
- v-bind="header"
44
- />
45
-
46
- <UPageBody>
47
- <slot />
48
- </UPageBody>
49
-
50
- <template #right>
51
- <UContentToc
52
- v-if="renderToc && page.body?.toc?.links?.length"
53
- :links="page.body.toc.links"
54
- :title="page.body.toc.title || appConfig.app.toc?.title"
55
- />
56
- </template>
57
- </UPage>
58
- </UContainer>
59
- </template>
1
+ <script setup lang="ts" generic="C extends 'page' = 'page'">
2
+ import type { Collections } from '@nuxt/content'
3
+ import { getPageLayoutUi } from '../internal/pageLayout'
4
+
5
+ const {
6
+ path,
7
+ collection = 'page' as C,
8
+ } = defineProps<{
9
+ path?: string
10
+ collection?: C
11
+ }>()
12
+
13
+ const appConfig = useAppConfig()
14
+ const route = useRoute()
15
+
16
+ const { data: page } = await usePageContent<C, Collections['page']>({
17
+ path: () => path,
18
+ collection: () => collection,
19
+ })
20
+
21
+ const { has } = useVariant(collection)
22
+ const hasHeader = has('header')
23
+ const hasToc = has('toc')
24
+
25
+ if (!page.value) {
26
+ throw createError({
27
+ statusCode: 404,
28
+ statusMessage: `${collection} ${path || route.path} not found`,
29
+ fatal: true,
30
+ })
31
+ }
32
+
33
+ usePageSeo(page)
34
+
35
+ const renderToc = computed(() => hasToc.value
36
+ && page.value?.toc !== false
37
+ && Boolean(page.value?.body?.toc?.links?.length))
38
+ const pageUi = computed(() => getPageLayoutUi(renderToc.value))
39
+ const header = computed(() => resolvePageHeader(page.value))
40
+ </script>
41
+
42
+ <template>
43
+ <UContainer v-if="page">
44
+ <UPageHeader
45
+ v-if="hasHeader && header"
46
+ v-bind="header"
47
+ />
48
+
49
+ <UPage :ui="pageUi">
50
+ <UPageBody>
51
+ <slot />
52
+ </UPageBody>
53
+
54
+ <template #right>
55
+ <UContentToc
56
+ v-if="renderToc"
57
+ :links="page.body?.toc?.links"
58
+ :title="page.body?.toc?.title || appConfig.app.toc?.title"
59
+ />
60
+ </template>
61
+ </UPage>
62
+ </UContainer>
63
+ </template>
@@ -1,13 +1,91 @@
1
- import type { SQLOperator } from '@nuxt/content'
2
- import type { ButtonProps } from '@nuxt/ui'
3
-
4
- export type ActionButton = ButtonProps & {
5
- /** Built-in type for a dynamic GitHub link (URL resolved from app.meta.github) */
6
- action?: 'github-edit' | 'report-github-issue'
7
- }
8
-
9
- export interface QueryConfig {
10
- fields?: string[]
11
- where?: { field: string, operator: SQLOperator, value?: unknown }[]
12
- order?: { field: string, direction: 'ASC' | 'DESC' } | false
13
- }
1
+ import type { PageCollections, SQLOperator } from '@nuxt/content'
2
+ import type { ButtonProps, CommandPaletteGroup, ContentSearchLink, FooterColumn, NavigationMenuItem } from '@nuxt/ui'
3
+
4
+ export type ActionButton = ButtonProps & {
5
+ /** Built-in type for a dynamic GitHub link (URL resolved from app.meta.github) */
6
+ action?: 'github-edit' | 'report-github-issue'
7
+ }
8
+
9
+ export interface QueryConfig {
10
+ fields?: string[]
11
+ where?: { field: string, operator: SQLOperator, value?: unknown }[]
12
+ order?: { field: string, direction: 'ASC' | 'DESC' } | false
13
+ }
14
+ export interface SearchCollectionConfig {
15
+ /** Page collection included in both generated search indexes. */
16
+ name: keyof PageCollections & string
17
+ /** Filters applied before navigation and search sections are generated. */
18
+ where?: QueryConfig['where']
19
+ /** Optional stable ordering for generated entries. */
20
+ order?: QueryConfig['order']
21
+ }
22
+
23
+ export interface SearchConfig {
24
+ title?: string
25
+ description?: string
26
+ placeholder?: string
27
+ resultLimit?: number
28
+ links?: ContentSearchLink[]
29
+ groups?: CommandPaletteGroup[]
30
+ /** Shared-cache policy for dynamic search endpoints. Set to false to disable caching. */
31
+ cache?: false | {
32
+ /** CDN/proxy cache lifetime in seconds. Browser responses always revalidate. */
33
+ sharedMaxAge?: number
34
+ /** Time in seconds a shared cache may serve stale data while refreshing. */
35
+ staleWhileRevalidate?: number
36
+ }
37
+ error?: {
38
+ title?: string
39
+ description?: string
40
+ retryLabel?: string
41
+ }
42
+ /** Opt-in page collections exposed by the generated public search indexes. */
43
+ collections?: SearchCollectionConfig[]
44
+ }
45
+ /**
46
+ * Consumer-owned app config fields can be added through declaration merging.
47
+ *
48
+ * @example
49
+ * declare module '@happydesigns/ui/types' {
50
+ * interface HAppConfigExtensions {
51
+ * contact?: { email?: string }
52
+ * }
53
+ * }
54
+ */
55
+ export interface HAppConfigExtensions {}
56
+
57
+ export interface HAppConfigInput extends HAppConfigExtensions {
58
+ meta?: {
59
+ copyright?: {
60
+ copyrightYear?: number
61
+ copyrightHolder?: string
62
+ copyrightHomepage?: string
63
+ }
64
+ socials?: ButtonProps[]
65
+ github?: {
66
+ repo?: string
67
+ branch?: string
68
+ dir?: string
69
+ }
70
+ }
71
+ links?: {
72
+ header?: NavigationMenuItem[]
73
+ footer?: FooterColumn[]
74
+ }
75
+ search?: SearchConfig
76
+ toc?: { title?: string }
77
+ icons?: Record<string, string>
78
+ date?: {
79
+ locale?: string
80
+ options?: Intl.DateTimeFormatOptions
81
+ datetimeOptions?: Intl.DateTimeFormatOptions
82
+ }
83
+ }
84
+ export interface HAppConfig extends HAppConfigInput {
85
+ meta: NonNullable<HAppConfigInput['meta']>
86
+ links: NonNullable<HAppConfigInput['links']>
87
+ search: SearchConfig
88
+ toc: NonNullable<HAppConfigInput['toc']>
89
+ icons: Record<string, string>
90
+ date: NonNullable<HAppConfigInput['date']>
91
+ }
@@ -0,0 +1,45 @@
1
+ export interface ContentSearchLoaders<TNavigation, TFiles> {
2
+ navigation: () => Promise<TNavigation>
3
+ files: () => Promise<TFiles>
4
+ }
5
+
6
+ export interface ContentSearchLoaderCallbacks<TNavigation, TFiles> {
7
+ success: (navigation: TNavigation, files: TFiles) => void
8
+ error: (error: Error) => void
9
+ pending?: () => void
10
+ }
11
+
12
+ export function createContentSearchLoader<TNavigation, TFiles>(
13
+ loaders: ContentSearchLoaders<TNavigation, TFiles>,
14
+ callbacks: ContentSearchLoaderCallbacks<TNavigation, TFiles>,
15
+ ) {
16
+ let loaded = false
17
+ let pendingRequest: Promise<void> | undefined
18
+
19
+ async function load() {
20
+ if (loaded) {
21
+ return
22
+ }
23
+
24
+ if (pendingRequest) {
25
+ return pendingRequest
26
+ }
27
+
28
+ callbacks.pending?.()
29
+ pendingRequest = Promise.all([loaders.navigation(), loaders.files()])
30
+ .then(([navigation, files]) => {
31
+ loaded = true
32
+ callbacks.success(navigation, files)
33
+ })
34
+ .catch((cause: unknown) => {
35
+ callbacks.error(cause instanceof Error ? cause : new Error(String(cause)))
36
+ })
37
+ .finally(() => {
38
+ pendingRequest = undefined
39
+ })
40
+
41
+ return pendingRequest
42
+ }
43
+
44
+ return { load }
45
+ }
@@ -16,7 +16,7 @@ export default function formatDate(date?: string | number | Date): string {
16
16
 
17
17
  const appConfig = useAppConfig()
18
18
  const locale = appConfig.app.date?.locale || 'en'
19
- const options = appConfig.app.date?.options || {
19
+ const options: Intl.DateTimeFormatOptions = appConfig.app.date?.options as Intl.DateTimeFormatOptions || {
20
20
  year: 'numeric',
21
21
  month: 'short',
22
22
  day: 'numeric',
@@ -16,7 +16,7 @@ export default function formatDateTime(date?: string | number | Date): string {
16
16
 
17
17
  const appConfig = useAppConfig()
18
18
  const locale = appConfig.app.date?.locale || 'en'
19
- const options = appConfig.app.date?.datetimeOptions || {
19
+ const options: Intl.DateTimeFormatOptions = appConfig.app.date?.datetimeOptions as Intl.DateTimeFormatOptions || {
20
20
  year: 'numeric',
21
21
  month: 'short',
22
22
  day: 'numeric',
@@ -0,0 +1,12 @@
1
+ export function isNavigationTargetActive(currentPath: string, target?: unknown): boolean {
2
+ if (typeof target !== 'string' || !target.startsWith('/') || target.startsWith('//')) {
3
+ return false
4
+ }
5
+
6
+ const targetPath = target.split(/[?#]/, 1)[0] || '/'
7
+ const normalizedCurrent = currentPath === '/' ? '/' : currentPath.replace(/\/+$/, '')
8
+ const normalizedTarget = targetPath === '/' ? '/' : targetPath.replace(/\/+$/, '')
9
+
10
+ return normalizedCurrent === normalizedTarget
11
+ || (normalizedTarget !== '/' && normalizedCurrent.startsWith(normalizedTarget.concat('/')))
12
+ }
@@ -1,45 +1,59 @@
1
- import type { UserProps } from '@nuxt/ui'
2
-
3
- interface UserRecord {
4
- username: string
5
- name?: UserProps['name']
6
- description?: UserProps['description']
7
- to?: UserProps['to']
8
- avatar?: UserProps['avatar']
9
- }
10
-
11
- interface UserQuery {
12
- where: (field: 'username', operator: 'IN', value: string[]) => UserQuery
13
- select: (...fields: Array<keyof UserRecord>) => UserQuery
14
- all: () => Promise<UserRecord[]>
15
- }
16
-
17
- /**
18
- * Removes the internal collection lookup key before passing a profile to Nuxt UI.
19
- */
20
- export function toUserProps<T extends { username: string }>(
21
- user: T,
22
- extraProps: Partial<UserProps> = {},
23
- ) {
24
- const { username: _lookupKey, ...profile } = user
25
-
26
- return { ...profile, ...extraProps }
1
+ import type { UserProps } from '@nuxt/ui'
2
+
3
+ interface UserRecord {
4
+ username: string
5
+ name?: UserProps['name']
6
+ description?: UserProps['description']
7
+ to?: UserProps['to']
8
+ avatar?: UserProps['avatar']
27
9
  }
28
10
 
29
- /**
30
- * Fetches user details from the Nuxt Content user collection.
31
- *
32
- * @param users - A single username or an array of usernames
33
- * @returns A promise resolving to the selected user profiles
34
- */
35
- export default async function resolveUsers(users: string | string[], extraProps: Partial<UserProps> = {}) {
36
- const userList = Array.isArray(users) ? users : [users]
11
+ export type ResolvedUser = Omit<UserRecord, 'username'> & Partial<UserProps>
12
+
13
+ /**
14
+ * Removes the internal collection lookup key before passing a profile to Nuxt UI.
15
+ */
16
+ export function toUserProps<T extends { username: string }>(
17
+ user: T,
18
+ extraProps: Partial<UserProps> = {},
19
+ ): Omit<T, 'username'> & Partial<UserProps> {
20
+ const { username: _lookupKey, ...profile } = user
21
+
22
+ return { ...profile, ...extraProps }
23
+ }
24
+
25
+ /**
26
+ * Fetches user details once and keeps the lookup key available for callers
27
+ * that need to associate a profile with several content entries.
28
+ */
29
+ export async function resolveUserMap(users: string[], extraProps: Partial<UserProps> = {}) {
30
+ const uniqueUsers = [...new Set(users)]
31
+
32
+ if (uniqueUsers.length === 0)
33
+ return new Map<string, ResolvedUser>()
37
34
 
38
- const queryUserCollection = queryCollection as unknown as (collection: 'user') => UserQuery
39
- const resolved = await queryUserCollection('user')
40
- .where('username', 'IN', userList)
41
- .select('username', 'name', 'description', 'to', 'avatar')
42
- .all()
43
-
44
- return resolved.map(user => toUserProps(user, extraProps))
45
- }
35
+ const resolved = await queryCollection('user')
36
+ .where('username', 'IN', uniqueUsers)
37
+ .select('username', 'name', 'description', 'to', 'avatar')
38
+ .all()
39
+
40
+ return new Map(resolved.map(user => [user.username, toUserProps(user, extraProps)]))
41
+ }
42
+
43
+ /**
44
+ * Fetches user details from the Nuxt Content user collection.
45
+ *
46
+ * The returned profiles follow the requested username order. Unknown users are omitted.
47
+ *
48
+ * @param users - A single username or an array of usernames
49
+ * @returns A promise resolving to the selected user profiles
50
+ */
51
+ export default async function resolveUsers(users: string | string[], extraProps: Partial<UserProps> = {}) {
52
+ const userList = Array.isArray(users) ? users : [users]
53
+ const resolved = await resolveUserMap(userList, extraProps)
54
+
55
+ return userList.flatMap((username) => {
56
+ const user = resolved.get(username)
57
+ return user ? [user] : []
58
+ })
59
+ }
package/nuxt.config.ts CHANGED
@@ -1,9 +1,3 @@
1
- import { dirname } from 'node:path'
2
- import { fileURLToPath } from 'node:url'
3
- import { resolve } from 'pathe'
4
-
5
- const currentDir: string = dirname(fileURLToPath(import.meta.url))
6
-
7
1
  // https://nuxt.com/docs/api/configuration/nuxt-config
8
2
  export default defineNuxtConfig({
9
3
 
@@ -15,10 +9,6 @@ export default defineNuxtConfig({
15
9
  { path: './components', pathPrefix: false, prefix: 'H' },
16
10
  ],
17
11
 
18
- css: [
19
- resolve(currentDir, './app/assets/css/main.css'),
20
- ],
21
-
22
12
  devtools: { enabled: true },
23
13
 
24
14
  modules: [
@@ -34,7 +24,7 @@ export default defineNuxtConfig({
34
24
  dates: {},
35
25
  authors: {},
36
26
  category: {},
37
- status: {},
27
+ published: {},
38
28
  header: {},
39
29
  toc: {},
40
30
  links: {},
@@ -52,11 +42,11 @@ export default defineNuxtConfig({
52
42
  // Collection variants — extends chains defined here for graph generation
53
43
  snippet: {},
54
44
  article: {
55
- extends: ['dates', 'authors', 'category', 'status', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton', 'user'],
45
+ extends: ['dates', 'authors', 'category', 'published', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton'],
56
46
  config: {},
57
47
  },
58
48
  event: {
59
- extends: ['dates', 'location', 'category', 'links', 'status', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton', 'user'],
49
+ extends: ['dates', 'location', 'category', 'links', 'published', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton'],
60
50
  config: {},
61
51
  },
62
52
  page: {
@@ -66,7 +56,5 @@ export default defineNuxtConfig({
66
56
  },
67
57
  },
68
58
 
69
- studio: {
70
- dev: true,
71
- },
59
+ studio: false,
72
60
  })
package/package.json CHANGED
@@ -1,21 +1,25 @@
1
1
  {
2
2
  "name": "@happydesigns/ui",
3
3
  "type": "module",
4
- "version": "0.15.1",
4
+ "version": "0.17.0",
5
5
  "private": false,
6
6
  "packageManager": "pnpm@11.11.0",
7
7
  "author": "happydesigns",
8
8
  "homepage": "https://github.com/happydesigns",
9
9
  "exports": {
10
10
  ".": "./nuxt.config.ts",
11
- "./schemas": "./schemas/index.ts"
11
+ "./schemas": "./schemas/index.ts",
12
+ "./styles.css": "./app/assets/css/styles.css",
13
+ "./types": "./app/types/config.ts"
12
14
  },
13
15
  "main": "./nuxt.config.ts",
14
16
  "files": [
15
17
  "app",
16
18
  "content.config.ts",
17
19
  "nuxt.config.ts",
18
- "schemas"
20
+ "schemas",
21
+ "server",
22
+ "shared"
19
23
  ],
20
24
  "publishConfig": {
21
25
  "access": "public"
@@ -27,6 +31,9 @@
27
31
  "docs:build:server": "nuxt build docs",
28
32
  "prepare": "nuxt prepare && nuxt prepare playground",
29
33
  "build": "nuxt build playground",
34
+ "generate": "nuxt generate playground && node scripts/validate-playground-output.mjs",
35
+ "package:check": "node scripts/validate-package.mjs",
36
+ "consumer:check": "node scripts/validate-consumer.mjs",
30
37
  "preview": "nuxt preview playground",
31
38
  "lint": "eslint .",
32
39
  "lint:fix": "eslint . --fix",
@@ -38,17 +45,19 @@
38
45
  "release:alpha": "changelogen --release --versionSuffix alpha.0",
39
46
  "release:beta": "changelogen --release --versionSuffix beta.0"
40
47
  },
48
+ "peerDependencies": {
49
+ "tailwindcss": "^4.3.2"
50
+ },
41
51
  "dependencies": {
42
52
  "@happydesigns/nuxt-variants": "^0.0.6",
43
53
  "@iconify-json/heroicons": "^1.2.3",
44
54
  "@iconify-json/lucide": "^1.2.116",
45
55
  "@iconify-json/simple-icons": "^1.2.89",
46
56
  "@nuxt/content": "^3.15.0",
47
- "@nuxt/ui": "^4.9.0",
57
+ "@nuxt/ui": "^4.10.0",
48
58
  "@vueuse/core": "^14.3.0",
49
59
  "better-sqlite3": "^12.11.1",
50
60
  "nuxt-studio": "^1.7.0",
51
- "pathe": "^2.0.3",
52
61
  "zod": "^4.4.3"
53
62
  },
54
63
  "devDependencies": {
@@ -59,13 +68,12 @@
59
68
  "cross-env": "^10.1.0",
60
69
  "docus": "5.12.3",
61
70
  "eslint": "^10.6.0",
62
- "nuxt": "^4.4.8",
71
+ "nuxt": "4.5.1",
63
72
  "typescript": "^6.0.3",
64
73
  "vitest": "^4.1.10",
65
- "vue-tsc": "^3.3.7",
66
- "zod-to-json-schema": "^3.25.2"
74
+ "vue-tsc": "^3.3.7"
67
75
  },
68
76
  "resolutions": {
69
77
  "@happydesigns/ui": "workspace:*"
70
78
  }
71
- }
79
+ }
@@ -1,5 +1,6 @@
1
1
  import { mergeVariantSchemas } from '@happydesigns/nuxt-variants/schemas'
2
2
  import { defineCollection } from '@nuxt/content'
3
+ import { articleCollectionIndexes, userCollectionIndexes } from './indexes'
3
4
  import { variantSchemas } from './traits'
4
5
 
5
6
  export const collections = {
@@ -18,6 +19,7 @@ export const collections = {
18
19
  prefix: '/articles',
19
20
  },
20
21
  schema: mergeVariantSchemas(['article'], variantSchemas),
22
+ indexes: articleCollectionIndexes,
21
23
  }),
22
24
 
23
25
  event: defineCollection({
@@ -27,6 +29,7 @@ export const collections = {
27
29
  prefix: '/events',
28
30
  },
29
31
  schema: mergeVariantSchemas(['event'], variantSchemas),
32
+ indexes: articleCollectionIndexes,
30
33
  }),
31
34
 
32
35
  page: defineCollection({
@@ -42,5 +45,6 @@ export const collections = {
42
45
  type: 'data',
43
46
  source: 'users/**/*.{md,yaml}',
44
47
  schema: mergeVariantSchemas(['user'], variantSchemas),
48
+ indexes: userCollectionIndexes,
45
49
  }),
46
50
  }
@@ -0,0 +1,10 @@
1
+ import type { CollectionIndex } from '@nuxt/content'
2
+
3
+ export const articleCollectionIndexes = [
4
+ { columns: ['published', 'date'] },
5
+ { columns: ['published', 'category', 'date'] },
6
+ ] satisfies CollectionIndex[]
7
+
8
+ export const userCollectionIndexes = [
9
+ { columns: ['username'], unique: true },
10
+ ] satisfies CollectionIndex[]
package/schemas/traits.ts CHANGED
@@ -20,9 +20,9 @@ export const categoryTrait = {
20
20
  }),
21
21
  }
22
22
 
23
- export const statusTrait = {
23
+ export const publishedTrait = {
24
24
  schema: z.object({
25
- status: z.enum(['published', 'draft', 'archived']).default('published'),
25
+ published: z.boolean().default(true),
26
26
  }),
27
27
  }
28
28
 
@@ -67,7 +67,12 @@ export const userTrait = {
67
67
  name: z.string().optional(),
68
68
  description: z.string().optional(),
69
69
  to: z.string().optional(),
70
- avatar: property(z.object({})).inherit('@nuxt/ui/components/Avatar.vue').optional(),
70
+ avatar: z.object({
71
+ src: property(z.string()).editor({ input: 'media' }).optional(),
72
+ alt: z.string().optional(),
73
+ icon: property(z.string()).editor({ input: 'icon' }).optional(),
74
+ text: z.string().optional(),
75
+ }).optional(),
71
76
  socials: z.array(z.object({
72
77
  name: z.string(),
73
78
  url: z.url(),
@@ -80,7 +85,7 @@ export const variantSchemas = {
80
85
  dates: datesTrait.schema,
81
86
  authors: authorsTrait.schema,
82
87
  category: categoryTrait.schema,
83
- status: statusTrait.schema,
88
+ published: publishedTrait.schema,
84
89
  header: headerTrait.schema,
85
90
  toc: tocTrait.schema,
86
91
  links: linksTrait.schema,
@@ -0,0 +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
+ })
@@ -0,0 +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
+ })