@happydesigns/ui 0.18.0 → 0.19.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 +96 -70
- package/app/app.config.ts +139 -135
- package/app/components/Snippet.vue +7 -2
- package/app/components/article/ArticleGrid.vue +2 -2
- package/app/components/article/ArticleHeaderBody.vue +26 -26
- package/app/components/article/ArticleHeadlineMeta.vue +37 -37
- package/app/components/article/ArticleList.vue +2 -2
- package/app/components/article/ArticlePage.vue +2 -2
- package/app/components/traits/Authors.vue +2 -1
- package/app/components/traits/Links.vue +17 -21
- package/app/components/traits/Surround.vue +13 -7
- package/app/composables/useArticleList.ts +44 -33
- package/app/composables/usePageContent.ts +22 -19
- package/app/layouts/article.vue +132 -132
- package/app/layouts/content.vue +70 -70
- package/app/types/config.ts +96 -91
- package/app/types/content.ts +14 -0
- package/app/utils/resolveUsers.ts +56 -55
- package/package.json +2 -3
- package/schemas/collections.ts +11 -46
- package/schemas/index.ts +1 -0
- package/server/utils/contentSearch.ts +68 -67
- package/content.config.ts +0 -6
|
@@ -1,67 +1,68 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
condition.
|
|
47
|
-
condition.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
config.order.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
import type { PageCollectionName } from '../../app/types/content'
|
|
5
|
+
|
|
6
|
+
interface ConfigurableSearchQuery {
|
|
7
|
+
where: (field: string, operator: SQLOperator, value?: unknown) => unknown
|
|
8
|
+
order: (field: string, direction: 'ASC' | 'DESC') => unknown
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type SearchCacheConfig = NonNullable<SearchConfig['cache']>
|
|
12
|
+
|
|
13
|
+
const DEFAULT_SHARED_MAX_AGE = 300
|
|
14
|
+
const DEFAULT_STALE_WHILE_REVALIDATE = 3600
|
|
15
|
+
|
|
16
|
+
function normalizedSeconds(value: number | undefined, fallback: number) {
|
|
17
|
+
if (value === undefined || !Number.isFinite(value))
|
|
18
|
+
return fallback
|
|
19
|
+
|
|
20
|
+
return Math.max(0, Math.floor(value))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createSearchCacheControl(config: SearchCacheConfig = {}, isDevelopment = false) {
|
|
24
|
+
if (config === false || isDevelopment)
|
|
25
|
+
return 'no-store'
|
|
26
|
+
|
|
27
|
+
const sharedMaxAge = normalizedSeconds(config.sharedMaxAge, DEFAULT_SHARED_MAX_AGE)
|
|
28
|
+
const staleWhileRevalidate = normalizedSeconds(
|
|
29
|
+
config.staleWhileRevalidate,
|
|
30
|
+
DEFAULT_STALE_WHILE_REVALIDATE,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
return `public, max-age=0, s-maxage=${sharedMaxAge}, stale-while-revalidate=${staleWhileRevalidate}`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function setSearchCacheHeaders(event: H3Event) {
|
|
37
|
+
const cache = (useAppConfig().app?.search?.cache ?? {}) as SearchCacheConfig
|
|
38
|
+
setResponseHeader(event, 'Cache-Control', createSearchCacheControl(cache, import.meta.dev))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function applySearchCollectionConfig<T>(query: T, config: SearchCollectionConfig): T {
|
|
42
|
+
let configuredQuery = query as ConfigurableSearchQuery
|
|
43
|
+
|
|
44
|
+
for (const condition of config.where ?? []) {
|
|
45
|
+
configuredQuery = configuredQuery.where(
|
|
46
|
+
condition.field,
|
|
47
|
+
condition.operator,
|
|
48
|
+
condition.value,
|
|
49
|
+
) as ConfigurableSearchQuery
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (config.order) {
|
|
53
|
+
configuredQuery = configuredQuery.order(
|
|
54
|
+
config.order.field,
|
|
55
|
+
config.order.direction,
|
|
56
|
+
) as ConfigurableSearchQuery
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return configuredQuery as T
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function getSearchCollections(): SearchCollectionConfig[] {
|
|
63
|
+
return (useAppConfig().app?.search?.collections ?? []) as SearchCollectionConfig[]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function asPageCollection(name: PageCollectionName): keyof PageCollections {
|
|
67
|
+
return name as keyof PageCollections
|
|
68
|
+
}
|