nuxt-schema-org 0.6.2 → 0.7.0-beta.0
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.json +1 -1
- package/dist/module.mjs +26 -5
- package/dist/runtime/composables.d.ts +1 -1
- package/dist/runtime/composables.mjs +3 -3
- package/dist/runtime/{plugin-spa.client.d.ts → plugin.client.d.ts} +0 -0
- package/dist/runtime/{plugin-ssr.client.mjs → plugin.client.mjs} +12 -14
- package/dist/runtime/plugin.server.mjs +6 -12
- package/package.json +7 -7
- package/dist/runtime/plugin-spa.client.mjs +0 -35
- package/dist/runtime/plugin-ssr.client.d.ts +0 -2
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addPlugin, addTemplate, addComponent } from '@nuxt/kit';
|
|
2
2
|
import { schemaOrgAutoImports, schemaOrgComponents } from '@vueuse/schema-org';
|
|
3
3
|
|
|
4
|
+
function normalizeWindowsPath(input = "") {
|
|
5
|
+
if (!input.includes("\\")) {
|
|
6
|
+
return input;
|
|
7
|
+
}
|
|
8
|
+
return input.replace(/\\/g, "/");
|
|
9
|
+
}
|
|
10
|
+
const _IS_ABSOLUTE_RE = /^\/|^\\|^[a-zA-Z]:[/\\]/;
|
|
11
|
+
const isAbsolute = function(p) {
|
|
12
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
13
|
+
};
|
|
14
|
+
const dirname = function(p) {
|
|
15
|
+
return normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1).join("/") || (isAbsolute(p) ? "/" : ".");
|
|
16
|
+
};
|
|
17
|
+
|
|
4
18
|
const module = defineNuxtModule({
|
|
5
19
|
meta: {
|
|
6
20
|
configKey: "schemaOrg",
|
|
@@ -13,12 +27,19 @@ const module = defineNuxtModule({
|
|
|
13
27
|
autoImportComponents: true
|
|
14
28
|
},
|
|
15
29
|
async setup(config, nuxt) {
|
|
16
|
-
const { resolve } = createResolver(import.meta.url);
|
|
17
|
-
const runtimeDir =
|
|
30
|
+
const { resolve, resolvePath } = createResolver(import.meta.url);
|
|
31
|
+
const runtimeDir = resolve("./runtime");
|
|
18
32
|
nuxt.options.build.transpile.push(runtimeDir);
|
|
19
|
-
addPlugin(resolve(runtimeDir,
|
|
33
|
+
addPlugin(resolve(runtimeDir, "plugin.client"));
|
|
20
34
|
addPlugin(resolve(runtimeDir, "plugin.server"));
|
|
21
|
-
|
|
35
|
+
const schemaOrgPath = dirname(await resolvePath("@vueuse/schema-org"));
|
|
36
|
+
nuxt.options.alias["@vueuse/schema-org"] = schemaOrgPath;
|
|
37
|
+
nuxt.hook("vite:extend", ({ config: config2 }) => {
|
|
38
|
+
config2.optimizeDeps = config2.optimizeDeps || {};
|
|
39
|
+
config2.optimizeDeps.exclude = config2.optimizeDeps.exclude || [];
|
|
40
|
+
config2.optimizeDeps.exclude.push(...[schemaOrgPath, "@vueuse/schema-org"]);
|
|
41
|
+
});
|
|
42
|
+
nuxt.options.build.transpile.push(...[schemaOrgPath, "@vueuse/schema-org"]);
|
|
22
43
|
addTemplate({
|
|
23
44
|
filename: "schemaOrg.config.mjs",
|
|
24
45
|
getContents: () => `export default ${JSON.stringify({ config })}`
|
|
@@ -36,7 +57,7 @@ const module = defineNuxtModule({
|
|
|
36
57
|
addComponent({
|
|
37
58
|
name: component,
|
|
38
59
|
export: component,
|
|
39
|
-
filePath:
|
|
60
|
+
filePath: schemaOrgPath
|
|
40
61
|
});
|
|
41
62
|
});
|
|
42
63
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from '@vueuse/schema-org';
|
|
2
|
-
export declare function useSchemaOrg(
|
|
2
|
+
export declare function useSchemaOrg(input: any): void;
|
|
@@ -2,7 +2,7 @@ import { isFunction } from "@vue/shared";
|
|
|
2
2
|
import { computed } from "vue";
|
|
3
3
|
import { useNuxtApp } from "#app";
|
|
4
4
|
export * from "@vueuse/schema-org";
|
|
5
|
-
export function useSchemaOrg(
|
|
6
|
-
const
|
|
7
|
-
useNuxtApp()._useSchemaOrg(
|
|
5
|
+
export function useSchemaOrg(input) {
|
|
6
|
+
const resolveInput = isFunction(input) ? computed(input) : input;
|
|
7
|
+
useNuxtApp()._useSchemaOrg(resolveInput);
|
|
8
8
|
}
|
|
File without changes
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { createSchemaOrg, useVueUseHead } from "@vueuse/schema-org";
|
|
2
1
|
import { defineNuxtPlugin } from "#app";
|
|
3
|
-
import { getCurrentInstance, onBeforeUnmount, useRoute, useRouter } from "#imports";
|
|
2
|
+
import { createSchemaOrg, getCurrentInstance, onBeforeUnmount, ref, useRoute, useRouter, useVueUseHead } from "#imports";
|
|
4
3
|
import meta from "#build/schemaOrg.config.mjs";
|
|
5
4
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
6
5
|
const head = nuxtApp.vueApp._context.provides.usehead;
|
|
@@ -13,32 +12,31 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
13
12
|
...meta.config
|
|
14
13
|
});
|
|
15
14
|
let _routeChanged = false;
|
|
16
|
-
const rootCtx = client.setupRouteContext(1);
|
|
17
|
-
const schemaOrg = document.querySelector('head script[data-id="schema-org-graph"]')?.innerHTML;
|
|
18
|
-
if (schemaOrg) {
|
|
19
|
-
for (const node of JSON.parse(schemaOrg)["@graph"])
|
|
20
|
-
client.addNode(node, rootCtx);
|
|
21
|
-
client.generateSchema();
|
|
22
|
-
}
|
|
23
15
|
nuxtApp._useSchemaOrg = (input) => {
|
|
16
|
+
const ids = ref(/* @__PURE__ */ new Set());
|
|
24
17
|
const vm = getCurrentInstance();
|
|
25
18
|
let ctx = client.setupRouteContext(vm.uid);
|
|
26
|
-
if (_routeChanged) {
|
|
27
|
-
client.addNodesAndResolveRelations(ctx, input);
|
|
19
|
+
if (!client.serverRendered || _routeChanged) {
|
|
20
|
+
ids.value = client.addNodesAndResolveRelations(ctx, input);
|
|
21
|
+
if (!client.serverRendered)
|
|
22
|
+
client.generateSchema();
|
|
28
23
|
}
|
|
29
|
-
const
|
|
24
|
+
const handleRouteChange = () => {
|
|
30
25
|
ctx = client.setupRouteContext(vm.uid);
|
|
31
26
|
client.removeContext(ctx);
|
|
32
|
-
client.addNodesAndResolveRelations(ctx, input);
|
|
27
|
+
ids.value = client.addNodesAndResolveRelations(ctx, input);
|
|
33
28
|
client.generateSchema();
|
|
34
29
|
client.setupDOM();
|
|
35
30
|
_routeChanged = true;
|
|
36
|
-
}
|
|
31
|
+
};
|
|
32
|
+
const unwatchRoute = useRouter().afterEach(handleRouteChange);
|
|
37
33
|
onBeforeUnmount(() => {
|
|
38
34
|
client.removeContext(ctx);
|
|
35
|
+
ids.value = /* @__PURE__ */ new Set();
|
|
39
36
|
client.generateSchema();
|
|
40
37
|
unwatchRoute();
|
|
41
38
|
});
|
|
39
|
+
return ids;
|
|
42
40
|
};
|
|
43
41
|
nuxtApp.vueApp.use(client);
|
|
44
42
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { createSchemaOrg } from "@vueuse/schema-org";
|
|
1
|
+
import { createSchemaOrg, handleNodesSSR } from "@vueuse/schema-org";
|
|
2
2
|
import { computed } from "vue";
|
|
3
3
|
import { defineNuxtPlugin } from "#app";
|
|
4
|
-
import {
|
|
4
|
+
import { useRoute } from "#imports";
|
|
5
5
|
import meta from "#build/schemaOrg.config.mjs";
|
|
6
6
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
7
7
|
const head = nuxtApp.vueApp._context.provides.usehead;
|
|
8
8
|
let _domSetup = false;
|
|
9
|
-
const
|
|
9
|
+
const client = createSchemaOrg({
|
|
10
10
|
provider: {
|
|
11
11
|
useRoute,
|
|
12
12
|
setupDOM({ schemaRef }) {
|
|
@@ -30,15 +30,9 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
30
30
|
},
|
|
31
31
|
...meta.config
|
|
32
32
|
});
|
|
33
|
-
schemaOrg.setupDOM();
|
|
34
|
-
let _uid = 0;
|
|
35
33
|
nuxtApp._useSchemaOrg = (input) => {
|
|
36
|
-
|
|
37
|
-
const ctx = schemaOrg.setupRouteContext(vm?.uid || _uid++);
|
|
38
|
-
schemaOrg.addNodesAndResolveRelations(ctx, input);
|
|
39
|
-
watchEffect(() => {
|
|
40
|
-
schemaOrg.generateSchema();
|
|
41
|
-
});
|
|
34
|
+
return handleNodesSSR(client, input);
|
|
42
35
|
};
|
|
43
|
-
|
|
36
|
+
client.setupDOM();
|
|
37
|
+
nuxtApp.vueApp.use(client);
|
|
44
38
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-schema-org",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-beta.0",
|
|
4
4
|
"description": "Nuxt module for @vueuse/schema-org",
|
|
5
5
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
27
|
"types": "./dist/types.d.ts",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
28
|
+
"require": "./dist/module.cjs",
|
|
29
|
+
"import": "./dist/module.mjs"
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"main": "dist/module.cjs",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@nuxt/kit": "3.0.0-rc.
|
|
39
|
-
"@vueuse/schema-org": "0.
|
|
38
|
+
"@nuxt/kit": "3.0.0-rc.5",
|
|
39
|
+
"@vueuse/schema-org": "0.7.0-beta.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@nuxt/module-builder": "latest",
|
|
43
|
-
"@nuxt/schema": "3.0.0-rc.
|
|
44
|
-
"nuxt": "^3.0.0-rc.
|
|
43
|
+
"@nuxt/schema": "3.0.0-rc.5",
|
|
44
|
+
"nuxt": "^3.0.0-rc.5"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "nuxi prepare ../../playgrounds/nuxt3 && nuxt-module-build",
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { createSchemaOrg, useVueUseHead } from "@vueuse/schema-org";
|
|
2
|
-
import { defineNuxtPlugin } from "#app";
|
|
3
|
-
import { getCurrentInstance, onBeforeUnmount, useRoute, useRouter } 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
|
-
client.setupDOM();
|
|
16
|
-
nuxtApp._useSchemaOrg = (input) => {
|
|
17
|
-
const vm = getCurrentInstance();
|
|
18
|
-
let ctx = client.setupRouteContext(vm.uid);
|
|
19
|
-
client.addNodesAndResolveRelations(ctx, input);
|
|
20
|
-
client.generateSchema();
|
|
21
|
-
const unwatchRoute = useRouter().afterEach(() => {
|
|
22
|
-
ctx = client.setupRouteContext(vm.uid);
|
|
23
|
-
client.removeContext(ctx);
|
|
24
|
-
client.addNodesAndResolveRelations(ctx, input);
|
|
25
|
-
client.generateSchema();
|
|
26
|
-
client.setupDOM();
|
|
27
|
-
});
|
|
28
|
-
onBeforeUnmount(() => {
|
|
29
|
-
client.removeContext(ctx);
|
|
30
|
-
client.generateSchema();
|
|
31
|
-
unwatchRoute();
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
nuxtApp.vueApp.use(client);
|
|
35
|
-
});
|