@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.
Files changed (146) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -0
  3. package/dist/module.d.mts +1176 -0
  4. package/dist/module.json +12 -0
  5. package/dist/module.mjs +696 -0
  6. package/dist/runtime/app.vue +3 -0
  7. package/dist/runtime/app.vue.d.ts +2 -0
  8. package/dist/runtime/components/ContentDoc.vue +108 -0
  9. package/dist/runtime/components/ContentDoc.vue.d.ts +118 -0
  10. package/dist/runtime/components/ContentList.vue +59 -0
  11. package/dist/runtime/components/ContentList.vue.d.ts +59 -0
  12. package/dist/runtime/components/ContentNavigation.vue +61 -0
  13. package/dist/runtime/components/ContentNavigation.vue.d.ts +35 -0
  14. package/dist/runtime/components/ContentQuery.vue +212 -0
  15. package/dist/runtime/components/ContentQuery.vue.d.ts +0 -0
  16. package/dist/runtime/components/ContentRenderer.vue +78 -0
  17. package/dist/runtime/components/ContentRenderer.vue.d.ts +56 -0
  18. package/dist/runtime/components/ContentRendererMarkdown.vue +69 -0
  19. package/dist/runtime/components/ContentRendererMarkdown.vue.d.ts +73 -0
  20. package/dist/runtime/components/ContentSlot.vue +25 -0
  21. package/dist/runtime/components/ContentSlot.vue.d.ts +37 -0
  22. package/dist/runtime/components/DocumentDrivenEmpty.vue +18 -0
  23. package/dist/runtime/components/DocumentDrivenEmpty.vue.d.ts +17 -0
  24. package/dist/runtime/components/DocumentDrivenNotFound.vue +9 -0
  25. package/dist/runtime/components/DocumentDrivenNotFound.vue.d.ts +5 -0
  26. package/dist/runtime/components/Markdown.vue +29 -0
  27. package/dist/runtime/components/Markdown.vue.d.ts +31 -0
  28. package/dist/runtime/components/Prose/ProseCode.vue +32 -0
  29. package/dist/runtime/components/Prose/ProseCode.vue.d.ts +110 -0
  30. package/dist/runtime/components/Prose/ProseCodeInline.vue +3 -0
  31. package/dist/runtime/components/Prose/ProseCodeInline.vue.d.ts +14 -0
  32. package/dist/runtime/components/Prose/ProsePre.vue +42 -0
  33. package/dist/runtime/components/Prose/ProsePre.vue.d.ts +146 -0
  34. package/dist/runtime/composables/client-db.d.ts +14 -0
  35. package/dist/runtime/composables/client-db.js +105 -0
  36. package/dist/runtime/composables/content.d.ts +19 -0
  37. package/dist/runtime/composables/content.js +41 -0
  38. package/dist/runtime/composables/head.d.ts +4 -0
  39. package/dist/runtime/composables/head.js +94 -0
  40. package/dist/runtime/composables/helpers.d.ts +7 -0
  41. package/dist/runtime/composables/helpers.js +66 -0
  42. package/dist/runtime/composables/navigation.d.ts +2 -0
  43. package/dist/runtime/composables/navigation.js +34 -0
  44. package/dist/runtime/composables/preview.d.ts +5 -0
  45. package/dist/runtime/composables/preview.js +41 -0
  46. package/dist/runtime/composables/query.d.ts +10 -0
  47. package/dist/runtime/composables/query.js +64 -0
  48. package/dist/runtime/composables/search.d.ts +130 -0
  49. package/dist/runtime/composables/search.js +59 -0
  50. package/dist/runtime/composables/useUnwrap.d.ts +5 -0
  51. package/dist/runtime/composables/useUnwrap.js +5 -0
  52. package/dist/runtime/composables/utils.d.ts +6 -0
  53. package/dist/runtime/composables/utils.js +36 -0
  54. package/dist/runtime/composables/web-socket.d.ts +3 -0
  55. package/dist/runtime/composables/web-socket.js +65 -0
  56. package/dist/runtime/legacy/composables/client-db.d.ts +12 -0
  57. package/dist/runtime/legacy/composables/client-db.js +105 -0
  58. package/dist/runtime/legacy/composables/navigation.d.ts +2 -0
  59. package/dist/runtime/legacy/composables/navigation.js +34 -0
  60. package/dist/runtime/legacy/composables/query.d.ts +10 -0
  61. package/dist/runtime/legacy/composables/query.js +61 -0
  62. package/dist/runtime/legacy/plugins/documentDriven.d.ts +2 -0
  63. package/dist/runtime/legacy/plugins/documentDriven.js +231 -0
  64. package/dist/runtime/legacy/server.d.ts +3 -0
  65. package/dist/runtime/legacy/server.js +3 -0
  66. package/dist/runtime/legacy/types.d.ts +5 -0
  67. package/dist/runtime/pages/document-driven.vue +27 -0
  68. package/dist/runtime/pages/document-driven.vue.d.ts +2 -0
  69. package/dist/runtime/plugins/documentDriven.d.ts +2 -0
  70. package/dist/runtime/plugins/documentDriven.js +222 -0
  71. package/dist/runtime/plugins/ws.d.ts +2 -0
  72. package/dist/runtime/plugins/ws.js +7 -0
  73. package/dist/runtime/query/match/index.d.ts +6 -0
  74. package/dist/runtime/query/match/index.js +123 -0
  75. package/dist/runtime/query/match/pipeline-legacy.d.ts +2 -0
  76. package/dist/runtime/query/match/pipeline-legacy.js +22 -0
  77. package/dist/runtime/query/match/pipeline.d.ts +2 -0
  78. package/dist/runtime/query/match/pipeline.js +104 -0
  79. package/dist/runtime/query/match/utils.d.ts +35 -0
  80. package/dist/runtime/query/match/utils.js +65 -0
  81. package/dist/runtime/query/query.d.ts +12 -0
  82. package/dist/runtime/query/query.js +61 -0
  83. package/dist/runtime/server/api/cache.d.ts +7 -0
  84. package/dist/runtime/server/api/cache.js +18 -0
  85. package/dist/runtime/server/api/navigation-qid-params.d.ts +1 -0
  86. package/dist/runtime/server/api/navigation-qid-params.js +1 -0
  87. package/dist/runtime/server/api/navigation-qid.d.ts +1 -0
  88. package/dist/runtime/server/api/navigation-qid.js +1 -0
  89. package/dist/runtime/server/api/navigation.d.ts +2 -0
  90. package/dist/runtime/server/api/navigation.js +42 -0
  91. package/dist/runtime/server/api/query-qid-params.d.ts +1 -0
  92. package/dist/runtime/server/api/query-qid-params.js +1 -0
  93. package/dist/runtime/server/api/query-qid.d.ts +1 -0
  94. package/dist/runtime/server/api/query-qid.js +1 -0
  95. package/dist/runtime/server/api/query.d.ts +2 -0
  96. package/dist/runtime/server/api/query.js +32 -0
  97. package/dist/runtime/server/api/search.d.ts +8 -0
  98. package/dist/runtime/server/api/search.js +16 -0
  99. package/dist/runtime/server/content-index.d.ts +4 -0
  100. package/dist/runtime/server/content-index.js +37 -0
  101. package/dist/runtime/server/index.d.ts +1 -0
  102. package/dist/runtime/server/index.js +1 -0
  103. package/dist/runtime/server/navigation.d.ts +5 -0
  104. package/dist/runtime/server/navigation.js +96 -0
  105. package/dist/runtime/server/plugins/refresh-cache.d.ts +2 -0
  106. package/dist/runtime/server/plugins/refresh-cache.js +15 -0
  107. package/dist/runtime/server/preview.d.ts +5 -0
  108. package/dist/runtime/server/preview.js +9 -0
  109. package/dist/runtime/server/search.d.ts +14 -0
  110. package/dist/runtime/server/search.js +70 -0
  111. package/dist/runtime/server/storage.d.ts +35 -0
  112. package/dist/runtime/server/storage.js +238 -0
  113. package/dist/runtime/transformers/component-resolver.d.ts +2 -0
  114. package/dist/runtime/transformers/component-resolver.js +44 -0
  115. package/dist/runtime/transformers/csv/create-tokenizer.d.ts +39 -0
  116. package/dist/runtime/transformers/csv/create-tokenizer.js +307 -0
  117. package/dist/runtime/transformers/csv/from-csv.d.ts +13 -0
  118. package/dist/runtime/transformers/csv/from-csv.js +203 -0
  119. package/dist/runtime/transformers/csv/index.d.ts +2 -0
  120. package/dist/runtime/transformers/csv/index.js +50 -0
  121. package/dist/runtime/transformers/csv/parser.d.ts +24 -0
  122. package/dist/runtime/transformers/csv/parser.js +154 -0
  123. package/dist/runtime/transformers/index.d.ts +7 -0
  124. package/dist/runtime/transformers/index.js +50 -0
  125. package/dist/runtime/transformers/json.d.ts +2 -0
  126. package/dist/runtime/transformers/json.js +29 -0
  127. package/dist/runtime/transformers/markdown.d.ts +2 -0
  128. package/dist/runtime/transformers/markdown.js +88 -0
  129. package/dist/runtime/transformers/path-meta.d.ts +27 -0
  130. package/dist/runtime/transformers/path-meta.js +59 -0
  131. package/dist/runtime/transformers/utils.d.ts +3 -0
  132. package/dist/runtime/transformers/utils.js +12 -0
  133. package/dist/runtime/transformers/yaml.d.ts +2 -0
  134. package/dist/runtime/transformers/yaml.js +21 -0
  135. package/dist/runtime/utils/config.d.ts +4 -0
  136. package/dist/runtime/utils/config.js +7 -0
  137. package/dist/runtime/utils/html-tags.d.ts +2 -0
  138. package/dist/runtime/utils/html-tags.js +119 -0
  139. package/dist/runtime/utils/json.d.ts +10 -0
  140. package/dist/runtime/utils/json.js +20 -0
  141. package/dist/runtime/utils/query.d.ts +5 -0
  142. package/dist/runtime/utils/query.js +77 -0
  143. package/dist/runtime/virtual/transformers.d.ts +2 -0
  144. package/dist/types.d.mts +9 -0
  145. package/dist/web-types.json +572 -0
  146. package/package.json +111 -0
@@ -0,0 +1,70 @@
1
+ import { serverQueryContent } from "#content/server";
2
+ export async function serverSearchContent(event, filterQuery) {
3
+ if (filterQuery) {
4
+ return await serverQueryContent(event).where(filterQuery).find();
5
+ } else {
6
+ return await serverQueryContent(event).find();
7
+ }
8
+ }
9
+ const HEADING = /^h([1-6])$/;
10
+ const isHeading = (tag) => HEADING.test(tag);
11
+ export function splitPageIntoSections(page, { ignoredTags }) {
12
+ const path = page._path ?? "";
13
+ const sections = [{
14
+ id: path,
15
+ title: page.title || "",
16
+ titles: [],
17
+ content: (page.description || "").trim(),
18
+ level: 1
19
+ }];
20
+ if (!page?.body?.children) {
21
+ return sections;
22
+ }
23
+ let section = 1;
24
+ let previousHeadingLevel = 0;
25
+ const titles = [page.title ?? ""];
26
+ for (const item of page.body.children) {
27
+ const tag = item.tag || "";
28
+ if (isHeading(tag)) {
29
+ const currentHeadingLevel = Number(tag.match(HEADING)?.[1] ?? 0);
30
+ const title = extractTextFromAst(item).trim();
31
+ if (currentHeadingLevel === 1) {
32
+ titles.splice(0, titles.length);
33
+ } else if (currentHeadingLevel < previousHeadingLevel) {
34
+ titles.splice(currentHeadingLevel - 1, titles.length - 1);
35
+ } else if (currentHeadingLevel === previousHeadingLevel) {
36
+ titles.pop();
37
+ }
38
+ sections.push({
39
+ id: `${path}#${item.props?.id}`,
40
+ title,
41
+ titles: [...titles],
42
+ content: "",
43
+ level: currentHeadingLevel
44
+ });
45
+ titles.push(title);
46
+ previousHeadingLevel = currentHeadingLevel;
47
+ section += 1;
48
+ } else {
49
+ const content = extractTextFromAst(item, ignoredTags).trim();
50
+ if (section === 1 && sections[section - 1]?.content === content) {
51
+ continue;
52
+ }
53
+ sections[section - 1].content = `${sections[section - 1].content} ${content}`.trim();
54
+ }
55
+ }
56
+ return sections;
57
+ }
58
+ function extractTextFromAst(node, ignoredTags = []) {
59
+ let text = "";
60
+ if (node.type === "text") {
61
+ text += node.value || "";
62
+ }
63
+ if (ignoredTags.includes(node.tag ?? "")) {
64
+ return "";
65
+ }
66
+ if (node.children?.length) {
67
+ text += node.children.map((child) => extractTextFromAst(child, ignoredTags)).filter(Boolean).join("");
68
+ }
69
+ return text;
70
+ }
@@ -0,0 +1,35 @@
1
+ import { type StorageValue, type Storage } from 'unstorage';
2
+ import type { H3Event } from 'h3';
3
+ import type { ParsedContent, ContentTransformer, ContentQueryBuilder, ContentQueryBuilderParams, ModuleOptions } from '@nuxt/content';
4
+ interface ParseContentOptions {
5
+ csv?: ModuleOptions['csv'];
6
+ yaml?: ModuleOptions['yaml'];
7
+ highlight?: ModuleOptions['highlight'];
8
+ markdown?: ModuleOptions['markdown'];
9
+ transformers?: ContentTransformer[];
10
+ pathMeta?: {
11
+ locales?: ModuleOptions['locales'];
12
+ defaultLocale?: ModuleOptions['defaultLocale'];
13
+ respectPathCase?: ModuleOptions['respectPathCase'];
14
+ };
15
+ [key: string]: any;
16
+ }
17
+ export declare const sourceStorage: () => Storage<StorageValue>;
18
+ export declare const cacheStorage: () => Storage<StorageValue>;
19
+ export declare const cacheParsedStorage: () => Storage<StorageValue>;
20
+ export declare const getContentsIds: (event: H3Event, prefix?: string) => Promise<string[]>;
21
+ export declare function chunksFromArray<T>(arr: T[], n: number): Generator<T[], void>;
22
+ export declare const cleanCachedContents: () => void;
23
+ export declare const getContentsList: (event: H3Event, prefix?: string) => any;
24
+ export declare const getContent: (event: H3Event, id: string) => Promise<ParsedContent>;
25
+ /**
26
+ * Parse content file using registered plugins
27
+ */
28
+ export declare const parseContent: (id: string, content: StorageValue, opts?: ParseContentOptions) => Promise<any>;
29
+ export declare const createServerQueryFetch: <T = ParsedContent>(event: H3Event) => (query: ContentQueryBuilder<T>) => Promise<ContentQueryResponse<T_1>>;
30
+ /**
31
+ * Query contents
32
+ */
33
+ export declare function serverQueryContent<T = ParsedContent>(event: H3Event, params?: ContentQueryBuilderParams): ContentQueryBuilder<T>;
34
+ export declare function serverQueryContent<T = ParsedContent>(event: H3Event, query?: string, ...pathParts: string[]): ContentQueryBuilder<T>;
35
+ export {};
@@ -0,0 +1,238 @@
1
+ import { prefixStorage } from "unstorage";
2
+ import { joinURL, withLeadingSlash, withoutTrailingSlash } from "ufo";
3
+ import { hash as ohash } from "ohash";
4
+ import defu from "defu";
5
+ import { createQuery } from "../query/query.js";
6
+ import { transformContent } from "../transformers/index.js";
7
+ import { makeIgnored } from "../utils/config.js";
8
+ import { createPipelineFetcher } from "../query/match/pipeline.js";
9
+ import { getPreview, isPreview } from "./preview.js";
10
+ import { getIndexedContentsList } from "./content-index.js";
11
+ import { useNitroApp, useRuntimeConfig, useStorage } from "#imports";
12
+ import { transformers as customTransformers } from "#content/virtual/transformers";
13
+ let _sourceStorage;
14
+ let _cacheStorage;
15
+ let _cacheParsedStorage;
16
+ export const sourceStorage = () => {
17
+ if (!_sourceStorage) {
18
+ _sourceStorage = prefixStorage(useStorage(), "content:source");
19
+ }
20
+ return _sourceStorage;
21
+ };
22
+ export const cacheStorage = () => {
23
+ if (!_cacheStorage) {
24
+ _cacheStorage = prefixStorage(useStorage(), "cache:content");
25
+ }
26
+ return _cacheStorage;
27
+ };
28
+ export const cacheParsedStorage = () => {
29
+ if (!_cacheParsedStorage) {
30
+ _cacheParsedStorage = prefixStorage(useStorage(), "cache:content:parsed");
31
+ }
32
+ return _cacheParsedStorage;
33
+ };
34
+ const isProduction = process.env.NODE_ENV === "production";
35
+ const isPrerendering = import.meta.prerender;
36
+ const contentConfig = () => useRuntimeConfig().content;
37
+ const invalidKeyCharacters = `'"?#/`.split("");
38
+ const contentIgnorePredicate = (key) => {
39
+ const isIgnored = makeIgnored(contentConfig().ignores);
40
+ if (key.startsWith("preview:") || isIgnored(key)) {
41
+ return false;
42
+ }
43
+ if (invalidKeyCharacters.some((ik) => key.includes(ik))) {
44
+ console.warn(`Ignoring [${key}]. File name should not contain any of the following characters: ${invalidKeyCharacters.join(", ")}`);
45
+ return false;
46
+ }
47
+ return true;
48
+ };
49
+ export const getContentsIds = async (event, prefix) => {
50
+ let keys = [];
51
+ if (isProduction) {
52
+ keys = await cacheParsedStorage().getKeys(prefix);
53
+ }
54
+ const source = sourceStorage();
55
+ if (keys.length === 0) {
56
+ keys = await source.getKeys(prefix);
57
+ }
58
+ if (isPreview(event)) {
59
+ const { key } = getPreview(event);
60
+ const previewPrefix = `preview:${key}:${prefix || ""}`;
61
+ const previewKeys = await source.getKeys(previewPrefix);
62
+ if (previewKeys.length) {
63
+ const keysSet = new Set(keys);
64
+ await Promise.all(
65
+ previewKeys.map(async (key2) => {
66
+ const meta = await source.getMeta(key2);
67
+ if (meta?.__deleted) {
68
+ keysSet.delete(key2.substring(previewPrefix.length));
69
+ } else {
70
+ keysSet.add(key2.substring(previewPrefix.length));
71
+ }
72
+ })
73
+ );
74
+ keys = Array.from(keysSet);
75
+ }
76
+ }
77
+ return keys.filter(contentIgnorePredicate);
78
+ };
79
+ export function* chunksFromArray(arr, n) {
80
+ for (let i = 0; i < arr.length; i += n) {
81
+ yield arr.slice(i, i + n);
82
+ }
83
+ }
84
+ let cachedContents = [];
85
+ export const cleanCachedContents = () => {
86
+ cachedContents = [];
87
+ };
88
+ export const getContentsList = /* @__PURE__ */ (() => {
89
+ let pendingContentsListPromise = null;
90
+ const _getContentsList = async (event, prefix) => {
91
+ const keys = await getContentsIds(event, prefix);
92
+ const keyChunks = [...chunksFromArray(keys, 10)];
93
+ const contents = [];
94
+ for (const chunk of keyChunks) {
95
+ const result = await Promise.all(chunk.map((key) => getContent(event, key)));
96
+ contents.push(...result);
97
+ }
98
+ return contents.filter((c) => c && c._path);
99
+ };
100
+ return (event, prefix) => {
101
+ if (event.context.__contentList) {
102
+ return event.context.__contentList;
103
+ }
104
+ if ((isPrerendering || !isProduction) && cachedContents.length) {
105
+ return cachedContents;
106
+ }
107
+ if (!pendingContentsListPromise) {
108
+ pendingContentsListPromise = _getContentsList(event, prefix);
109
+ pendingContentsListPromise.then((result) => {
110
+ if (isPrerendering || !isProduction) {
111
+ cachedContents = result;
112
+ }
113
+ event.context.__contentList = result;
114
+ pendingContentsListPromise = null;
115
+ });
116
+ }
117
+ return pendingContentsListPromise;
118
+ };
119
+ })();
120
+ const pendingPromises = {};
121
+ export const getContent = async (event, id) => {
122
+ const contentId = id;
123
+ if (!contentIgnorePredicate(id)) {
124
+ return { _id: contentId, body: null };
125
+ }
126
+ const source = sourceStorage();
127
+ const cache = cacheParsedStorage();
128
+ if (isPreview(event)) {
129
+ const { key } = getPreview(event);
130
+ const previewId = `preview:${key}:${id}`;
131
+ const draft = await source.getItem(previewId);
132
+ if (draft) {
133
+ id = previewId;
134
+ }
135
+ }
136
+ const cached = await cache.getItem(id);
137
+ if (isProduction && cached) {
138
+ return cached.parsed;
139
+ }
140
+ const config = contentConfig();
141
+ const meta = await source.getMeta(id);
142
+ const mtime = meta.mtime;
143
+ const size = meta.size || 0;
144
+ const hash = ohash({
145
+ // Last modified time
146
+ mtime,
147
+ // File size
148
+ size,
149
+ // Add Content version to the hash, to revalidate the cache on content update
150
+ version: config.cacheVersion,
151
+ integrity: config.cacheIntegrity
152
+ });
153
+ if (cached?.hash === hash) {
154
+ return cached.parsed;
155
+ }
156
+ if (!pendingPromises[id + hash]) {
157
+ pendingPromises[id + hash] = new Promise(async (resolve) => {
158
+ const body = await source.getItem(id);
159
+ if (body === null) {
160
+ return resolve({ _id: contentId, body: null });
161
+ }
162
+ const parsed = await parseContent(contentId, body);
163
+ await cache.setItem(id, { parsed, hash }).catch(() => {
164
+ });
165
+ resolve(parsed);
166
+ delete pendingPromises[id + hash];
167
+ });
168
+ }
169
+ return pendingPromises[id + hash];
170
+ };
171
+ export const parseContent = async (id, content, opts = {}) => {
172
+ const nitroApp = useNitroApp();
173
+ const config = contentConfig();
174
+ const options = defu(
175
+ opts,
176
+ {
177
+ markdown: {
178
+ ...config.markdown,
179
+ highlight: config.highlight
180
+ },
181
+ csv: config.csv,
182
+ yaml: config.yaml,
183
+ transformers: customTransformers,
184
+ pathMeta: {
185
+ defaultLocale: config.defaultLocale,
186
+ locales: config.locales,
187
+ respectPathCase: config.respectPathCase
188
+ }
189
+ }
190
+ );
191
+ const file = { _id: id, body: typeof content === "string" ? content.replace(/\r\n|\r/g, "\n") : content };
192
+ await nitroApp.hooks.callHook("content:file:beforeParse", file);
193
+ const result = await transformContent(id, file.body, options);
194
+ await nitroApp.hooks.callHook("content:file:afterParse", result);
195
+ return result;
196
+ };
197
+ export const createServerQueryFetch = (event) => (query) => {
198
+ return createPipelineFetcher(() => getIndexedContentsList(event, query))(query);
199
+ };
200
+ export function serverQueryContent(event, query, ...pathParts) {
201
+ const { advanceQuery } = useRuntimeConfig().public.content.experimental;
202
+ const config = contentConfig();
203
+ const queryBuilder = advanceQuery ? createQuery(createServerQueryFetch(event), { initialParams: typeof query !== "string" ? query || {} : {}, legacy: false }) : createQuery(createServerQueryFetch(event), { initialParams: typeof query !== "string" ? query || {} : {}, legacy: true });
204
+ let path;
205
+ if (typeof query === "string") {
206
+ path = withLeadingSlash(joinURL(query, ...pathParts));
207
+ }
208
+ const originalParamsFn = queryBuilder.params;
209
+ queryBuilder.params = () => {
210
+ const params = originalParamsFn();
211
+ if (path) {
212
+ params.where = params.where || [];
213
+ if (params.first && (params.where || []).length === 0) {
214
+ params.where.push({ _path: withoutTrailingSlash(path) });
215
+ } else {
216
+ params.where.push({ _path: new RegExp(`^${path.replace(/[-[\]{}()*+.,^$\s/]/g, "\\$&")}`) });
217
+ }
218
+ }
219
+ if (!params.sort?.length) {
220
+ params.sort = [{ _stem: 1, $numeric: true }];
221
+ }
222
+ if (!import.meta.dev) {
223
+ params.where = params.where || [];
224
+ if (!params.where.find((item) => typeof item._draft !== "undefined")) {
225
+ params.where.push({ _draft: { $ne: true } });
226
+ }
227
+ }
228
+ if (config.locales.length) {
229
+ const queryLocale = params.where?.find((w) => w._locale)?._locale;
230
+ if (!queryLocale) {
231
+ params.where = params.where || [];
232
+ params.where.push({ _locale: config.defaultLocale });
233
+ }
234
+ }
235
+ return params;
236
+ };
237
+ return queryBuilder;
238
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: ContentTransformer;
2
+ export default _default;
@@ -0,0 +1,44 @@
1
+ import { pascalCase } from "scule";
2
+ import htmlTags from "../utils/html-tags.js";
3
+ import { defineTransformer } from "./utils.js";
4
+ async function resolveContentComponents(body, meta) {
5
+ const components = Array.from(new Set(loadComponents(body, meta)));
6
+ const manifest = await import("#build/content-components").catch(() => ({}));
7
+ const resolvedComponentsEntries = await Promise.all(components.map(async ([t, c]) => {
8
+ const componentImporter = c && manifest[pascalCase(c)];
9
+ if (typeof componentImporter === "function") {
10
+ return [t, await componentImporter()];
11
+ }
12
+ return [t, c];
13
+ }));
14
+ return Object.fromEntries(resolvedComponentsEntries);
15
+ function loadComponents(node, tags) {
16
+ if (node.type === "text" || node.tag === "binding") {
17
+ return [];
18
+ }
19
+ const renderTag = typeof node.props?.__ignoreMap === "undefined" && tags[node.tag] || node.tag;
20
+ const components2 = [];
21
+ if (node.type !== "root" && !htmlTags.includes(renderTag)) {
22
+ components2.push([node.tag, renderTag]);
23
+ }
24
+ for (const child of node.children || []) {
25
+ components2.push(...loadComponents(child, tags));
26
+ }
27
+ return components2;
28
+ }
29
+ }
30
+ export default defineTransformer({
31
+ name: "component-resolver",
32
+ extensions: [".*"],
33
+ async transform(content, options = {}) {
34
+ if (import.meta.server) {
35
+ return content;
36
+ }
37
+ const _components = await resolveContentComponents(content.body, {
38
+ ...options?.tags || {},
39
+ ...content._components || {}
40
+ });
41
+ content._components = _components;
42
+ return content;
43
+ }
44
+ });
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @typedef {import('micromark-util-types').Code} Code
3
+ * @typedef {import('micromark-util-types').Chunk} Chunk
4
+ * @typedef {import('micromark-util-types').Point} Point
5
+ * @typedef {import('micromark-util-types').Token} Token
6
+ * @typedef {import('micromark-util-types').Effects} Effects
7
+ * @typedef {import('micromark-util-types').State} State
8
+ * @typedef {import('micromark-util-types').Construct} Construct
9
+ * @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
10
+ * @typedef {import('micromark-util-types').ConstructRecord} ConstructRecord
11
+ * @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
12
+ * @typedef {import('micromark-util-types').ParseContext} ParseContext
13
+ */
14
+ /**
15
+ * Create a tokenizer.
16
+ * Tokenizers deal with one type of data (e.g., containers, flow, text).
17
+ * The parser is the object dealing with it all.
18
+ * `initialize` works like other constructs, except that only its `tokenize`
19
+ * function is used, in which case it doesn’t receive an `ok` or `nok`.
20
+ * `from` can be given to set the point before the first character, although
21
+ * when further lines are indented, they must be set with `defineSkip`.
22
+ *
23
+ * @param {ParseContext} parser
24
+ * @param {InitialConstruct} initialize
25
+ * @param {Omit<Point, '_index'|'_bufferIndex'>} [from]
26
+ * @returns {TokenizeContext}
27
+ */
28
+ export declare function createTokenizer(parser: any, initialize: any, from: any): {
29
+ previous: null;
30
+ code: null;
31
+ containerState: {};
32
+ events: never[];
33
+ parser: any;
34
+ sliceStream: (token: any) => any;
35
+ sliceSerialize: (token: any, expandTabs: any) => string;
36
+ now: () => any;
37
+ defineSkip: (value: any) => void;
38
+ write: (slice: any) => never[];
39
+ };