nuxt-schema-org 0.7.0-beta.3 → 1.0.0-beta.3
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 +9 -11
- package/dist/module.json +1 -1
- package/dist/module.mjs +50 -92
- package/dist/runtime/composables.d.ts +2 -2
- package/dist/runtime/composables.mjs +5 -6
- package/dist/runtime/{plugin.client.d.ts → plugin-fallback.client.d.ts} +0 -0
- package/dist/runtime/plugin-fallback.client.mjs +7 -0
- package/dist/runtime/{plugin.server.d.ts → plugin.d.ts} +0 -0
- package/dist/runtime/plugin.mjs +36 -0
- package/package.json +8 -6
- package/dist/runtime/plugin.client.mjs +0 -19
- package/dist/runtime/plugin.server.mjs +0 -37
package/dist/module.d.ts
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MetaInput } from 'schema-org-graph-js';
|
|
2
2
|
import { NuxtModule } from '@nuxt/schema';
|
|
3
3
|
|
|
4
|
-
interface ModuleOptions
|
|
4
|
+
interface ModuleOptions {
|
|
5
5
|
/**
|
|
6
6
|
* Should schema.org only be rendered by the server.
|
|
7
7
|
*
|
|
8
8
|
* Useful for optimising performance as it may not be needed by search engines. Changes runtime package size to 0kb.
|
|
9
|
+
*
|
|
10
|
+
* @default false
|
|
9
11
|
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Whether composables will be automatically imported for you.
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
autoImportComposables: boolean;
|
|
12
|
+
client?: boolean;
|
|
16
13
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @default
|
|
14
|
+
* Should full schema types from `schema-dts` be used over a simplified version.
|
|
15
|
+
* @default false
|
|
19
16
|
*/
|
|
20
|
-
|
|
17
|
+
full?: boolean;
|
|
18
|
+
meta?: MetaInput;
|
|
21
19
|
}
|
|
22
20
|
interface ModuleHooks {
|
|
23
21
|
}
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addPlugin, addTemplate, addComponent } from '@nuxt/kit';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
2
|
+
import { schemaOrgComponents, RootSchemas } from '@vueuse/schema-org';
|
|
3
|
+
import { dirname } from 'pathe';
|
|
4
|
+
import { SchemaOrg } from '@vueuse/schema-org-vite';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return input;
|
|
9
|
-
}
|
|
10
|
-
return input.replace(/\\/g, "/");
|
|
11
|
-
}
|
|
12
|
-
const _IS_ABSOLUTE_RE = /^\/|^\\|^[a-zA-Z]:[/\\]/;
|
|
13
|
-
const isAbsolute = function(p) {
|
|
14
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
15
|
-
};
|
|
16
|
-
const dirname = function(p) {
|
|
17
|
-
return normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1).join("/") || (isAbsolute(p) ? "/" : ".");
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const SchemaOrgPkg = "@vueuse/schema-org";
|
|
6
|
+
const Pkg = "@vueuse/schema-org";
|
|
7
|
+
const RuntimeDir = "#vueuse/schema-org/runtime";
|
|
21
8
|
const module = defineNuxtModule({
|
|
22
9
|
meta: {
|
|
23
10
|
configKey: "schemaOrg",
|
|
@@ -25,88 +12,59 @@ const module = defineNuxtModule({
|
|
|
25
12
|
bridge: false
|
|
26
13
|
}
|
|
27
14
|
},
|
|
28
|
-
|
|
29
|
-
disableRuntimeScriptsWhenSSR: false,
|
|
30
|
-
autoImportComposables: true,
|
|
31
|
-
autoImportComponents: true
|
|
32
|
-
},
|
|
33
|
-
async setup(config, nuxt) {
|
|
15
|
+
async setup(moduleOptions, nuxt) {
|
|
34
16
|
const { resolve, resolvePath } = createResolver(import.meta.url);
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
config2.optimizeDeps = config2.optimizeDeps || {};
|
|
46
|
-
config2.optimizeDeps.exclude = config2.optimizeDeps.exclude || [];
|
|
47
|
-
config2.optimizeDeps.exclude.push(...[schemaOrgPath, SchemaOrgPkg]);
|
|
17
|
+
const schemaOrgPath = dirname(await resolvePath(Pkg));
|
|
18
|
+
const moduleRuntimeDir = resolve("./runtime");
|
|
19
|
+
nuxt.options.build.transpile.push(...[moduleRuntimeDir, RuntimeDir]);
|
|
20
|
+
if (typeof moduleOptions.client === "undefined")
|
|
21
|
+
moduleOptions.client = !!nuxt.options.dev;
|
|
22
|
+
if (!moduleOptions.client)
|
|
23
|
+
addPlugin(resolve(moduleRuntimeDir, "plugin-fallback.client"));
|
|
24
|
+
addPlugin({
|
|
25
|
+
src: resolve(moduleRuntimeDir, "plugin"),
|
|
26
|
+
mode: moduleOptions.client ? "all" : "server"
|
|
48
27
|
});
|
|
28
|
+
const nuxtSchemaComposablesRuntime = `${moduleRuntimeDir}/composables`;
|
|
49
29
|
addTemplate({
|
|
50
|
-
filename: "
|
|
51
|
-
getContents: () => `export default ${JSON.stringify(
|
|
30
|
+
filename: "nuxt-schema-org-config.mjs",
|
|
31
|
+
getContents: () => `export default ${JSON.stringify(moduleOptions)}`
|
|
52
32
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
if (config.autoImportComponents) {
|
|
62
|
-
schemaOrgComponents.forEach((component) => {
|
|
63
|
-
addComponent({
|
|
64
|
-
name: component,
|
|
65
|
-
export: component,
|
|
66
|
-
filePath: schemaOrgPath
|
|
67
|
-
});
|
|
33
|
+
const componentPath = await resolvePath("@vueuse/schema-org/components");
|
|
34
|
+
for (const component of schemaOrgComponents) {
|
|
35
|
+
await addComponent({
|
|
36
|
+
name: component,
|
|
37
|
+
export: component,
|
|
38
|
+
chunkName: "schema-org-components",
|
|
39
|
+
filePath: componentPath
|
|
68
40
|
});
|
|
69
41
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
42
|
+
nuxt.hooks.hook("autoImports:sources", (autoImports) => {
|
|
43
|
+
autoImports.unshift({
|
|
44
|
+
from: nuxtSchemaComposablesRuntime,
|
|
45
|
+
imports: [
|
|
46
|
+
"injectSchemaOrg",
|
|
47
|
+
"useSchemaOrg"
|
|
48
|
+
]
|
|
76
49
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
50
|
+
autoImports.unshift({
|
|
51
|
+
from: "#vueuse/schema-org/provider",
|
|
52
|
+
imports: [
|
|
53
|
+
...RootSchemas.map((schema) => [`define${schema}`]).flat()
|
|
54
|
+
]
|
|
81
55
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (s.hasChanged()) {
|
|
95
|
-
return {
|
|
96
|
-
code: s.toString(),
|
|
97
|
-
map: s.generateMap({ includeContent: true, source: id })
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
nuxt.hook("vite:extendConfig", (config2, { isClient }) => {
|
|
104
|
-
if (isClient) {
|
|
105
|
-
config2.plugins = config2.plugins || [];
|
|
106
|
-
config2.plugins.push(mockerPlugin.vite());
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
56
|
+
});
|
|
57
|
+
nuxt.hooks.hook("vite:extendConfig", (config, { isClient }) => {
|
|
58
|
+
config.optimizeDeps = config.optimizeDeps || {};
|
|
59
|
+
config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
|
|
60
|
+
config.optimizeDeps.exclude.push(...[`${schemaOrgPath}/runtime`, Pkg]);
|
|
61
|
+
config.plugins = config.plugins || [];
|
|
62
|
+
config.plugins.push(SchemaOrg({
|
|
63
|
+
mock: !moduleOptions.client && isClient,
|
|
64
|
+
full: moduleOptions.full,
|
|
65
|
+
runtimePath: nuxtSchemaComposablesRuntime
|
|
66
|
+
}));
|
|
67
|
+
});
|
|
110
68
|
}
|
|
111
69
|
});
|
|
112
70
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export declare function
|
|
1
|
+
export { useSchemaOrg } from '@vueuse/schema-org/runtime';
|
|
2
|
+
export declare function injectSchemaOrg(): any;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { isFunction } from "@vue/shared";
|
|
2
|
-
import { computed } from "#imports";
|
|
3
1
|
import { useNuxtApp } from "#app";
|
|
4
|
-
export
|
|
5
|
-
export function
|
|
6
|
-
const
|
|
7
|
-
|
|
2
|
+
export { useSchemaOrg } from "@vueuse/schema-org/runtime";
|
|
3
|
+
export function injectSchemaOrg() {
|
|
4
|
+
const nuxtApp = useNuxtApp();
|
|
5
|
+
if (nuxtApp._injectSchemaOrg)
|
|
6
|
+
return nuxtApp._injectSchemaOrg();
|
|
8
7
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createSchemaOrg } from "@vueuse/schema-org";
|
|
2
|
+
import { defineNuxtPlugin } from "#app";
|
|
3
|
+
import { unref, watch } from "#imports";
|
|
4
|
+
import config from "#build/nuxt-schema-org-config.mjs";
|
|
5
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
6
|
+
const ssr = !!nuxtApp.ssrContext?.url;
|
|
7
|
+
const client = createSchemaOrg({
|
|
8
|
+
updateHead(fn) {
|
|
9
|
+
nuxtApp._useHead(unref(fn));
|
|
10
|
+
},
|
|
11
|
+
meta() {
|
|
12
|
+
const head = nuxtApp.vueApp._context.provides.usehead;
|
|
13
|
+
const inferredMeta = {};
|
|
14
|
+
const headTag = head.headTags.reverse().filter((t) => t.tag === "title" && !!t.props.children);
|
|
15
|
+
if (headTag.length)
|
|
16
|
+
inferredMeta.title = headTag[0].props.children;
|
|
17
|
+
return {
|
|
18
|
+
path: nuxtApp._route.path,
|
|
19
|
+
...inferredMeta,
|
|
20
|
+
...nuxtApp._route.meta,
|
|
21
|
+
...config.meta || {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
nuxtApp._injectSchemaOrg = () => client;
|
|
26
|
+
nuxtApp.vueApp.use(client);
|
|
27
|
+
if (ssr) {
|
|
28
|
+
client.generateSchema();
|
|
29
|
+
client.setupDOM();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
watch(() => nuxtApp._route.path, () => {
|
|
33
|
+
client.generateSchema();
|
|
34
|
+
client.setupDOM();
|
|
35
|
+
});
|
|
36
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-schema-org",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"description": "Nuxt module for @vueuse/schema-org",
|
|
5
5
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,14 +35,16 @@
|
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@nuxt/kit": "3.0.0-rc.
|
|
39
|
-
"@vueuse/schema-org": "0.
|
|
40
|
-
"
|
|
41
|
-
"
|
|
38
|
+
"@nuxt/kit": "3.0.0-rc.8",
|
|
39
|
+
"@vueuse/schema-org": "1.0.0-beta.3",
|
|
40
|
+
"@vueuse/schema-org-vite": "1.0.0-beta.3",
|
|
41
|
+
"pathe": "^0.3.4",
|
|
42
|
+
"schema-org-graph-js": "0.3.3"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@nuxt/module-builder": "latest",
|
|
45
|
-
"@nuxt/schema": "3.0.0-rc.
|
|
46
|
+
"@nuxt/schema": "3.0.0-rc.8",
|
|
47
|
+
"nuxt": "3.0.0-rc.8"
|
|
46
48
|
},
|
|
47
49
|
"scripts": {
|
|
48
50
|
"build": "npm run -C ../../playgrounds/nuxt3 prepare && nuxt-module-build",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { createSchemaOrg, handleNodesCSR, useVueUseHead } from "@vueuse/schema-org";
|
|
2
|
-
import { defineNuxtPlugin } from "#app";
|
|
3
|
-
import { useRoute } from "#imports";
|
|
4
|
-
import meta from "#build/schemaOrg.config.mjs";
|
|
5
|
-
export default defineNuxtPlugin((nuxtApp) => {
|
|
6
|
-
const head = nuxtApp.vueApp._context.provides.usehead;
|
|
7
|
-
const client = createSchemaOrg({
|
|
8
|
-
provider: {
|
|
9
|
-
useRoute,
|
|
10
|
-
setupDOM: useVueUseHead(head),
|
|
11
|
-
name: "nuxt"
|
|
12
|
-
},
|
|
13
|
-
...meta.config
|
|
14
|
-
});
|
|
15
|
-
nuxtApp._useSchemaOrg = (input) => {
|
|
16
|
-
return handleNodesCSR(client, input);
|
|
17
|
-
};
|
|
18
|
-
nuxtApp.vueApp.use(client);
|
|
19
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createSchemaOrg, handleNodesSSR } from "@vueuse/schema-org";
|
|
2
|
-
import { defineNuxtPlugin } from "#app";
|
|
3
|
-
import { computed, useRoute } from "#imports";
|
|
4
|
-
import meta from "#build/schemaOrg.config.mjs";
|
|
5
|
-
export default defineNuxtPlugin((nuxtApp) => {
|
|
6
|
-
const head = nuxtApp.vueApp._context.provides.usehead;
|
|
7
|
-
let _domSetup = false;
|
|
8
|
-
const client = createSchemaOrg({
|
|
9
|
-
provider: {
|
|
10
|
-
useRoute,
|
|
11
|
-
setupDOM({ schemaRef }) {
|
|
12
|
-
if (_domSetup)
|
|
13
|
-
return;
|
|
14
|
-
head.addHeadObjs(computed(() => {
|
|
15
|
-
return {
|
|
16
|
-
script: [
|
|
17
|
-
{
|
|
18
|
-
"type": "application/ld+json",
|
|
19
|
-
"data-id": "schema-org-graph",
|
|
20
|
-
"key": "schema-org-graph",
|
|
21
|
-
"children": schemaRef.value
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
};
|
|
25
|
-
}));
|
|
26
|
-
_domSetup = true;
|
|
27
|
-
},
|
|
28
|
-
name: "nuxt"
|
|
29
|
-
},
|
|
30
|
-
...meta.config
|
|
31
|
-
});
|
|
32
|
-
nuxtApp._useSchemaOrg = (input) => {
|
|
33
|
-
return handleNodesSSR(client, input);
|
|
34
|
-
};
|
|
35
|
-
client.setupDOM();
|
|
36
|
-
nuxtApp.vueApp.use(client);
|
|
37
|
-
});
|