nuxt-schema-org 0.6.1 → 0.6.5

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 CHANGED
@@ -4,5 +4,5 @@
4
4
  "bridge": false
5
5
  },
6
6
  "name": "nuxt-schema-org",
7
- "version": "0.6.1"
7
+ "version": "0.6.5"
8
8
  }
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,9 +27,14 @@ const module = defineNuxtModule({
13
27
  autoImportComponents: true
14
28
  },
15
29
  async setup(config, nuxt) {
16
- const { resolve } = createResolver(import.meta.url);
17
- addPlugin(resolve("./runtime/plugin"));
18
- nuxt.options.build.transpile.push("@vueuse/schema-org");
30
+ const { resolve, resolvePath } = createResolver(import.meta.url);
31
+ const runtimeDir = resolve("./runtime");
32
+ nuxt.options.build.transpile.push(runtimeDir);
33
+ addPlugin(resolve(runtimeDir, "plugin.client"));
34
+ addPlugin(resolve(runtimeDir, "plugin.server"));
35
+ const schemaOrgPath = dirname(await resolvePath("@vueuse/schema-org"));
36
+ nuxt.options.alias["@vueuse/schema-org"] = schemaOrgPath;
37
+ nuxt.options.build.transpile.push(schemaOrgPath);
19
38
  addTemplate({
20
39
  filename: "schemaOrg.config.mjs",
21
40
  getContents: () => `export default ${JSON.stringify({ config })}`
@@ -33,7 +52,7 @@ const module = defineNuxtModule({
33
52
  addComponent({
34
53
  name: component,
35
54
  export: component,
36
- filePath: "@vueuse/schema-org"
55
+ filePath: schemaOrgPath
37
56
  });
38
57
  });
39
58
  }
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,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -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.1",
3
+ "version": "0.6.5",
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,39 +21,27 @@
9
21
  "nuxt-module",
10
22
  "nuxt3"
11
23
  ],
12
- "license": "MIT",
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
- "import": "./dist/module.mjs",
27
+ "types": "./dist/types.d.ts",
25
28
  "require": "./dist/module.cjs",
26
- "types": "./dist/types.d.ts"
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.2",
39
- "@vueuse/schema-org": "0.6.1"
38
+ "@nuxt/kit": "3.0.0-rc.4",
39
+ "@vueuse/schema-org": "0.6.5"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@nuxt/module-builder": "latest",
43
- "@nuxt/schema": "^3.0.0-rc.2",
44
- "nuxt": "^3.0.0-rc.2"
43
+ "@nuxt/schema": "3.0.0-rc.4",
44
+ "nuxt": "^3.0.0-rc.4"
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, 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
- });