@ztl-uwu/nuxt-content 2.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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/module.d.mts +1176 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +696 -0
- package/dist/runtime/app.vue +3 -0
- package/dist/runtime/app.vue.d.ts +2 -0
- package/dist/runtime/components/ContentDoc.vue +108 -0
- package/dist/runtime/components/ContentDoc.vue.d.ts +118 -0
- package/dist/runtime/components/ContentList.vue +59 -0
- package/dist/runtime/components/ContentList.vue.d.ts +59 -0
- package/dist/runtime/components/ContentNavigation.vue +61 -0
- package/dist/runtime/components/ContentNavigation.vue.d.ts +35 -0
- package/dist/runtime/components/ContentQuery.vue +212 -0
- package/dist/runtime/components/ContentQuery.vue.d.ts +0 -0
- package/dist/runtime/components/ContentRenderer.vue +78 -0
- package/dist/runtime/components/ContentRenderer.vue.d.ts +56 -0
- package/dist/runtime/components/ContentRendererMarkdown.vue +69 -0
- package/dist/runtime/components/ContentRendererMarkdown.vue.d.ts +73 -0
- package/dist/runtime/components/ContentSlot.vue +25 -0
- package/dist/runtime/components/ContentSlot.vue.d.ts +37 -0
- package/dist/runtime/components/DocumentDrivenEmpty.vue +18 -0
- package/dist/runtime/components/DocumentDrivenEmpty.vue.d.ts +17 -0
- package/dist/runtime/components/DocumentDrivenNotFound.vue +9 -0
- package/dist/runtime/components/DocumentDrivenNotFound.vue.d.ts +5 -0
- package/dist/runtime/components/Markdown.vue +29 -0
- package/dist/runtime/components/Markdown.vue.d.ts +31 -0
- package/dist/runtime/components/Prose/ProseCode.vue +32 -0
- package/dist/runtime/components/Prose/ProseCode.vue.d.ts +110 -0
- package/dist/runtime/components/Prose/ProseCodeInline.vue +3 -0
- package/dist/runtime/components/Prose/ProseCodeInline.vue.d.ts +14 -0
- package/dist/runtime/components/Prose/ProsePre.vue +42 -0
- package/dist/runtime/components/Prose/ProsePre.vue.d.ts +146 -0
- package/dist/runtime/composables/client-db.d.ts +14 -0
- package/dist/runtime/composables/client-db.js +105 -0
- package/dist/runtime/composables/content.d.ts +19 -0
- package/dist/runtime/composables/content.js +41 -0
- package/dist/runtime/composables/head.d.ts +4 -0
- package/dist/runtime/composables/head.js +94 -0
- package/dist/runtime/composables/helpers.d.ts +7 -0
- package/dist/runtime/composables/helpers.js +66 -0
- package/dist/runtime/composables/navigation.d.ts +2 -0
- package/dist/runtime/composables/navigation.js +34 -0
- package/dist/runtime/composables/preview.d.ts +5 -0
- package/dist/runtime/composables/preview.js +41 -0
- package/dist/runtime/composables/query.d.ts +10 -0
- package/dist/runtime/composables/query.js +64 -0
- package/dist/runtime/composables/search.d.ts +130 -0
- package/dist/runtime/composables/search.js +59 -0
- package/dist/runtime/composables/useUnwrap.d.ts +5 -0
- package/dist/runtime/composables/useUnwrap.js +5 -0
- package/dist/runtime/composables/utils.d.ts +6 -0
- package/dist/runtime/composables/utils.js +36 -0
- package/dist/runtime/composables/web-socket.d.ts +3 -0
- package/dist/runtime/composables/web-socket.js +65 -0
- package/dist/runtime/legacy/composables/client-db.d.ts +12 -0
- package/dist/runtime/legacy/composables/client-db.js +105 -0
- package/dist/runtime/legacy/composables/navigation.d.ts +2 -0
- package/dist/runtime/legacy/composables/navigation.js +34 -0
- package/dist/runtime/legacy/composables/query.d.ts +10 -0
- package/dist/runtime/legacy/composables/query.js +61 -0
- package/dist/runtime/legacy/plugins/documentDriven.d.ts +2 -0
- package/dist/runtime/legacy/plugins/documentDriven.js +231 -0
- package/dist/runtime/legacy/server.d.ts +3 -0
- package/dist/runtime/legacy/server.js +3 -0
- package/dist/runtime/legacy/types.d.ts +5 -0
- package/dist/runtime/pages/document-driven.vue +27 -0
- package/dist/runtime/pages/document-driven.vue.d.ts +2 -0
- package/dist/runtime/plugins/documentDriven.d.ts +2 -0
- package/dist/runtime/plugins/documentDriven.js +222 -0
- package/dist/runtime/plugins/ws.d.ts +2 -0
- package/dist/runtime/plugins/ws.js +7 -0
- package/dist/runtime/query/match/index.d.ts +6 -0
- package/dist/runtime/query/match/index.js +123 -0
- package/dist/runtime/query/match/pipeline-legacy.d.ts +2 -0
- package/dist/runtime/query/match/pipeline-legacy.js +22 -0
- package/dist/runtime/query/match/pipeline.d.ts +2 -0
- package/dist/runtime/query/match/pipeline.js +104 -0
- package/dist/runtime/query/match/utils.d.ts +35 -0
- package/dist/runtime/query/match/utils.js +65 -0
- package/dist/runtime/query/query.d.ts +12 -0
- package/dist/runtime/query/query.js +61 -0
- package/dist/runtime/server/api/cache.d.ts +7 -0
- package/dist/runtime/server/api/cache.js +18 -0
- package/dist/runtime/server/api/navigation-qid-params.d.ts +1 -0
- package/dist/runtime/server/api/navigation-qid-params.js +1 -0
- package/dist/runtime/server/api/navigation-qid.d.ts +1 -0
- package/dist/runtime/server/api/navigation-qid.js +1 -0
- package/dist/runtime/server/api/navigation.d.ts +2 -0
- package/dist/runtime/server/api/navigation.js +42 -0
- package/dist/runtime/server/api/query-qid-params.d.ts +1 -0
- package/dist/runtime/server/api/query-qid-params.js +1 -0
- package/dist/runtime/server/api/query-qid.d.ts +1 -0
- package/dist/runtime/server/api/query-qid.js +1 -0
- package/dist/runtime/server/api/query.d.ts +2 -0
- package/dist/runtime/server/api/query.js +32 -0
- package/dist/runtime/server/api/search.d.ts +8 -0
- package/dist/runtime/server/api/search.js +16 -0
- package/dist/runtime/server/content-index.d.ts +4 -0
- package/dist/runtime/server/content-index.js +37 -0
- package/dist/runtime/server/index.d.ts +1 -0
- package/dist/runtime/server/index.js +1 -0
- package/dist/runtime/server/navigation.d.ts +5 -0
- package/dist/runtime/server/navigation.js +96 -0
- package/dist/runtime/server/plugins/refresh-cache.d.ts +2 -0
- package/dist/runtime/server/plugins/refresh-cache.js +15 -0
- package/dist/runtime/server/preview.d.ts +5 -0
- package/dist/runtime/server/preview.js +9 -0
- package/dist/runtime/server/search.d.ts +14 -0
- package/dist/runtime/server/search.js +70 -0
- package/dist/runtime/server/storage.d.ts +35 -0
- package/dist/runtime/server/storage.js +238 -0
- package/dist/runtime/transformers/component-resolver.d.ts +2 -0
- package/dist/runtime/transformers/component-resolver.js +44 -0
- package/dist/runtime/transformers/csv/create-tokenizer.d.ts +39 -0
- package/dist/runtime/transformers/csv/create-tokenizer.js +307 -0
- package/dist/runtime/transformers/csv/from-csv.d.ts +13 -0
- package/dist/runtime/transformers/csv/from-csv.js +203 -0
- package/dist/runtime/transformers/csv/index.d.ts +2 -0
- package/dist/runtime/transformers/csv/index.js +50 -0
- package/dist/runtime/transformers/csv/parser.d.ts +24 -0
- package/dist/runtime/transformers/csv/parser.js +154 -0
- package/dist/runtime/transformers/index.d.ts +7 -0
- package/dist/runtime/transformers/index.js +50 -0
- package/dist/runtime/transformers/json.d.ts +2 -0
- package/dist/runtime/transformers/json.js +29 -0
- package/dist/runtime/transformers/markdown.d.ts +2 -0
- package/dist/runtime/transformers/markdown.js +88 -0
- package/dist/runtime/transformers/path-meta.d.ts +27 -0
- package/dist/runtime/transformers/path-meta.js +59 -0
- package/dist/runtime/transformers/utils.d.ts +3 -0
- package/dist/runtime/transformers/utils.js +12 -0
- package/dist/runtime/transformers/yaml.d.ts +2 -0
- package/dist/runtime/transformers/yaml.js +21 -0
- package/dist/runtime/utils/config.d.ts +4 -0
- package/dist/runtime/utils/config.js +7 -0
- package/dist/runtime/utils/html-tags.d.ts +2 -0
- package/dist/runtime/utils/html-tags.js +119 -0
- package/dist/runtime/utils/json.d.ts +10 -0
- package/dist/runtime/utils/json.js +20 -0
- package/dist/runtime/utils/query.d.ts +5 -0
- package/dist/runtime/utils/query.js +77 -0
- package/dist/runtime/virtual/transformers.d.ts +2 -0
- package/dist/types.d.mts +9 -0
- package/dist/web-types.json +572 -0
- package/package.json +111 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { defineComponent, h, useSlots } from "vue";
|
|
3
|
+
import { withTrailingSlash } from "ufo";
|
|
4
|
+
import ContentRenderer from "./ContentRenderer.vue";
|
|
5
|
+
import ContentQuery from "./ContentQuery.vue";
|
|
6
|
+
import { useRuntimeConfig, useRoute, useContentHead } from "#imports";
|
|
7
|
+
const ContentDoc = defineComponent({
|
|
8
|
+
name: "ContentDoc",
|
|
9
|
+
props: {
|
|
10
|
+
/**
|
|
11
|
+
* Renderer props
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The tag to use for the renderer element if it is used.
|
|
15
|
+
* @default 'div'
|
|
16
|
+
*/
|
|
17
|
+
tag: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: false,
|
|
20
|
+
default: "div"
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Whether or not to render the excerpt.
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
excerpt: {
|
|
27
|
+
type: Boolean,
|
|
28
|
+
default: false
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* Query props
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* The path of the content to load from content source.
|
|
35
|
+
* @default useRoute().path
|
|
36
|
+
*/
|
|
37
|
+
path: {
|
|
38
|
+
type: String,
|
|
39
|
+
required: false,
|
|
40
|
+
default: void 0
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* A query builder params object to be passed to <ContentQuery /> component.
|
|
44
|
+
*/
|
|
45
|
+
query: {
|
|
46
|
+
type: Object,
|
|
47
|
+
required: false,
|
|
48
|
+
default: void 0
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Whether or not to map the document data to the `head` property.
|
|
52
|
+
*/
|
|
53
|
+
head: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
required: false,
|
|
56
|
+
default: void 0
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Document empty fallback
|
|
61
|
+
* @slot empty
|
|
62
|
+
*/
|
|
63
|
+
/**
|
|
64
|
+
* Document not found fallback
|
|
65
|
+
* @slot not-found
|
|
66
|
+
*/
|
|
67
|
+
render(ctx) {
|
|
68
|
+
const { contentHead } = useRuntimeConfig().public.content;
|
|
69
|
+
const slots = useSlots();
|
|
70
|
+
const { tag, excerpt, path, query, head } = ctx;
|
|
71
|
+
const shouldInjectContentHead = head === void 0 ? contentHead : head;
|
|
72
|
+
const contentQueryProps = {
|
|
73
|
+
...query || {},
|
|
74
|
+
path: path || query?.path || withTrailingSlash(useRoute().path),
|
|
75
|
+
find: "one"
|
|
76
|
+
};
|
|
77
|
+
const emptyNode = (slot, data) => h("pre", null, JSON.stringify({ message: "You should use slots with <ContentDoc>", slot, data }, null, 2));
|
|
78
|
+
return h(
|
|
79
|
+
ContentQuery,
|
|
80
|
+
contentQueryProps,
|
|
81
|
+
{
|
|
82
|
+
// Default slot
|
|
83
|
+
default: slots?.default ? ({ data, refresh, isPartial }) => {
|
|
84
|
+
if (shouldInjectContentHead) {
|
|
85
|
+
useContentHead(data);
|
|
86
|
+
}
|
|
87
|
+
return slots.default?.({ doc: data, refresh, isPartial, excerpt, ...this.$attrs });
|
|
88
|
+
} : ({ data }) => {
|
|
89
|
+
if (shouldInjectContentHead) {
|
|
90
|
+
useContentHead(data);
|
|
91
|
+
}
|
|
92
|
+
return h(
|
|
93
|
+
ContentRenderer,
|
|
94
|
+
{ value: data, excerpt, tag, ...this.$attrs },
|
|
95
|
+
// Forward local `empty` slots to ContentRenderer if it is used.
|
|
96
|
+
{ empty: (bindings) => slots?.empty ? slots.empty(bindings) : emptyNode("default", data) }
|
|
97
|
+
);
|
|
98
|
+
},
|
|
99
|
+
// Empty slot
|
|
100
|
+
empty: (bindings) => slots?.empty?.(bindings) || h("p", null, "Document is empty, overwrite this content with #empty slot in <ContentDoc>."),
|
|
101
|
+
// Not Found slot
|
|
102
|
+
"not-found": (bindings) => slots?.["not-found"]?.(bindings) || h("p", null, "Document not found, overwrite this content with #not-found slot in <ContentDoc>.")
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
export default ContentDoc;
|
|
108
|
+
</script>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type PropType, type VNode } from 'vue';
|
|
2
|
+
import type { ParsedContent, QueryBuilderParams } from '@nuxt/content';
|
|
3
|
+
declare const ContentDoc: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
4
|
+
/**
|
|
5
|
+
* Renderer props
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The tag to use for the renderer element if it is used.
|
|
9
|
+
* @default 'div'
|
|
10
|
+
*/
|
|
11
|
+
tag: {
|
|
12
|
+
type: StringConstructor;
|
|
13
|
+
required: false;
|
|
14
|
+
default: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Whether or not to render the excerpt.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
excerpt: {
|
|
21
|
+
type: BooleanConstructor;
|
|
22
|
+
default: boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Query props
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* The path of the content to load from content source.
|
|
29
|
+
* @default useRoute().path
|
|
30
|
+
*/
|
|
31
|
+
path: {
|
|
32
|
+
type: StringConstructor;
|
|
33
|
+
required: false;
|
|
34
|
+
default: undefined;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* A query builder params object to be passed to <ContentQuery /> component.
|
|
38
|
+
*/
|
|
39
|
+
query: {
|
|
40
|
+
type: PropType<QueryBuilderParams>;
|
|
41
|
+
required: false;
|
|
42
|
+
default: undefined;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Whether or not to map the document data to the `head` property.
|
|
46
|
+
*/
|
|
47
|
+
head: {
|
|
48
|
+
type: BooleanConstructor;
|
|
49
|
+
required: false;
|
|
50
|
+
default: undefined;
|
|
51
|
+
};
|
|
52
|
+
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
53
|
+
/**
|
|
54
|
+
* Renderer props
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* The tag to use for the renderer element if it is used.
|
|
58
|
+
* @default 'div'
|
|
59
|
+
*/
|
|
60
|
+
tag: {
|
|
61
|
+
type: StringConstructor;
|
|
62
|
+
required: false;
|
|
63
|
+
default: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Whether or not to render the excerpt.
|
|
67
|
+
* @default false
|
|
68
|
+
*/
|
|
69
|
+
excerpt: {
|
|
70
|
+
type: BooleanConstructor;
|
|
71
|
+
default: boolean;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Query props
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* The path of the content to load from content source.
|
|
78
|
+
* @default useRoute().path
|
|
79
|
+
*/
|
|
80
|
+
path: {
|
|
81
|
+
type: StringConstructor;
|
|
82
|
+
required: false;
|
|
83
|
+
default: undefined;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* A query builder params object to be passed to <ContentQuery /> component.
|
|
87
|
+
*/
|
|
88
|
+
query: {
|
|
89
|
+
type: PropType<QueryBuilderParams>;
|
|
90
|
+
required: false;
|
|
91
|
+
default: undefined;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Whether or not to map the document data to the `head` property.
|
|
95
|
+
*/
|
|
96
|
+
head: {
|
|
97
|
+
type: BooleanConstructor;
|
|
98
|
+
required: false;
|
|
99
|
+
default: undefined;
|
|
100
|
+
};
|
|
101
|
+
}>> & Readonly<{}>, {
|
|
102
|
+
path: string;
|
|
103
|
+
query: QueryBuilderParams;
|
|
104
|
+
head: boolean;
|
|
105
|
+
tag: string;
|
|
106
|
+
excerpt: boolean;
|
|
107
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
108
|
+
declare const _default: typeof ContentDoc & {
|
|
109
|
+
new (): {
|
|
110
|
+
$slots: {
|
|
111
|
+
default: (context: {
|
|
112
|
+
doc: ParsedContent;
|
|
113
|
+
refresh: () => Promise<void>;
|
|
114
|
+
}) => VNode[] | undefined;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
export default _default;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { defineComponent, h, useSlots } from "vue";
|
|
3
|
+
import ContentQuery from "./ContentQuery.vue";
|
|
4
|
+
const emptyNode = (slot, data) => h("pre", null, JSON.stringify({ message: "You should use slots with <ContentList>", slot, data }, null, 2));
|
|
5
|
+
const ContentList = defineComponent({
|
|
6
|
+
name: "ContentList",
|
|
7
|
+
props: {
|
|
8
|
+
/**
|
|
9
|
+
* Query props
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* The path of the content to load from content source.
|
|
13
|
+
* @default '/'
|
|
14
|
+
*/
|
|
15
|
+
path: {
|
|
16
|
+
type: String,
|
|
17
|
+
required: false,
|
|
18
|
+
default: void 0
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* A query builder params object to be passed to <ContentQuery /> component.
|
|
22
|
+
*/
|
|
23
|
+
query: {
|
|
24
|
+
type: Object,
|
|
25
|
+
required: false,
|
|
26
|
+
default: void 0
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* Content empty fallback
|
|
31
|
+
* @slot empty
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Content not found fallback
|
|
35
|
+
* @slot not-found
|
|
36
|
+
*/
|
|
37
|
+
render(ctx) {
|
|
38
|
+
const slots = useSlots();
|
|
39
|
+
const { path, query } = ctx;
|
|
40
|
+
const contentQueryProps = {
|
|
41
|
+
...query || {},
|
|
42
|
+
path: path || query?.path || "/"
|
|
43
|
+
};
|
|
44
|
+
return h(
|
|
45
|
+
ContentQuery,
|
|
46
|
+
contentQueryProps,
|
|
47
|
+
{
|
|
48
|
+
// Default slot
|
|
49
|
+
default: slots?.default ? ({ data, refresh, isPartial }) => slots.default({ list: data, refresh, isPartial, ...this.$attrs }) : (bindings) => emptyNode("default", bindings.data),
|
|
50
|
+
// Empty slot
|
|
51
|
+
empty: (bindings) => slots?.empty ? slots.empty(bindings) : emptyNode("default", bindings?.data),
|
|
52
|
+
// Not Found slot
|
|
53
|
+
"not-found": (bindings) => slots?.["not-found"] ? slots?.["not-found"]?.(bindings) : emptyNode("not-found", bindings?.data)
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
export default ContentList;
|
|
59
|
+
</script>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type PropType, type VNode } from 'vue';
|
|
2
|
+
import type { ParsedContent, QueryBuilderParams } from '@nuxt/content';
|
|
3
|
+
declare const ContentList: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
4
|
+
/**
|
|
5
|
+
* Query props
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The path of the content to load from content source.
|
|
9
|
+
* @default '/'
|
|
10
|
+
*/
|
|
11
|
+
path: {
|
|
12
|
+
type: StringConstructor;
|
|
13
|
+
required: false;
|
|
14
|
+
default: undefined;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A query builder params object to be passed to <ContentQuery /> component.
|
|
18
|
+
*/
|
|
19
|
+
query: {
|
|
20
|
+
type: PropType<QueryBuilderParams>;
|
|
21
|
+
required: false;
|
|
22
|
+
default: undefined;
|
|
23
|
+
};
|
|
24
|
+
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
25
|
+
/**
|
|
26
|
+
* Query props
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* The path of the content to load from content source.
|
|
30
|
+
* @default '/'
|
|
31
|
+
*/
|
|
32
|
+
path: {
|
|
33
|
+
type: StringConstructor;
|
|
34
|
+
required: false;
|
|
35
|
+
default: undefined;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* A query builder params object to be passed to <ContentQuery /> component.
|
|
39
|
+
*/
|
|
40
|
+
query: {
|
|
41
|
+
type: PropType<QueryBuilderParams>;
|
|
42
|
+
required: false;
|
|
43
|
+
default: undefined;
|
|
44
|
+
};
|
|
45
|
+
}>> & Readonly<{}>, {
|
|
46
|
+
path: string;
|
|
47
|
+
query: QueryBuilderParams;
|
|
48
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
49
|
+
declare const _default: typeof ContentList & {
|
|
50
|
+
new (): {
|
|
51
|
+
$slots: {
|
|
52
|
+
default: (context: {
|
|
53
|
+
list: ParsedContent[];
|
|
54
|
+
refresh: () => Promise<void>;
|
|
55
|
+
}) => VNode[] | undefined;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export default _default;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { toRefs, defineComponent, h, useSlots, computed } from "vue";
|
|
3
|
+
import { hash } from "ohash";
|
|
4
|
+
import { useAsyncData, fetchContentNavigation, useState, useContent } from "#imports";
|
|
5
|
+
import { NuxtLink } from "#components";
|
|
6
|
+
const ContentNavigation = defineComponent({
|
|
7
|
+
name: "ContentNavigation",
|
|
8
|
+
props: {
|
|
9
|
+
/**
|
|
10
|
+
* A query to be passed to `fetchContentNavigation()`.
|
|
11
|
+
*/
|
|
12
|
+
query: {
|
|
13
|
+
type: Object,
|
|
14
|
+
required: false,
|
|
15
|
+
default: void 0
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
async setup(props) {
|
|
19
|
+
const {
|
|
20
|
+
query
|
|
21
|
+
} = toRefs(props);
|
|
22
|
+
const queryBuilder = computed(() => {
|
|
23
|
+
if (typeof query.value?.params === "function") {
|
|
24
|
+
return query.value.params();
|
|
25
|
+
}
|
|
26
|
+
return query.value;
|
|
27
|
+
});
|
|
28
|
+
if (!queryBuilder.value && useState("dd-navigation").value) {
|
|
29
|
+
const { navigation: navigation2 } = useContent();
|
|
30
|
+
return { navigation: navigation2 };
|
|
31
|
+
}
|
|
32
|
+
const { data: navigation } = await useAsyncData(
|
|
33
|
+
`content-navigation-${hash(queryBuilder.value)}`,
|
|
34
|
+
() => fetchContentNavigation(queryBuilder.value)
|
|
35
|
+
);
|
|
36
|
+
return { navigation };
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* Navigation empty fallback
|
|
40
|
+
* @slot empty
|
|
41
|
+
*/
|
|
42
|
+
render(ctx) {
|
|
43
|
+
const slots = useSlots();
|
|
44
|
+
const { navigation } = ctx;
|
|
45
|
+
const renderLink = (link) => h(NuxtLink, { to: link._path }, () => link.title);
|
|
46
|
+
const renderLinks = (data, level) => h(
|
|
47
|
+
"ul",
|
|
48
|
+
level ? { "data-level": level } : null,
|
|
49
|
+
data.map((link) => {
|
|
50
|
+
if (link.children) {
|
|
51
|
+
return h("li", null, [renderLink(link), renderLinks(link.children, level + 1)]);
|
|
52
|
+
}
|
|
53
|
+
return h("li", null, renderLink(link));
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
const defaultNode = (data) => renderLinks(data, 0);
|
|
57
|
+
return slots?.default ? slots.default({ navigation, ...this.$attrs }) : defaultNode(navigation);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
export default ContentNavigation;
|
|
61
|
+
</script>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type PropType, type VNode } from 'vue';
|
|
2
|
+
import type { NavItem, QueryBuilderParams, QueryBuilder } from '@nuxt/content';
|
|
3
|
+
declare const ContentNavigation: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
4
|
+
/**
|
|
5
|
+
* A query to be passed to `fetchContentNavigation()`.
|
|
6
|
+
*/
|
|
7
|
+
query: {
|
|
8
|
+
type: PropType<QueryBuilderParams | QueryBuilder>;
|
|
9
|
+
required: false;
|
|
10
|
+
default: undefined;
|
|
11
|
+
};
|
|
12
|
+
}>, {
|
|
13
|
+
navigation: import("vue").Ref<NavItem[] | null, NavItem[] | null>;
|
|
14
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
15
|
+
/**
|
|
16
|
+
* A query to be passed to `fetchContentNavigation()`.
|
|
17
|
+
*/
|
|
18
|
+
query: {
|
|
19
|
+
type: PropType<QueryBuilderParams | QueryBuilder>;
|
|
20
|
+
required: false;
|
|
21
|
+
default: undefined;
|
|
22
|
+
};
|
|
23
|
+
}>> & Readonly<{}>, {
|
|
24
|
+
query: any;
|
|
25
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
26
|
+
declare const _default: typeof ContentNavigation & {
|
|
27
|
+
new (): {
|
|
28
|
+
$slots: {
|
|
29
|
+
default: ({ navigation }: {
|
|
30
|
+
navigation: NavItem[];
|
|
31
|
+
}) => VNode[] | undefined;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export default _default;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { hash } from "ohash";
|
|
3
|
+
import { toRefs, defineComponent, h, useSlots, watch } from "vue";
|
|
4
|
+
import { computed, useAsyncData, queryContent, useRuntimeConfig } from "#imports";
|
|
5
|
+
const ContentQuery = defineComponent({
|
|
6
|
+
name: "ContentQuery",
|
|
7
|
+
props: {
|
|
8
|
+
/**
|
|
9
|
+
* The path of the content to load from content source.
|
|
10
|
+
*/
|
|
11
|
+
path: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: false,
|
|
14
|
+
default: void 0
|
|
15
|
+
},
|
|
16
|
+
/**
|
|
17
|
+
* Select a subset of fields
|
|
18
|
+
*/
|
|
19
|
+
only: {
|
|
20
|
+
type: Array,
|
|
21
|
+
required: false,
|
|
22
|
+
default: void 0
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* Remove a subset of fields
|
|
26
|
+
*/
|
|
27
|
+
without: {
|
|
28
|
+
type: Array,
|
|
29
|
+
required: false,
|
|
30
|
+
default: void 0
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* Filter results
|
|
34
|
+
*/
|
|
35
|
+
where: {
|
|
36
|
+
type: Object,
|
|
37
|
+
required: false,
|
|
38
|
+
default: void 0
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Sort results
|
|
42
|
+
*/
|
|
43
|
+
sort: {
|
|
44
|
+
type: Object,
|
|
45
|
+
required: false,
|
|
46
|
+
default: void 0
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* Limit number of results
|
|
50
|
+
*/
|
|
51
|
+
limit: {
|
|
52
|
+
type: Number,
|
|
53
|
+
required: false,
|
|
54
|
+
default: void 0
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Skip number of results
|
|
58
|
+
*/
|
|
59
|
+
skip: {
|
|
60
|
+
type: Number,
|
|
61
|
+
required: false,
|
|
62
|
+
default: void 0
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Filter contents based on locale
|
|
66
|
+
*/
|
|
67
|
+
locale: {
|
|
68
|
+
type: String,
|
|
69
|
+
required: false,
|
|
70
|
+
default: void 0
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* A type of query to be made.
|
|
74
|
+
*/
|
|
75
|
+
find: {
|
|
76
|
+
type: String,
|
|
77
|
+
required: false,
|
|
78
|
+
default: void 0
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
async setup(props) {
|
|
82
|
+
const {
|
|
83
|
+
path,
|
|
84
|
+
only,
|
|
85
|
+
without,
|
|
86
|
+
where,
|
|
87
|
+
sort,
|
|
88
|
+
limit,
|
|
89
|
+
skip,
|
|
90
|
+
locale,
|
|
91
|
+
find
|
|
92
|
+
} = toRefs(props);
|
|
93
|
+
const isPartial = computed(() => path.value?.includes("/_"));
|
|
94
|
+
const legacy = !useRuntimeConfig().public.content.experimental.advanceQuery;
|
|
95
|
+
watch(() => props, () => refresh(), { deep: true });
|
|
96
|
+
const resolveResult = (result) => {
|
|
97
|
+
if (legacy) {
|
|
98
|
+
if (result?.surround) {
|
|
99
|
+
return result.surround;
|
|
100
|
+
}
|
|
101
|
+
return result?._id || Array.isArray(result) ? result : result?.result;
|
|
102
|
+
}
|
|
103
|
+
return result.result;
|
|
104
|
+
};
|
|
105
|
+
const { data, refresh } = await useAsyncData(
|
|
106
|
+
`content-query-${hash(props)}`,
|
|
107
|
+
() => {
|
|
108
|
+
let queryBuilder;
|
|
109
|
+
if (path.value) {
|
|
110
|
+
queryBuilder = queryContent(path.value);
|
|
111
|
+
} else {
|
|
112
|
+
queryBuilder = queryContent();
|
|
113
|
+
}
|
|
114
|
+
if (only.value) {
|
|
115
|
+
queryBuilder = queryBuilder.only(only.value);
|
|
116
|
+
}
|
|
117
|
+
if (without.value) {
|
|
118
|
+
queryBuilder = queryBuilder.without(without.value);
|
|
119
|
+
}
|
|
120
|
+
if (where.value) {
|
|
121
|
+
queryBuilder = queryBuilder.where(where.value);
|
|
122
|
+
}
|
|
123
|
+
if (sort.value) {
|
|
124
|
+
queryBuilder = queryBuilder.sort(sort.value);
|
|
125
|
+
}
|
|
126
|
+
if (limit.value) {
|
|
127
|
+
queryBuilder = queryBuilder.limit(limit.value);
|
|
128
|
+
}
|
|
129
|
+
if (skip.value) {
|
|
130
|
+
queryBuilder = queryBuilder.skip(skip.value);
|
|
131
|
+
}
|
|
132
|
+
if (locale.value) {
|
|
133
|
+
queryBuilder = queryBuilder.where({ _locale: locale.value });
|
|
134
|
+
}
|
|
135
|
+
if (find.value === "one") {
|
|
136
|
+
return queryBuilder.findOne().then(resolveResult);
|
|
137
|
+
}
|
|
138
|
+
if (find.value === "surround") {
|
|
139
|
+
if (!path.value) {
|
|
140
|
+
console.warn("[Content] Surround queries requires `path` prop to be set.");
|
|
141
|
+
console.warn("[Content] Query without `path` will return regular `find()` results.");
|
|
142
|
+
return queryBuilder.find().then(resolveResult);
|
|
143
|
+
}
|
|
144
|
+
if (legacy) {
|
|
145
|
+
return queryBuilder.findSurround(path.value);
|
|
146
|
+
} else {
|
|
147
|
+
return queryBuilder.withSurround(path.value).findOne().then(resolveResult);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return queryBuilder.find().then(resolveResult);
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
return {
|
|
154
|
+
isPartial,
|
|
155
|
+
data,
|
|
156
|
+
refresh
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
/**
|
|
160
|
+
* Content not found fallback
|
|
161
|
+
* @slot not-found
|
|
162
|
+
*/
|
|
163
|
+
render(ctx) {
|
|
164
|
+
const slots = useSlots();
|
|
165
|
+
const {
|
|
166
|
+
// Setup
|
|
167
|
+
data,
|
|
168
|
+
refresh,
|
|
169
|
+
isPartial,
|
|
170
|
+
// Props
|
|
171
|
+
path,
|
|
172
|
+
only,
|
|
173
|
+
without,
|
|
174
|
+
where,
|
|
175
|
+
sort,
|
|
176
|
+
limit,
|
|
177
|
+
skip,
|
|
178
|
+
locale,
|
|
179
|
+
find
|
|
180
|
+
} = ctx;
|
|
181
|
+
const props = {
|
|
182
|
+
path,
|
|
183
|
+
only,
|
|
184
|
+
without,
|
|
185
|
+
where,
|
|
186
|
+
sort,
|
|
187
|
+
limit,
|
|
188
|
+
skip,
|
|
189
|
+
locale,
|
|
190
|
+
find
|
|
191
|
+
};
|
|
192
|
+
if (props.find === "one") {
|
|
193
|
+
if (!data && slots?.["not-found"]) {
|
|
194
|
+
return slots["not-found"]({ props, ...this.$attrs });
|
|
195
|
+
}
|
|
196
|
+
if (slots?.empty && data?._type === "markdown" && !data?.body?.children.length) {
|
|
197
|
+
return slots.empty({ props, ...this.$attrs });
|
|
198
|
+
}
|
|
199
|
+
} else if (!data || !data.length) {
|
|
200
|
+
if (slots?.["not-found"]) {
|
|
201
|
+
return slots["not-found"]({ props, ...this.$attrs });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (slots?.default) {
|
|
205
|
+
return slots.default({ data, refresh, isPartial, props, ...this.$attrs });
|
|
206
|
+
}
|
|
207
|
+
const emptyNode = (slot, data2) => h("pre", null, JSON.stringify({ message: "You should use slots with <ContentQuery>!", slot, data: data2 }, null, 2));
|
|
208
|
+
return emptyNode("default", { data, props, isPartial });
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
export default ContentQuery;
|
|
212
|
+
</script>
|
|
File without changes
|