nuxt-schema-org 1.0.0-beta.2 → 1.0.0-beta.20
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/dist/module.d.ts +8 -16
- package/dist/module.json +2 -1
- package/dist/module.mjs +69 -35
- package/dist/runtime/plugin.mjs +13 -7
- package/package.json +11 -13
- package/dist/runtime/schema-org-runtime.d.ts +0 -3
- package/dist/runtime/schema-org-runtime.mjs +0 -8
package/dist/module.d.ts
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import { MetaInput } from 'schema-org-graph-js';
|
|
2
1
|
import { NuxtModule } from '@nuxt/schema';
|
|
2
|
+
import { UserConfig } from '@vueuse/schema-org';
|
|
3
|
+
import { MetaInput } from 'schema-org-graph-js';
|
|
3
4
|
|
|
4
|
-
interface ModuleOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Should schema.org only be rendered by the server.
|
|
7
|
-
*
|
|
8
|
-
* Useful for optimising performance as it may not be needed by search engines. Changes runtime package size to 0kb.
|
|
9
|
-
*
|
|
10
|
-
* @default false
|
|
11
|
-
*/
|
|
12
|
-
client?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Should full schema types from `schema-dts` be used over a simplified version.
|
|
15
|
-
* @default false
|
|
16
|
-
*/
|
|
17
|
-
full?: boolean;
|
|
18
|
-
meta?: MetaInput;
|
|
5
|
+
interface ModuleOptions extends UserConfig {
|
|
19
6
|
}
|
|
20
7
|
interface ModuleHooks {
|
|
21
8
|
}
|
|
9
|
+
declare module 'nuxt' {
|
|
10
|
+
interface RuntimeNuxtHooks {
|
|
11
|
+
'schema-org:meta': (meta: MetaInput) => void;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
22
14
|
declare const _default: NuxtModule<ModuleOptions>;
|
|
23
15
|
|
|
24
16
|
export { ModuleHooks, ModuleOptions, _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,64 +1,98 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addPlugin, addTemplate, addComponent } from '@nuxt/kit';
|
|
2
|
-
import {
|
|
1
|
+
import { defineNuxtModule, createResolver, addPlugin, addTemplate, addComponent, extendWebpackConfig } from '@nuxt/kit';
|
|
2
|
+
import { resolveUserConfig, AliasProvider, AliasRuntime, schemaOrgComponents, schemaOrgAutoImports } from '@vueuse/schema-org';
|
|
3
3
|
import { dirname } from 'pathe';
|
|
4
|
-
import {
|
|
4
|
+
import { AliasRuntimePluginVite, AliasRuntimePluginWebpack } from '@vueuse/schema-org-vite';
|
|
5
5
|
|
|
6
6
|
const Pkg = "@vueuse/schema-org";
|
|
7
|
-
const RuntimeDir = "#vueuse/schema-org/runtime";
|
|
8
7
|
const module = defineNuxtModule({
|
|
9
8
|
meta: {
|
|
10
9
|
configKey: "schemaOrg",
|
|
11
10
|
compatibility: {
|
|
11
|
+
nuxt: ">=3.0.0-rc.8",
|
|
12
12
|
bridge: false
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
async setup(moduleOptions, nuxt) {
|
|
16
16
|
const { resolve, resolvePath } = createResolver(import.meta.url);
|
|
17
|
+
moduleOptions = resolveUserConfig(moduleOptions);
|
|
18
|
+
if (nuxt.options.ssr && !moduleOptions.canonicalHost && !moduleOptions.meta?.host) {
|
|
19
|
+
console.warn("WARN [nuxt-schema-org] Please provide a `canonicalHost` to use this module with SSR enabled.");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
17
22
|
const schemaOrgPath = dirname(await resolvePath(Pkg));
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
if (!nuxt.options.ssr)
|
|
24
|
+
moduleOptions.client = true;
|
|
20
25
|
if (typeof moduleOptions.client === "undefined")
|
|
21
26
|
moduleOptions.client = !!nuxt.options.dev;
|
|
27
|
+
const providerPath = await resolvePath(`${schemaOrgPath}/providers/${moduleOptions.full ? "full" : "simple"}`);
|
|
28
|
+
const runtimePath = await resolvePath(`${schemaOrgPath}/runtime`);
|
|
29
|
+
const runtimeMockPath = await resolvePath(`${schemaOrgPath}/runtime-mock`);
|
|
30
|
+
nuxt.options.alias[AliasProvider] = providerPath;
|
|
31
|
+
nuxt.options.alias[AliasRuntime] = runtimePath;
|
|
32
|
+
nuxt.options.alias[Pkg] = schemaOrgPath;
|
|
33
|
+
const moduleRuntimeDir = resolve("./runtime");
|
|
34
|
+
nuxt.options.build.transpile.push(...[moduleRuntimeDir, AliasRuntime]);
|
|
22
35
|
if (!moduleOptions.client)
|
|
23
|
-
addPlugin(resolve(
|
|
36
|
+
addPlugin(resolve(moduleRuntimeDir, "plugin-fallback.client"));
|
|
24
37
|
addPlugin({
|
|
25
|
-
src: resolve(
|
|
38
|
+
src: resolve(moduleRuntimeDir, "plugin"),
|
|
26
39
|
mode: moduleOptions.client ? "all" : "server"
|
|
27
40
|
});
|
|
28
|
-
nuxt.options.alias[Pkg] = schemaOrgPath;
|
|
29
|
-
nuxt.options.alias["#vueuse/schema-org/provider"] = await resolvePath(`${schemaOrgPath}/providers/full`);
|
|
30
|
-
nuxt.options.alias["#vueuse/schema-org/runtime"] = await resolvePath(`${schemaOrgPath}/runtime`);
|
|
31
|
-
nuxt.hook("vite:extendConfig", (config, { isClient }) => {
|
|
32
|
-
config.optimizeDeps = config.optimizeDeps || {};
|
|
33
|
-
config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
|
|
34
|
-
config.optimizeDeps.exclude.push(...[`${schemaOrgPath}/runtime`, Pkg]);
|
|
35
|
-
config.plugins = config.plugins || [];
|
|
36
|
-
config.plugins.push(SchemaOrg({
|
|
37
|
-
mock: !moduleOptions.client && isClient,
|
|
38
|
-
full: moduleOptions.full
|
|
39
|
-
}));
|
|
40
|
-
});
|
|
41
41
|
addTemplate({
|
|
42
42
|
filename: "nuxt-schema-org-config.mjs",
|
|
43
43
|
getContents: () => `export default ${JSON.stringify(moduleOptions)}`
|
|
44
44
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
from: `${moduleRuntime}/schema-org-runtime`,
|
|
48
|
-
imports: [
|
|
49
|
-
"injectSchemaOrg",
|
|
50
|
-
"useSchemaOrg",
|
|
51
|
-
...RootSchemas.map((schema) => [`define${schema}`]).flat()
|
|
52
|
-
]
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
schemaOrgComponents.forEach((component) => {
|
|
56
|
-
addComponent({
|
|
45
|
+
for (const component of schemaOrgComponents) {
|
|
46
|
+
await addComponent({
|
|
57
47
|
name: component,
|
|
58
48
|
export: component,
|
|
59
|
-
chunkName: "schema-org
|
|
60
|
-
filePath:
|
|
49
|
+
chunkName: "nuxt-schema-org/components",
|
|
50
|
+
filePath: AliasRuntime
|
|
61
51
|
});
|
|
52
|
+
}
|
|
53
|
+
await addComponent({
|
|
54
|
+
name: "SchemaOrgDebug",
|
|
55
|
+
export: "SchemaOrgDebug",
|
|
56
|
+
filePath: `${schemaOrgPath}/runtime/components/SchemaOrgDebug`
|
|
57
|
+
});
|
|
58
|
+
nuxt.hooks.hook("autoImports:sources", (autoImports) => {
|
|
59
|
+
autoImports.unshift(...schemaOrgAutoImports);
|
|
60
|
+
});
|
|
61
|
+
const realPaths = {
|
|
62
|
+
runtime: runtimePath,
|
|
63
|
+
provider: providerPath,
|
|
64
|
+
pkg: schemaOrgPath
|
|
65
|
+
};
|
|
66
|
+
const mockPaths = {
|
|
67
|
+
runtime: runtimeMockPath,
|
|
68
|
+
provider: runtimeMockPath,
|
|
69
|
+
pkg: schemaOrgPath
|
|
70
|
+
};
|
|
71
|
+
nuxt.hooks.hook("vite:extendConfig", (config, { isClient }) => {
|
|
72
|
+
config.plugins = config.plugins || [];
|
|
73
|
+
config.plugins.push(AliasRuntimePluginVite({
|
|
74
|
+
paths: !moduleOptions.client && isClient ? mockPaths : realPaths
|
|
75
|
+
}));
|
|
76
|
+
});
|
|
77
|
+
extendWebpackConfig((config) => {
|
|
78
|
+
config.plugins = config.plugins || [];
|
|
79
|
+
config.plugins.push(AliasRuntimePluginWebpack({
|
|
80
|
+
paths: realPaths
|
|
81
|
+
}));
|
|
82
|
+
}, {
|
|
83
|
+
client: false,
|
|
84
|
+
modern: false,
|
|
85
|
+
server: true
|
|
86
|
+
});
|
|
87
|
+
extendWebpackConfig((config) => {
|
|
88
|
+
config.plugins = config.plugins || [];
|
|
89
|
+
config.plugins.push(AliasRuntimePluginWebpack({
|
|
90
|
+
paths: !moduleOptions.client ? mockPaths : realPaths
|
|
91
|
+
}));
|
|
92
|
+
}, {
|
|
93
|
+
client: true,
|
|
94
|
+
modern: true,
|
|
95
|
+
server: false
|
|
62
96
|
});
|
|
63
97
|
}
|
|
64
98
|
});
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -2,34 +2,40 @@ import { createSchemaOrg } from "@vueuse/schema-org";
|
|
|
2
2
|
import { defineNuxtPlugin } from "#app";
|
|
3
3
|
import { unref, watch } from "#imports";
|
|
4
4
|
import config from "#build/nuxt-schema-org-config.mjs";
|
|
5
|
-
export default defineNuxtPlugin((nuxtApp) => {
|
|
5
|
+
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
6
6
|
const ssr = !!nuxtApp.ssrContext?.url;
|
|
7
7
|
const client = createSchemaOrg({
|
|
8
8
|
updateHead(fn) {
|
|
9
9
|
nuxtApp._useHead(unref(fn));
|
|
10
10
|
},
|
|
11
|
-
meta() {
|
|
11
|
+
async meta() {
|
|
12
12
|
const head = nuxtApp.vueApp._context.provides.usehead;
|
|
13
13
|
const inferredMeta = {};
|
|
14
14
|
const headTag = head.headTags.reverse().filter((t) => t.tag === "title" && !!t.props.children);
|
|
15
15
|
if (headTag.length)
|
|
16
16
|
inferredMeta.title = headTag[0].props.children;
|
|
17
|
-
|
|
17
|
+
const descTag = head.headTags.reverse().filter((t) => t.tag === "meta" && t.props.name === "description" && !!t.props.content);
|
|
18
|
+
if (descTag.length)
|
|
19
|
+
inferredMeta.description = descTag[0].props.content;
|
|
20
|
+
const imageTag = head.headTags.reverse().filter((t) => t.tag === "meta" && t.props.property === "og:image" && !!t.props.content);
|
|
21
|
+
if (imageTag.length)
|
|
22
|
+
inferredMeta.image = imageTag[0].props.content;
|
|
23
|
+
const schemaOrgMeta = {
|
|
18
24
|
path: nuxtApp._route.path,
|
|
19
25
|
...inferredMeta,
|
|
20
26
|
...nuxtApp._route.meta,
|
|
21
27
|
...config.meta || {}
|
|
22
28
|
};
|
|
29
|
+
await nuxtApp.hooks.callHook("schema-org:meta", schemaOrgMeta);
|
|
30
|
+
return schemaOrgMeta;
|
|
23
31
|
}
|
|
24
32
|
});
|
|
25
|
-
nuxtApp._injectSchemaOrg = () => client;
|
|
26
33
|
nuxtApp.vueApp.use(client);
|
|
27
34
|
if (ssr) {
|
|
28
|
-
client.
|
|
29
|
-
client.setupDOM();
|
|
35
|
+
await client.forceRefresh();
|
|
30
36
|
return;
|
|
31
37
|
}
|
|
32
38
|
watch(() => nuxtApp._route.path, () => {
|
|
33
|
-
client.
|
|
39
|
+
client.forceRefresh();
|
|
34
40
|
});
|
|
35
41
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-schema-org",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-beta.20",
|
|
4
5
|
"description": "Nuxt module for @vueuse/schema-org",
|
|
5
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
6
7
|
"license": "MIT",
|
|
@@ -21,10 +22,8 @@
|
|
|
21
22
|
"nuxt-module",
|
|
22
23
|
"nuxt3"
|
|
23
24
|
],
|
|
24
|
-
"sideEffects": false,
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
-
"types": "./dist/types.d.ts",
|
|
28
27
|
"require": "./dist/module.cjs",
|
|
29
28
|
"import": "./dist/module.mjs"
|
|
30
29
|
}
|
|
@@ -35,21 +34,20 @@
|
|
|
35
34
|
"dist"
|
|
36
35
|
],
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"@nuxt/kit": "3.0.0-rc.8",
|
|
39
|
-
"@vueuse/schema-org": "1.0.0-beta.
|
|
40
|
-
"@vueuse/schema-org-vite": "1.0.0-beta.
|
|
41
|
-
"pathe": "^0.3.
|
|
42
|
-
"schema-org-graph-js": "0.
|
|
37
|
+
"@nuxt/kit": "^3.0.0-rc.8",
|
|
38
|
+
"@vueuse/schema-org": "1.0.0-beta.20",
|
|
39
|
+
"@vueuse/schema-org-vite": "1.0.0-beta.20",
|
|
40
|
+
"pathe": "^0.3.5",
|
|
41
|
+
"schema-org-graph-js": "0.4.4"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@nuxt/module-builder": "latest",
|
|
46
|
-
"@nuxt/schema": "3.0.0-rc.8"
|
|
47
|
-
"nuxt": "3.0.0-rc.8"
|
|
45
|
+
"@nuxt/schema": "3.0.0-rc.8"
|
|
48
46
|
},
|
|
49
47
|
"scripts": {
|
|
50
|
-
"build": "npm run -C ../../
|
|
48
|
+
"build": "npm run -C ../../test/fixtures/nuxt nuxt:prepare && nuxt-module-build",
|
|
49
|
+
"stub": "nuxt-module-build --stub && nuxi prepare ../../test/fixtures/nuxt",
|
|
51
50
|
"play": "nuxi dev ../../playgrounds/nuxt3",
|
|
52
|
-
"play:build": "nuxi build ../../playgrounds/nuxt3"
|
|
53
|
-
"stub": "nuxt-module-build --stub && nuxi prepare ../../playgrounds/nuxt3"
|
|
51
|
+
"play:build": "nuxi build ../../playgrounds/nuxt3"
|
|
54
52
|
}
|
|
55
53
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { useNuxtApp } from "#app";
|
|
2
|
-
export * from "#vueuse/schema-org/provider";
|
|
3
|
-
export { useSchemaOrg } from "#vueuse/schema-org/runtime";
|
|
4
|
-
export function injectSchemaOrg() {
|
|
5
|
-
const nuxtApp = useNuxtApp();
|
|
6
|
-
if (nuxtApp._injectSchemaOrg)
|
|
7
|
-
return nuxtApp._injectSchemaOrg();
|
|
8
|
-
}
|