@happydesigns/ui 0.16.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -53
- package/app/app.config.ts +138 -165
- package/app/app.vue +0 -2
- package/app/assets/css/styles.css +38 -0
- package/app/components/Carousel.vue +33 -0
- package/app/components/{content/Snippet.vue → Snippet.vue} +6 -2
- package/app/components/article/ArticleGridDate.vue +19 -16
- package/app/components/article/ArticleHeaderBody.vue +26 -20
- package/app/components/article/ArticleHeadlineMeta.vue +37 -26
- package/app/components/article/ArticleList.vue +1 -1
- package/app/components/article/ArticlePage.vue +1 -1
- package/app/components/footer/FooterColumns.vue +60 -101
- package/app/components/search/ContentSearch.client.vue +59 -0
- package/app/components/studio/StudioLoginButton.client.vue +11 -3
- package/app/components/traits/Category.vue +1 -1
- package/app/components/traits/CopyButton.vue +40 -32
- package/app/components/traits/Links.vue +21 -17
- package/app/components/traits/Surround.vue +5 -6
- package/app/components/traits/Toc.vue +18 -16
- package/app/composables/useArticleList.ts +29 -27
- package/app/composables/useClipboard.ts +48 -26
- package/app/composables/useContentSearchData.ts +42 -0
- package/app/composables/useNavigationLinks.ts +40 -0
- package/app/composables/usePageContent.ts +1 -3
- package/app/composables/usePageSeo.ts +7 -15
- package/app/internal/pageLayout.ts +7 -0
- package/app/layouts/article.vue +137 -120
- package/app/layouts/content.vue +63 -59
- package/app/types/config.ts +91 -13
- package/app/utils/createContentSearchLoader.ts +45 -0
- package/app/utils/formatDate.ts +1 -1
- package/app/utils/formatDateTime.ts +1 -1
- package/app/utils/isNavigationTargetActive.ts +12 -0
- package/app/utils/resolveUsers.ts +56 -42
- package/nuxt.config.ts +1 -13
- package/package.json +35 -10
- package/schemas/collections.ts +4 -0
- package/schemas/indexes.ts +10 -0
- package/server/api/navigation.json.get.ts +11 -0
- package/server/api/search.json.get.ts +11 -0
- package/server/utils/contentSearch.ts +67 -0
- package/shared/types/app-config.d.ts +23 -0
- package/app/assets/css/main.css +0 -14
- package/app/components/content/Carousel.vue +0 -11
package/app/types/config.ts
CHANGED
|
@@ -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
|
+
}
|
package/app/utils/formatDate.ts
CHANGED
|
@@ -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
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
39
|
-
|
|
40
|
-
.
|
|
41
|
-
.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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: [
|
|
@@ -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,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happydesigns/ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.17.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"packageManager": "pnpm@11.11.0",
|
|
7
|
+
"description": "A reusable Nuxt foundation for content-driven happydesigns websites and applications.",
|
|
7
8
|
"author": "happydesigns",
|
|
8
|
-
"homepage": "https://github.com/happydesigns",
|
|
9
|
+
"homepage": "https://github.com/happydesigns/ui#readme",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/happydesigns/ui.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/happydesigns/ui/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"nuxt",
|
|
19
|
+
"nuxt-layer",
|
|
20
|
+
"nuxt-ui",
|
|
21
|
+
"nuxt-content",
|
|
22
|
+
"vue",
|
|
23
|
+
"design-system",
|
|
24
|
+
"content-management"
|
|
25
|
+
],
|
|
9
26
|
"exports": {
|
|
10
27
|
".": "./nuxt.config.ts",
|
|
11
|
-
"./schemas": "./schemas/index.ts"
|
|
28
|
+
"./schemas": "./schemas/index.ts",
|
|
29
|
+
"./styles.css": "./app/assets/css/styles.css",
|
|
30
|
+
"./types": "./app/types/config.ts"
|
|
12
31
|
},
|
|
13
32
|
"main": "./nuxt.config.ts",
|
|
14
33
|
"files": [
|
|
15
34
|
"app",
|
|
16
35
|
"content.config.ts",
|
|
17
36
|
"nuxt.config.ts",
|
|
18
|
-
"schemas"
|
|
37
|
+
"schemas",
|
|
38
|
+
"server",
|
|
39
|
+
"shared"
|
|
19
40
|
],
|
|
20
41
|
"publishConfig": {
|
|
21
42
|
"access": "public"
|
|
@@ -27,6 +48,9 @@
|
|
|
27
48
|
"docs:build:server": "nuxt build docs",
|
|
28
49
|
"prepare": "nuxt prepare && nuxt prepare playground",
|
|
29
50
|
"build": "nuxt build playground",
|
|
51
|
+
"generate": "nuxt generate playground && node scripts/validate-playground-output.mjs",
|
|
52
|
+
"package:check": "node scripts/validate-package.mjs",
|
|
53
|
+
"consumer:check": "node scripts/validate-consumer.mjs",
|
|
30
54
|
"preview": "nuxt preview playground",
|
|
31
55
|
"lint": "eslint .",
|
|
32
56
|
"lint:fix": "eslint . --fix",
|
|
@@ -38,17 +62,19 @@
|
|
|
38
62
|
"release:alpha": "changelogen --release --versionSuffix alpha.0",
|
|
39
63
|
"release:beta": "changelogen --release --versionSuffix beta.0"
|
|
40
64
|
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"tailwindcss": "^4.3.2"
|
|
67
|
+
},
|
|
41
68
|
"dependencies": {
|
|
42
69
|
"@happydesigns/nuxt-variants": "^0.0.6",
|
|
43
70
|
"@iconify-json/heroicons": "^1.2.3",
|
|
44
71
|
"@iconify-json/lucide": "^1.2.116",
|
|
45
72
|
"@iconify-json/simple-icons": "^1.2.89",
|
|
46
73
|
"@nuxt/content": "^3.15.0",
|
|
47
|
-
"@nuxt/ui": "^4.
|
|
74
|
+
"@nuxt/ui": "^4.10.0",
|
|
48
75
|
"@vueuse/core": "^14.3.0",
|
|
49
76
|
"better-sqlite3": "^12.11.1",
|
|
50
77
|
"nuxt-studio": "^1.7.0",
|
|
51
|
-
"pathe": "^2.0.3",
|
|
52
78
|
"zod": "^4.4.3"
|
|
53
79
|
},
|
|
54
80
|
"devDependencies": {
|
|
@@ -59,13 +85,12 @@
|
|
|
59
85
|
"cross-env": "^10.1.0",
|
|
60
86
|
"docus": "5.12.3",
|
|
61
87
|
"eslint": "^10.6.0",
|
|
62
|
-
"nuxt": "
|
|
88
|
+
"nuxt": "4.5.1",
|
|
63
89
|
"typescript": "^6.0.3",
|
|
64
90
|
"vitest": "^4.1.10",
|
|
65
|
-
"vue-tsc": "^3.3.7"
|
|
66
|
-
"zod-to-json-schema": "^3.25.2"
|
|
91
|
+
"vue-tsc": "^3.3.7"
|
|
67
92
|
},
|
|
68
93
|
"resolutions": {
|
|
69
94
|
"@happydesigns/ui": "workspace:*"
|
|
70
95
|
}
|
|
71
|
-
}
|
|
96
|
+
}
|
package/schemas/collections.ts
CHANGED
|
@@ -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[]
|
|
@@ -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
|
+
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { PageCollections, SQLOperator } from '@nuxt/content'
|
|
2
|
+
import type { H3Event } from 'h3'
|
|
3
|
+
import type { SearchCollectionConfig, SearchConfig } from '../../app/types/config'
|
|
4
|
+
|
|
5
|
+
interface ConfigurableSearchQuery {
|
|
6
|
+
where: (field: string, operator: SQLOperator, value?: unknown) => unknown
|
|
7
|
+
order: (field: string, direction: 'ASC' | 'DESC') => unknown
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type SearchCacheConfig = NonNullable<SearchConfig['cache']>
|
|
11
|
+
|
|
12
|
+
const DEFAULT_SHARED_MAX_AGE = 300
|
|
13
|
+
const DEFAULT_STALE_WHILE_REVALIDATE = 3600
|
|
14
|
+
|
|
15
|
+
function normalizedSeconds(value: number | undefined, fallback: number) {
|
|
16
|
+
if (value === undefined || !Number.isFinite(value))
|
|
17
|
+
return fallback
|
|
18
|
+
|
|
19
|
+
return Math.max(0, Math.floor(value))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createSearchCacheControl(config: SearchCacheConfig = {}, isDevelopment = false) {
|
|
23
|
+
if (config === false || isDevelopment)
|
|
24
|
+
return 'no-store'
|
|
25
|
+
|
|
26
|
+
const sharedMaxAge = normalizedSeconds(config.sharedMaxAge, DEFAULT_SHARED_MAX_AGE)
|
|
27
|
+
const staleWhileRevalidate = normalizedSeconds(
|
|
28
|
+
config.staleWhileRevalidate,
|
|
29
|
+
DEFAULT_STALE_WHILE_REVALIDATE,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
return `public, max-age=0, s-maxage=${sharedMaxAge}, stale-while-revalidate=${staleWhileRevalidate}`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function setSearchCacheHeaders(event: H3Event) {
|
|
36
|
+
const cache = (useAppConfig().app?.search?.cache ?? {}) as SearchCacheConfig
|
|
37
|
+
setResponseHeader(event, 'Cache-Control', createSearchCacheControl(cache, import.meta.dev))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function applySearchCollectionConfig<T>(query: T, config: SearchCollectionConfig): T {
|
|
41
|
+
let configuredQuery = query as ConfigurableSearchQuery
|
|
42
|
+
|
|
43
|
+
for (const condition of config.where ?? []) {
|
|
44
|
+
configuredQuery = configuredQuery.where(
|
|
45
|
+
condition.field,
|
|
46
|
+
condition.operator,
|
|
47
|
+
condition.value,
|
|
48
|
+
) as ConfigurableSearchQuery
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (config.order) {
|
|
52
|
+
configuredQuery = configuredQuery.order(
|
|
53
|
+
config.order.field,
|
|
54
|
+
config.order.direction,
|
|
55
|
+
) as ConfigurableSearchQuery
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return configuredQuery as T
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function getSearchCollections(): SearchCollectionConfig[] {
|
|
62
|
+
return (useAppConfig().app?.search?.collections ?? []) as SearchCollectionConfig[]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function asPageCollection(name: keyof PageCollections): keyof PageCollections {
|
|
66
|
+
return name
|
|
67
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { HAppConfig, HAppConfigInput } from '../../app/types/config'
|
|
2
|
+
|
|
3
|
+
declare module '@nuxt/schema' {
|
|
4
|
+
interface AppConfigInput {
|
|
5
|
+
app?: HAppConfigInput
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface AppConfig {
|
|
9
|
+
app: HAppConfig
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module 'nuxt/schema' {
|
|
14
|
+
interface AppConfigInput {
|
|
15
|
+
app?: HAppConfigInput
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface AppConfig {
|
|
19
|
+
app: HAppConfig
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {}
|
package/app/assets/css/main.css
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
@import "tailwindcss";
|
|
2
|
-
@import "@nuxt/ui";
|
|
3
|
-
|
|
4
|
-
@custom-variant all (&);
|
|
5
|
-
|
|
6
|
-
@layer theme {
|
|
7
|
-
p .iconify {
|
|
8
|
-
display: inline-block;
|
|
9
|
-
margin-right: --spacing(1);
|
|
10
|
-
width: 1em !important;
|
|
11
|
-
height: 1em !important;
|
|
12
|
-
transform: translateY(-1px);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
defineProps<{
|
|
3
|
-
items: string[]
|
|
4
|
-
}>()
|
|
5
|
-
</script>
|
|
6
|
-
|
|
7
|
-
<template>
|
|
8
|
-
<UCarousel v-slot="{ item }" :items="items" :ui="{ item: 'basis-full sm:basis-1/2' }" dots>
|
|
9
|
-
<ProseImg :src="item" alt="" class="w-full rounded-lg" />
|
|
10
|
-
</UCarousel>
|
|
11
|
-
</template>
|