nuxt-schema-org 0.7.0-beta.3 → 1.0.0-beta.11
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 +10 -9
- package/dist/module.json +1 -1
- package/dist/module.mjs +43 -93
- 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 +35 -0
- package/package.json +9 -8
- package/dist/runtime/composables.d.ts +0 -2
- package/dist/runtime/composables.mjs +0 -8
- 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,24 @@
|
|
|
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
|
-
|
|
12
|
+
client?: boolean;
|
|
11
13
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @default
|
|
14
|
+
* Should full schema types from `schema-dts` be used over a simplified version.
|
|
15
|
+
* @default false
|
|
14
16
|
*/
|
|
15
|
-
|
|
17
|
+
full?: boolean;
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @default true
|
|
19
|
+
* Metadata for the schema.org generation
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
meta?: MetaInput;
|
|
21
22
|
}
|
|
22
23
|
interface ModuleHooks {
|
|
23
24
|
}
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addPlugin, addTemplate, addComponent } from '@nuxt/kit';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
2
|
+
import { AliasRuntime, AliasProvider, schemaOrgComponents, schemaOrgAutoImports } from '@vueuse/schema-org';
|
|
3
|
+
import { dirname } from 'pathe';
|
|
4
|
+
import { SchemaOrg } from '@vueuse/schema-org-vite';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
if (!input.includes("\\")) {
|
|
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";
|
|
21
7
|
const module = defineNuxtModule({
|
|
22
8
|
meta: {
|
|
23
9
|
configKey: "schemaOrg",
|
|
@@ -25,88 +11,52 @@ const module = defineNuxtModule({
|
|
|
25
11
|
bridge: false
|
|
26
12
|
}
|
|
27
13
|
},
|
|
28
|
-
|
|
29
|
-
disableRuntimeScriptsWhenSSR: false,
|
|
30
|
-
autoImportComposables: true,
|
|
31
|
-
autoImportComponents: true
|
|
32
|
-
},
|
|
33
|
-
async setup(config, nuxt) {
|
|
14
|
+
async setup(moduleOptions, nuxt) {
|
|
34
15
|
const { resolve, resolvePath } = createResolver(import.meta.url);
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
nuxt.options.alias[
|
|
43
|
-
nuxt.options.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
16
|
+
const schemaOrgPath = dirname(await resolvePath(Pkg));
|
|
17
|
+
const moduleRuntimeDir = resolve("./runtime");
|
|
18
|
+
nuxt.options.build.transpile.push(...[moduleRuntimeDir, AliasRuntime]);
|
|
19
|
+
if (typeof moduleOptions.client === "undefined")
|
|
20
|
+
moduleOptions.client = !!nuxt.options.dev;
|
|
21
|
+
const providerPath = await resolvePath(`${schemaOrgPath}/providers/${moduleOptions.full ? "full" : "simple"}`);
|
|
22
|
+
nuxt.options.alias[AliasProvider] = providerPath;
|
|
23
|
+
nuxt.options.alias[AliasRuntime] = "@vueuse/schema-org/runtime";
|
|
24
|
+
nuxt.options.alias[Pkg] = schemaOrgPath;
|
|
25
|
+
if (!moduleOptions.client)
|
|
26
|
+
addPlugin(resolve(moduleRuntimeDir, "plugin-fallback.client"));
|
|
27
|
+
addPlugin({
|
|
28
|
+
src: resolve(moduleRuntimeDir, "plugin"),
|
|
29
|
+
mode: moduleOptions.client ? "all" : "server"
|
|
48
30
|
});
|
|
49
31
|
addTemplate({
|
|
50
|
-
filename: "
|
|
51
|
-
getContents: () => `export default ${JSON.stringify(
|
|
32
|
+
filename: "nuxt-schema-org-config.mjs",
|
|
33
|
+
getContents: () => `export default ${JSON.stringify(moduleOptions)}`
|
|
52
34
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
35
|
+
for (const component of schemaOrgComponents) {
|
|
36
|
+
await addComponent({
|
|
37
|
+
name: component,
|
|
38
|
+
export: component,
|
|
39
|
+
chunkName: "nuxt-schema-org/components",
|
|
40
|
+
filePath: AliasRuntime
|
|
59
41
|
});
|
|
60
42
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
addComponent({
|
|
78
|
-
name: "SchemaOrgMock",
|
|
79
|
-
export: "SchemaOrgMock",
|
|
80
|
-
filePath: schemaOrgPath
|
|
81
|
-
});
|
|
82
|
-
nuxt.options.alias["#schema-org/mock"] = mockTemplate.dst;
|
|
83
|
-
const mockerPlugin = createUnplugin(() => {
|
|
84
|
-
return {
|
|
85
|
-
name: "nuxt-schema-org:mocker",
|
|
86
|
-
enforce: "post",
|
|
87
|
-
transformInclude(id) {
|
|
88
|
-
return id.endsWith(".vue") && id.includes(nuxt.options.srcDir);
|
|
89
|
-
},
|
|
90
|
-
transform(code, id) {
|
|
91
|
-
const s = new MagicString(code);
|
|
92
|
-
s.replace(resolve(runtimeDir, "composables"), "#schema-org/mock");
|
|
93
|
-
s.replace(/_resolveComponent\("SchemaOrg(.*?)"\)/gm, '_resolveComponent("SchemaOrgMock")');
|
|
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());
|
|
43
|
+
nuxt.hooks.hook("autoImports:sources", (autoImports) => {
|
|
44
|
+
autoImports.unshift(...schemaOrgAutoImports);
|
|
45
|
+
});
|
|
46
|
+
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
|
+
config.plugins = config.plugins || [];
|
|
51
|
+
config.plugins.push(SchemaOrg({
|
|
52
|
+
mock: !moduleOptions.client && isClient,
|
|
53
|
+
full: moduleOptions.full,
|
|
54
|
+
aliasPaths: {
|
|
55
|
+
provider: providerPath,
|
|
56
|
+
pkgDir: schemaOrgPath
|
|
107
57
|
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
58
|
+
}));
|
|
59
|
+
});
|
|
110
60
|
}
|
|
111
61
|
});
|
|
112
62
|
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
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.vueApp.use(client);
|
|
26
|
+
if (ssr) {
|
|
27
|
+
client.generateSchema();
|
|
28
|
+
client.setupDOM();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
watch(() => nuxtApp._route.path, () => {
|
|
32
|
+
client.generateSchema();
|
|
33
|
+
client.setupDOM();
|
|
34
|
+
});
|
|
35
|
+
});
|
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.11",
|
|
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,14 +34,16 @@
|
|
|
35
34
|
"dist"
|
|
36
35
|
],
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"@nuxt/kit": "3.0.0-rc.
|
|
39
|
-
"@vueuse/schema-org": "0.
|
|
40
|
-
"
|
|
41
|
-
"
|
|
37
|
+
"@nuxt/kit": "3.0.0-rc.8",
|
|
38
|
+
"@vueuse/schema-org": "1.0.0-beta.11",
|
|
39
|
+
"@vueuse/schema-org-vite": "1.0.0-beta.11",
|
|
40
|
+
"pathe": "^0.3.4",
|
|
41
|
+
"schema-org-graph-js": "0.3.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@nuxt/module-builder": "latest",
|
|
45
|
-
"@nuxt/schema": "3.0.0-rc.
|
|
45
|
+
"@nuxt/schema": "3.0.0-rc.8",
|
|
46
|
+
"nuxt": "3.0.0-rc.8"
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"build": "npm run -C ../../playgrounds/nuxt3 prepare && nuxt-module-build",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { isFunction } from "@vue/shared";
|
|
2
|
-
import { computed } from "#imports";
|
|
3
|
-
import { useNuxtApp } from "#app";
|
|
4
|
-
export * from "@vueuse/schema-org";
|
|
5
|
-
export function useSchemaOrg(input) {
|
|
6
|
-
const resolveInput = isFunction(input) ? computed(input) : input;
|
|
7
|
-
useNuxtApp()._useSchemaOrg(resolveInput);
|
|
8
|
-
}
|
|
@@ -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
|
-
});
|