nuxt-schema-org 1.0.0-beta.9 → 1.0.2
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 -19
- package/dist/module.json +2 -1
- package/dist/module.mjs +53 -16
- package/dist/runtime/plugin.mjs +13 -7
- package/package.json +10 -11
package/dist/module.d.ts
CHANGED
|
@@ -1,27 +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
|
-
/**
|
|
19
|
-
* Metadata for the schema.org generation
|
|
20
|
-
*/
|
|
21
|
-
meta?: MetaInput;
|
|
5
|
+
interface ModuleOptions extends UserConfig {
|
|
22
6
|
}
|
|
23
7
|
interface ModuleHooks {
|
|
24
8
|
}
|
|
9
|
+
declare module 'nuxt' {
|
|
10
|
+
interface RuntimeNuxtHooks {
|
|
11
|
+
'schema-org:meta': (meta: MetaInput) => void;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
25
14
|
declare const _default: NuxtModule<ModuleOptions>;
|
|
26
15
|
|
|
27
16
|
export { ModuleHooks, ModuleOptions, _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,27 +1,37 @@
|
|
|
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
7
|
const module = defineNuxtModule({
|
|
8
8
|
meta: {
|
|
9
9
|
configKey: "schemaOrg",
|
|
10
10
|
compatibility: {
|
|
11
|
+
nuxt: ">=3.0.0-rc.8",
|
|
11
12
|
bridge: false
|
|
12
13
|
}
|
|
13
14
|
},
|
|
14
15
|
async setup(moduleOptions, nuxt) {
|
|
15
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
|
+
}
|
|
16
22
|
const schemaOrgPath = dirname(await resolvePath(Pkg));
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
if (!nuxt.options.ssr)
|
|
24
|
+
moduleOptions.client = true;
|
|
19
25
|
if (typeof moduleOptions.client === "undefined")
|
|
20
26
|
moduleOptions.client = !!nuxt.options.dev;
|
|
21
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`);
|
|
22
30
|
nuxt.options.alias[AliasProvider] = providerPath;
|
|
23
|
-
nuxt.options.alias[AliasRuntime] =
|
|
31
|
+
nuxt.options.alias[AliasRuntime] = runtimePath;
|
|
24
32
|
nuxt.options.alias[Pkg] = schemaOrgPath;
|
|
33
|
+
const moduleRuntimeDir = resolve("./runtime");
|
|
34
|
+
nuxt.options.build.transpile.push(...[moduleRuntimeDir, AliasRuntime]);
|
|
25
35
|
if (!moduleOptions.client)
|
|
26
36
|
addPlugin(resolve(moduleRuntimeDir, "plugin-fallback.client"));
|
|
27
37
|
addPlugin({
|
|
@@ -40,22 +50,49 @@ const module = defineNuxtModule({
|
|
|
40
50
|
filePath: AliasRuntime
|
|
41
51
|
});
|
|
42
52
|
}
|
|
53
|
+
await addComponent({
|
|
54
|
+
name: "SchemaOrgDebug",
|
|
55
|
+
export: "SchemaOrgDebug",
|
|
56
|
+
filePath: `${schemaOrgPath}/runtime/components/SchemaOrgDebug`
|
|
57
|
+
});
|
|
43
58
|
nuxt.hooks.hook("autoImports:sources", (autoImports) => {
|
|
44
59
|
autoImports.unshift(...schemaOrgAutoImports);
|
|
45
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
|
+
};
|
|
46
71
|
nuxt.hooks.hook("vite:extendConfig", (config, { isClient }) => {
|
|
47
|
-
config.optimizeDeps = config.optimizeDeps || {};
|
|
48
|
-
config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
|
|
49
|
-
config.optimizeDeps.exclude.push(...[`${schemaOrgPath}/runtime`, Pkg]);
|
|
50
72
|
config.plugins = config.plugins || [];
|
|
51
|
-
config.plugins.push(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
58
91
|
}));
|
|
92
|
+
}, {
|
|
93
|
+
client: true,
|
|
94
|
+
modern: true,
|
|
95
|
+
server: false
|
|
59
96
|
});
|
|
60
97
|
}
|
|
61
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
33
|
nuxtApp.vueApp.use(client);
|
|
26
34
|
if (ssr) {
|
|
27
|
-
client.
|
|
28
|
-
client.setupDOM();
|
|
35
|
+
await client.forceRefresh();
|
|
29
36
|
return;
|
|
30
37
|
}
|
|
31
38
|
watch(() => nuxtApp._route.path, () => {
|
|
32
|
-
client.
|
|
33
|
-
client.setupDOM();
|
|
39
|
+
client.forceRefresh();
|
|
34
40
|
});
|
|
35
41
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-schema-org",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "Nuxt module for @vueuse/schema-org",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -34,21 +34,20 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nuxt/kit": "3.0.0-rc.8",
|
|
38
|
-
"@vueuse/schema-org": "1.0.
|
|
39
|
-
"@vueuse/schema-org-vite": "1.0.
|
|
40
|
-
"pathe": "^0.3.
|
|
41
|
-
"schema-org-graph-js": "0.
|
|
37
|
+
"@nuxt/kit": "^3.0.0-rc.8",
|
|
38
|
+
"@vueuse/schema-org": "1.0.2",
|
|
39
|
+
"@vueuse/schema-org-vite": "1.0.2",
|
|
40
|
+
"pathe": "^0.3.5",
|
|
41
|
+
"schema-org-graph-js": "0.5.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@nuxt/module-builder": "latest",
|
|
45
|
-
"@nuxt/schema": "3.0.0-rc.8"
|
|
46
|
-
"nuxt": "3.0.0-rc.8"
|
|
45
|
+
"@nuxt/schema": "3.0.0-rc.8"
|
|
47
46
|
},
|
|
48
47
|
"scripts": {
|
|
49
|
-
"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",
|
|
50
50
|
"play": "nuxi dev ../../playgrounds/nuxt3",
|
|
51
|
-
"play:build": "nuxi build ../../playgrounds/nuxt3"
|
|
52
|
-
"stub": "nuxt-module-build --stub && nuxi prepare ../../playgrounds/nuxt3"
|
|
51
|
+
"play:build": "nuxi build ../../playgrounds/nuxt3"
|
|
53
52
|
}
|
|
54
53
|
}
|