nuxtseo-shared 5.3.12 → 5.3.13

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.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Contract for `#nuxtseo/content`, the per-provider runtime shim that
3
+ * `setupContentRuntime()` aliases into the Nitro bundle.
4
+ *
5
+ * `@nuxt/content` and `comark-content` cannot both be imported by one build:
6
+ * pulling `@nuxt/content/server` into an app that does not have it fails the
7
+ * bundle. So provider choice is a build-time alias, and every consumer imports
8
+ * this one specifier instead of naming a package.
9
+ */
10
+ type ContentRuntimeProvider = 'nuxt-content-v3' | 'comark' | 'none';
11
+ /**
12
+ * A queryable page collection, normalized across providers.
13
+ *
14
+ * The two manifests disagree in shape. `@nuxt/content` keys an object by name and
15
+ * carries a schema-derived `fields` map. comark returns an array and carries a
16
+ * per-collection sitemap flag. Both reduce to this.
17
+ */
18
+ interface PageCollection {
19
+ name: string;
20
+ /**
21
+ * Whether the collection declares `field`.
22
+ *
23
+ * For `@nuxt/content` this is the schema opt in, so a module can require its own
24
+ * field before claiming the collection. comark derives no field list from a
25
+ * schema, so it answers `true` and relies on frontmatter being present or absent.
26
+ */
27
+ hasField: (field: string) => boolean;
28
+ /** `false` only when the collection opted out of the sitemap. */
29
+ inSitemap: boolean;
30
+ }
31
+ interface ContentPageQuery {
32
+ where: (field: string, operator: string, value?: unknown) => ContentPageQuery;
33
+ select: (...fields: string[]) => ContentPageQuery;
34
+ all: () => Promise<Record<string, any>[]>;
35
+ first: () => Promise<Record<string, any> | null>;
36
+ }
37
+ interface ContentRuntime {
38
+ provider: ContentRuntimeProvider;
39
+ listPageCollections: (event: unknown) => Promise<PageCollection[]>;
40
+ queryPages: (event: unknown, collection: string) => ContentPageQuery;
41
+ }
42
+
43
+ export type { ContentPageQuery, ContentRuntime, ContentRuntimeProvider, PageCollection };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Contract for `#nuxtseo/content`, the per-provider runtime shim that
3
+ * `setupContentRuntime()` aliases into the Nitro bundle.
4
+ *
5
+ * `@nuxt/content` and `comark-content` cannot both be imported by one build:
6
+ * pulling `@nuxt/content/server` into an app that does not have it fails the
7
+ * bundle. So provider choice is a build-time alias, and every consumer imports
8
+ * this one specifier instead of naming a package.
9
+ */
10
+ type ContentRuntimeProvider = 'nuxt-content-v3' | 'comark' | 'none';
11
+ /**
12
+ * A queryable page collection, normalized across providers.
13
+ *
14
+ * The two manifests disagree in shape. `@nuxt/content` keys an object by name and
15
+ * carries a schema-derived `fields` map. comark returns an array and carries a
16
+ * per-collection sitemap flag. Both reduce to this.
17
+ */
18
+ interface PageCollection {
19
+ name: string;
20
+ /**
21
+ * Whether the collection declares `field`.
22
+ *
23
+ * For `@nuxt/content` this is the schema opt in, so a module can require its own
24
+ * field before claiming the collection. comark derives no field list from a
25
+ * schema, so it answers `true` and relies on frontmatter being present or absent.
26
+ */
27
+ hasField: (field: string) => boolean;
28
+ /** `false` only when the collection opted out of the sitemap. */
29
+ inSitemap: boolean;
30
+ }
31
+ interface ContentPageQuery {
32
+ where: (field: string, operator: string, value?: unknown) => ContentPageQuery;
33
+ select: (...fields: string[]) => ContentPageQuery;
34
+ all: () => Promise<Record<string, any>[]>;
35
+ first: () => Promise<Record<string, any> | null>;
36
+ }
37
+ interface ContentRuntime {
38
+ provider: ContentRuntimeProvider;
39
+ listPageCollections: (event: unknown) => Promise<PageCollection[]>;
40
+ queryPages: (event: unknown, collection: string) => ContentPageQuery;
41
+ }
42
+
43
+ export type { ContentPageQuery, ContentRuntime, ContentRuntimeProvider, PageCollection };
@@ -0,0 +1 @@
1
+
package/dist/devtools.mjs CHANGED
@@ -177,14 +177,13 @@ function generateAndBuild(cacheDir, rootDir, installed, hooks) {
177
177
  const routes = ["/", ...installed.flatMap((m) => deriveRoutes(m.layerDir, m.slug))];
178
178
  const extendsList = [resolveBaseLayer(installed), ...installed.map((m) => m.layerDir)];
179
179
  mkdirSync(join(cacheDir, "pages"), { recursive: true });
180
- writeFileSync(join(cacheDir, "nuxt.config.ts"), `import { resolve } from 'pathe'
181
- export default defineNuxtConfig({
180
+ writeFileSync(join(cacheDir, "nuxt.config.ts"), `export default defineNuxtConfig({
182
181
  extends: ${JSON.stringify(extendsList, null, 2)},
183
182
  ssr: false,
184
183
  robots: false,
185
184
  content: false,
186
185
  sitemap: false,
187
- nitro: { prerender: { routes: ${JSON.stringify(routes)} }, output: { publicDir: resolve(__dirname, './dist/devtools') } },
186
+ nitro: { prerender: { routes: ${JSON.stringify(routes)} }, output: { publicDir: ${JSON.stringify(join(cacheDir, "dist/devtools"))} } },
188
187
  app: { baseURL: '${UNIFIED_CLIENT_ROUTE}' },
189
188
  compatibilityDate: '2026-03-13',
190
189
  })
package/dist/kit.d.mts CHANGED
@@ -97,6 +97,47 @@ type UnheadMajor = 2 | 3;
97
97
  * that ships both majors can use this to alias to the matching one.
98
98
  */
99
99
  declare function resolveHostUnheadMajor(rootDir: string): Promise<UnheadMajor>;
100
+ declare const COMARK_CONTENT_MODULE = "@harlan-zw/comark-content";
101
+ /**
102
+ * The Markdown content module backing this app, if any.
103
+ *
104
+ * `@nuxt/content` and `comark-content` both fire the `content:file:beforeParse`
105
+ * and `content:file:afterParse` build hooks with the same context shape, so a
106
+ * module's frontmatter handling is written once. They differ at runtime:
107
+ * `@nuxt/content` queries a SQL database, comark reads Nitro server assets.
108
+ */
109
+ type ContentProvider = {
110
+ _tag: 'None';
111
+ } | {
112
+ _tag: 'NuxtContent';
113
+ version: 2 | 3;
114
+ } | {
115
+ _tag: 'Comark';
116
+ };
117
+ /**
118
+ * Detect which Markdown content module is installed.
119
+ *
120
+ * `@nuxt/content` wins when both are present: it owns the `content` config key
121
+ * and its runtime is the one the app's pages query.
122
+ */
123
+ declare function resolveContentProvider(nuxt?: Nuxt): Promise<ContentProvider>;
124
+ /**
125
+ * Whether the provider fires the `content:file:*` build hooks, which is where
126
+ * every module maps its frontmatter field onto the parsed page.
127
+ */
128
+ declare function hasContentFileHooks(provider: ContentProvider): boolean;
129
+ /**
130
+ * Alias `#nuxtseo/content` to the shim for the detected provider.
131
+ *
132
+ * Consumers import collection enumeration and page queries from that one
133
+ * specifier instead of naming `@nuxt/content/server` or
134
+ * `@harlan-zw/comark-content/server`. Naming a package directly would put it in
135
+ * every build, and a build without that package installed fails to bundle.
136
+ *
137
+ * Nuxt Content v2 has no collection model, so it resolves to the empty shim.
138
+ * A module that supports v2 keeps its own v2 path.
139
+ */
140
+ declare function setupContentRuntime(provider: ContentProvider, nuxt?: Nuxt): void;
100
141
 
101
- export { createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, renderNitroTypeAugmentations, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, setupNitroRuntimeCompatibility, useModuleLogger };
102
- export type { NitroRuntimeCompatibility, NitroTypeAugmentations, NuxtContentVersion, NuxtSeoModuleDetection, UnheadMajor };
142
+ export { COMARK_CONTENT_MODULE, createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, hasContentFileHooks, isNuxtGenerate, renderNitroTypeAugmentations, resolveContentProvider, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, setupContentRuntime, setupNitroRuntimeCompatibility, useModuleLogger };
143
+ export type { ContentProvider, NitroRuntimeCompatibility, NitroTypeAugmentations, NuxtContentVersion, NuxtSeoModuleDetection, UnheadMajor };
package/dist/kit.d.ts CHANGED
@@ -97,6 +97,47 @@ type UnheadMajor = 2 | 3;
97
97
  * that ships both majors can use this to alias to the matching one.
98
98
  */
99
99
  declare function resolveHostUnheadMajor(rootDir: string): Promise<UnheadMajor>;
100
+ declare const COMARK_CONTENT_MODULE = "@harlan-zw/comark-content";
101
+ /**
102
+ * The Markdown content module backing this app, if any.
103
+ *
104
+ * `@nuxt/content` and `comark-content` both fire the `content:file:beforeParse`
105
+ * and `content:file:afterParse` build hooks with the same context shape, so a
106
+ * module's frontmatter handling is written once. They differ at runtime:
107
+ * `@nuxt/content` queries a SQL database, comark reads Nitro server assets.
108
+ */
109
+ type ContentProvider = {
110
+ _tag: 'None';
111
+ } | {
112
+ _tag: 'NuxtContent';
113
+ version: 2 | 3;
114
+ } | {
115
+ _tag: 'Comark';
116
+ };
117
+ /**
118
+ * Detect which Markdown content module is installed.
119
+ *
120
+ * `@nuxt/content` wins when both are present: it owns the `content` config key
121
+ * and its runtime is the one the app's pages query.
122
+ */
123
+ declare function resolveContentProvider(nuxt?: Nuxt): Promise<ContentProvider>;
124
+ /**
125
+ * Whether the provider fires the `content:file:*` build hooks, which is where
126
+ * every module maps its frontmatter field onto the parsed page.
127
+ */
128
+ declare function hasContentFileHooks(provider: ContentProvider): boolean;
129
+ /**
130
+ * Alias `#nuxtseo/content` to the shim for the detected provider.
131
+ *
132
+ * Consumers import collection enumeration and page queries from that one
133
+ * specifier instead of naming `@nuxt/content/server` or
134
+ * `@harlan-zw/comark-content/server`. Naming a package directly would put it in
135
+ * every build, and a build without that package installed fails to bundle.
136
+ *
137
+ * Nuxt Content v2 has no collection model, so it resolves to the empty shim.
138
+ * A module that supports v2 keeps its own v2 path.
139
+ */
140
+ declare function setupContentRuntime(provider: ContentProvider, nuxt?: Nuxt): void;
100
141
 
101
- export { createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, renderNitroTypeAugmentations, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, setupNitroRuntimeCompatibility, useModuleLogger };
102
- export type { NitroRuntimeCompatibility, NitroTypeAugmentations, NuxtContentVersion, NuxtSeoModuleDetection, UnheadMajor };
142
+ export { COMARK_CONTENT_MODULE, createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, hasContentFileHooks, isNuxtGenerate, renderNitroTypeAugmentations, resolveContentProvider, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, setupContentRuntime, setupNitroRuntimeCompatibility, useModuleLogger };
143
+ export type { ContentProvider, NitroRuntimeCompatibility, NitroTypeAugmentations, NuxtContentVersion, NuxtSeoModuleDetection, UnheadMajor };
package/dist/kit.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { pathToFileURL } from 'node:url';
2
- import { getNuxtVersion, addTypeTemplate, useNuxt, useLogger, resolveModule, directoryToURL, createResolver, addTemplate, loadNuxtModuleInstance, tryUseNuxt, hasNuxtModule, hasNuxtModuleCompatibility } from '@nuxt/kit';
2
+ import { getNuxtVersion, addTypeTemplate, useNuxt, useLogger, resolveModule, directoryToURL, createResolver, addTemplate, loadNuxtModuleInstance, hasNuxtModule, tryUseNuxt, hasNuxtModuleCompatibility } from '@nuxt/kit';
3
3
  import { relative, dirname } from 'pathe';
4
4
  import { resolvePackageJSON, readPackageJSON } from 'pkg-types';
5
5
  import { provider, env } from 'std-env';
@@ -356,5 +356,41 @@ async function resolveHostUnheadMajor(rootDir) {
356
356
  }
357
357
  return 3;
358
358
  }
359
+ const COMARK_CONTENT_MODULE = "@harlan-zw/comark-content";
360
+ const COMARK_CONTENT_MINIMUM = [0, 1, 2];
361
+ async function comarkSatisfiesMinimum(nuxt) {
362
+ const pkg = await readPackageJSON(COMARK_CONTENT_MODULE, { url: normalizePackageUrl(nuxt.options.rootDir) }).catch(() => {
363
+ return null;
364
+ });
365
+ const parts = pkg?.version?.split(".").map((part) => Number.parseInt(part, 10));
366
+ if (!parts || parts.length < 3 || parts.some((part) => !Number.isFinite(part)))
367
+ return false;
368
+ for (const [index, minimum] of COMARK_CONTENT_MINIMUM.entries()) {
369
+ if (parts[index] !== minimum)
370
+ return parts[index] > minimum;
371
+ }
372
+ return true;
373
+ }
374
+ async function resolveContentProvider(nuxt = useNuxt()) {
375
+ const nuxtContent = await resolveNuxtContentVersion();
376
+ if (nuxtContent)
377
+ return { _tag: "NuxtContent", version: nuxtContent.version };
378
+ if (hasNuxtModule(COMARK_CONTENT_MODULE, nuxt) && await comarkSatisfiesMinimum(nuxt))
379
+ return { _tag: "Comark" };
380
+ return { _tag: "None" };
381
+ }
382
+ function hasContentFileHooks(provider2) {
383
+ return provider2._tag === "Comark" || provider2._tag === "NuxtContent" && provider2.version === 3;
384
+ }
385
+ function setupContentRuntime(provider2, nuxt = useNuxt()) {
386
+ const shim = provider2._tag === "Comark" ? "comark" : provider2._tag === "NuxtContent" && provider2.version === 3 ? "nuxt-content-v3" : "none";
387
+ const resolver = createResolver(import.meta.url);
388
+ const nitro = nuxt.options.nitro ??= {};
389
+ nitro.alias ??= {};
390
+ nitro.alias["#nuxtseo/content"] = resolver.resolve(`./runtime/content/${shim}`);
391
+ nitro.externals ??= {};
392
+ nitro.externals.inline ??= [];
393
+ nitro.externals.inline.push(resolver.resolve("./runtime/content/"));
394
+ }
359
395
 
360
- export { createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, renderNitroTypeAugmentations, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, setupNitroRuntimeCompatibility, useModuleLogger };
396
+ export { COMARK_CONTENT_MODULE, createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, hasContentFileHooks, isNuxtGenerate, renderNitroTypeAugmentations, resolveContentProvider, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, setupContentRuntime, setupNitroRuntimeCompatibility, useModuleLogger };
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "5.3.12",
7
+ "version": "5.3.13",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
File without changes
@@ -0,0 +1,42 @@
1
+ import { queryCollection, queryCollectionManifest } from "@harlan-zw/comark-content/server";
2
+ export const provider = "comark";
3
+ export async function listPageCollections(event) {
4
+ const manifest = await queryCollectionManifest(event);
5
+ return manifest.map((entry) => ({
6
+ name: entry.name,
7
+ // comark derives no field list from a schema, so every field is available to ask
8
+ // for. A collection opts out of the sitemap on the collection itself.
9
+ hasField: () => true,
10
+ inSitemap: entry.sitemap
11
+ }));
12
+ }
13
+ export function queryPages(event, collection) {
14
+ const wheres = [];
15
+ let selected;
16
+ const query = {
17
+ where(field, operator, value) {
18
+ wheres.push([field, operator, value]);
19
+ return query;
20
+ },
21
+ select(...fields) {
22
+ selected = fields;
23
+ return query;
24
+ },
25
+ async all() {
26
+ const notNull = wheres.filter(([, operator]) => operator === "IS NOT NULL").map(([field]) => field);
27
+ const builder = queryCollection(event, collection);
28
+ for (const [field, operator, value] of wheres) {
29
+ if (operator !== "IS NOT NULL")
30
+ builder.where(field, operator, value);
31
+ }
32
+ if (selected)
33
+ builder.select(.../* @__PURE__ */ new Set([...selected, ...notNull]));
34
+ const rows = await builder.all();
35
+ return rows.filter((row) => notNull.every((field) => row[field] !== null && row[field] !== void 0));
36
+ },
37
+ async first() {
38
+ return (await query.all())[0] ?? null;
39
+ }
40
+ };
41
+ return query;
42
+ }
File without changes
@@ -0,0 +1,7 @@
1
+ export const provider = "none";
2
+ export async function listPageCollections(_event) {
3
+ return [];
4
+ }
5
+ export function queryPages(_event, collection) {
6
+ throw new Error(`No content module is installed, so collection "${collection}" cannot be queried.`);
7
+ }
File without changes
@@ -0,0 +1,15 @@
1
+ import { queryCollection } from "@nuxt/content/server";
2
+ import manifest from "#content/manifest";
3
+ export const provider = "nuxt-content-v3";
4
+ export async function listPageCollections(_event) {
5
+ return Object.entries(manifest).map(([name, entry]) => ({
6
+ name,
7
+ hasField: (field) => !!entry.fields && field in entry.fields,
8
+ // @nuxt/content has no collection level sitemap opt out. The schema field is
9
+ // the opt in, which `hasField` answers.
10
+ inSitemap: true
11
+ }));
12
+ }
13
+ export function queryPages(event, collection) {
14
+ return queryCollection(event, collection);
15
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxtseo-shared",
3
3
  "type": "module",
4
- "version": "5.3.12",
4
+ "version": "5.3.13",
5
5
  "description": "Shared utilities for Nuxt SEO modules.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -28,6 +28,10 @@
28
28
  "types": "./dist/content.d.mts",
29
29
  "default": "./dist/content.mjs"
30
30
  },
31
+ "./content-runtime": {
32
+ "types": "./dist/content-runtime.d.mts",
33
+ "default": "./dist/content-runtime.mjs"
34
+ },
31
35
  "./kit": {
32
36
  "types": "./dist/kit.d.mts",
33
37
  "default": "./dist/kit.mjs"
@@ -100,6 +104,8 @@
100
104
  },
101
105
  "devDependencies": {
102
106
  "@arethetypeswrong/cli": "^0.18.5",
107
+ "@harlan-zw/comark-content": "^0.1.3",
108
+ "@nuxt/content": "^3.15.2",
103
109
  "@nuxt/module-builder": "^1.0.3",
104
110
  "@nuxt/schema": "^4.5.2",
105
111
  "@nuxt/test-utils": "^4.1.0",
@@ -107,7 +113,7 @@
107
113
  "h3": "^1.15.11",
108
114
  "nitropack": "^2.13.4",
109
115
  "nuxt": "^4.5.2",
110
- "nuxt-site-config": "^4.2.0",
116
+ "nuxt-site-config": "^4.2.2",
111
117
  "typescript": "6.0.3",
112
118
  "vitest": "^4.1.10",
113
119
  "vue": "^3.5.41",