nuxt-schema-org 0.6.0 → 0.6.4
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 +4 -1
- package/dist/runtime/{plugin.d.ts → plugin.client.d.ts} +0 -0
- package/dist/runtime/plugin.client.mjs +52 -0
- package/dist/runtime/plugin.server.d.ts +2 -0
- package/dist/runtime/plugin.server.mjs +44 -0
- package/package.json +21 -21
- package/dist/runtime/plugin.mjs +0 -35
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -14,7 +14,10 @@ const module = defineNuxtModule({
|
|
|
14
14
|
},
|
|
15
15
|
async setup(config, nuxt) {
|
|
16
16
|
const { resolve } = createResolver(import.meta.url);
|
|
17
|
-
|
|
17
|
+
const runtimeDir = resolve("./runtime");
|
|
18
|
+
nuxt.options.build.transpile.push(runtimeDir);
|
|
19
|
+
addPlugin(resolve(runtimeDir, "plugin.client"));
|
|
20
|
+
addPlugin(resolve(runtimeDir, "plugin.server"));
|
|
18
21
|
nuxt.options.build.transpile.push("@vueuse/schema-org");
|
|
19
22
|
addTemplate({
|
|
20
23
|
filename: "schemaOrg.config.mjs",
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
let _routeChanged = false;
|
|
16
|
+
const { serverRendered } = nuxtApp.payload;
|
|
17
|
+
if (serverRendered) {
|
|
18
|
+
const rootCtx = client.setupRouteContext(1);
|
|
19
|
+
const schemaOrg = document.querySelector('head script[data-id="schema-org-graph"]')?.innerHTML;
|
|
20
|
+
if (schemaOrg) {
|
|
21
|
+
for (const node of JSON.parse(schemaOrg)["@graph"])
|
|
22
|
+
client.addNode(node, rootCtx);
|
|
23
|
+
client.generateSchema();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
nuxtApp._useSchemaOrg = (input) => {
|
|
27
|
+
const vm = getCurrentInstance();
|
|
28
|
+
let ctx = client.setupRouteContext(vm.uid);
|
|
29
|
+
if (!serverRendered || _routeChanged) {
|
|
30
|
+
client.addNodesAndResolveRelations(ctx, input);
|
|
31
|
+
if (!serverRendered)
|
|
32
|
+
client.generateSchema();
|
|
33
|
+
}
|
|
34
|
+
const unwatchRoute = useRouter().afterEach(() => {
|
|
35
|
+
ctx = client.setupRouteContext(vm.uid);
|
|
36
|
+
client.removeContext(ctx);
|
|
37
|
+
client.addNodesAndResolveRelations(ctx, input);
|
|
38
|
+
client.generateSchema();
|
|
39
|
+
client.setupDOM();
|
|
40
|
+
_routeChanged = true;
|
|
41
|
+
});
|
|
42
|
+
onBeforeUnmount(() => {
|
|
43
|
+
client.removeContext(ctx);
|
|
44
|
+
client.generateSchema();
|
|
45
|
+
unwatchRoute();
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
if (!serverRendered) {
|
|
49
|
+
client.setupDOM();
|
|
50
|
+
}
|
|
51
|
+
nuxtApp.vueApp.use(client);
|
|
52
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createSchemaOrg } from "@vueuse/schema-org";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { defineNuxtPlugin } from "#app";
|
|
4
|
+
import { getCurrentInstance, useRoute, watchEffect } from "#imports";
|
|
5
|
+
import meta from "#build/schemaOrg.config.mjs";
|
|
6
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
7
|
+
const head = nuxtApp.vueApp._context.provides.usehead;
|
|
8
|
+
let _domSetup = false;
|
|
9
|
+
const schemaOrg = createSchemaOrg({
|
|
10
|
+
provider: {
|
|
11
|
+
useRoute,
|
|
12
|
+
setupDOM({ schemaRef }) {
|
|
13
|
+
if (_domSetup)
|
|
14
|
+
return;
|
|
15
|
+
head.addHeadObjs(computed(() => {
|
|
16
|
+
return {
|
|
17
|
+
script: [
|
|
18
|
+
{
|
|
19
|
+
"type": "application/ld+json",
|
|
20
|
+
"data-id": "schema-org-graph",
|
|
21
|
+
"key": "schema-org-graph",
|
|
22
|
+
"children": schemaRef.value
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
};
|
|
26
|
+
}));
|
|
27
|
+
_domSetup = true;
|
|
28
|
+
},
|
|
29
|
+
name: "nuxt"
|
|
30
|
+
},
|
|
31
|
+
...meta.config
|
|
32
|
+
});
|
|
33
|
+
schemaOrg.setupDOM();
|
|
34
|
+
let _uid = 0;
|
|
35
|
+
nuxtApp._useSchemaOrg = (input) => {
|
|
36
|
+
const vm = getCurrentInstance();
|
|
37
|
+
const ctx = schemaOrg.setupRouteContext(vm?.uid || _uid++);
|
|
38
|
+
schemaOrg.addNodesAndResolveRelations(ctx, input);
|
|
39
|
+
watchEffect(() => {
|
|
40
|
+
schemaOrg.generateSchema();
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
nuxtApp.vueApp.use(schemaOrg);
|
|
44
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-schema-org",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Nuxt module for @vueuse/schema-org",
|
|
5
|
+
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"funding": "https://github.com/sponsors/harlan-zw",
|
|
8
|
+
"homepage": "https://github.com/vueuse/schema-org#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/vueuse/schema-org.git",
|
|
12
|
+
"directory": "packages/nuxt"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/vueuse/schema-org/issues"
|
|
16
|
+
},
|
|
5
17
|
"keywords": [
|
|
6
18
|
"schema-org",
|
|
7
19
|
"nuxt",
|
|
@@ -9,38 +21,26 @@
|
|
|
9
21
|
"nuxt-module",
|
|
10
22
|
"nuxt3"
|
|
11
23
|
],
|
|
12
|
-
"
|
|
13
|
-
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/vueuse/schema-org.git",
|
|
17
|
-
"directory": "packages/nuxt"
|
|
18
|
-
},
|
|
19
|
-
"funding": "https://github.com/sponsors/harlan-zw",
|
|
20
|
-
"main": "dist/module.cjs",
|
|
21
|
-
"types": "dist/types.d.ts",
|
|
24
|
+
"sideEffects": false,
|
|
22
25
|
"exports": {
|
|
23
26
|
".": {
|
|
24
|
-
"
|
|
27
|
+
"types": "./dist/types.d.ts",
|
|
25
28
|
"require": "./dist/module.cjs",
|
|
26
|
-
"
|
|
29
|
+
"import": "./dist/module.mjs"
|
|
27
30
|
}
|
|
28
31
|
},
|
|
32
|
+
"main": "dist/module.cjs",
|
|
33
|
+
"types": "dist/types.d.ts",
|
|
29
34
|
"files": [
|
|
30
35
|
"dist"
|
|
31
36
|
],
|
|
32
|
-
"sideEffects": false,
|
|
33
|
-
"homepage": "https://github.com/vueuse/schema-org#readme",
|
|
34
|
-
"bugs": {
|
|
35
|
-
"url": "https://github.com/vueuse/schema-org/issues"
|
|
36
|
-
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@nuxt/kit": "3.0.0-rc.
|
|
39
|
-
"@vueuse/schema-org": "0.6.
|
|
38
|
+
"@nuxt/kit": "3.0.0-rc.4",
|
|
39
|
+
"@vueuse/schema-org": "0.6.4"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@nuxt/module-builder": "latest",
|
|
43
|
-
"@nuxt/schema": "
|
|
43
|
+
"@nuxt/schema": "3.0.0-rc.4",
|
|
44
44
|
"nuxt": "^3.0.0-rc.2"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
package/dist/runtime/plugin.mjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { createSchemaOrg, useVueUseHead } from "@vueuse/schema-org";
|
|
2
|
-
import { defineNuxtPlugin } from "#app";
|
|
3
|
-
import { getCurrentInstance, onBeforeUnmount, useRoute, watch, watchEffect } 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 schemaOrg = createSchemaOrg({
|
|
8
|
-
provider: {
|
|
9
|
-
useRoute,
|
|
10
|
-
setupDOM: useVueUseHead(head),
|
|
11
|
-
name: "nuxt"
|
|
12
|
-
},
|
|
13
|
-
...meta.config
|
|
14
|
-
});
|
|
15
|
-
nuxtApp.vueApp.use(schemaOrg);
|
|
16
|
-
let _uid = 0;
|
|
17
|
-
nuxtApp._useSchemaOrg = (input) => {
|
|
18
|
-
const vm = getCurrentInstance();
|
|
19
|
-
const ctx = schemaOrg.setupRouteContext(vm?.uid || _uid++);
|
|
20
|
-
schemaOrg.addNodesAndResolveRelations(ctx, input);
|
|
21
|
-
watch(useRoute(), () => {
|
|
22
|
-
schemaOrg.removeContext(ctx);
|
|
23
|
-
schemaOrg.addNodesAndResolveRelations(ctx, input);
|
|
24
|
-
schemaOrg.generateSchema();
|
|
25
|
-
});
|
|
26
|
-
watchEffect(() => {
|
|
27
|
-
schemaOrg.generateSchema();
|
|
28
|
-
});
|
|
29
|
-
onBeforeUnmount(() => {
|
|
30
|
-
schemaOrg.removeContext(ctx);
|
|
31
|
-
schemaOrg.generateSchema();
|
|
32
|
-
});
|
|
33
|
-
schemaOrg.setupDOM();
|
|
34
|
-
};
|
|
35
|
-
});
|