nuxt-schema-org 3.0.0 → 3.1.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/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
  <p align="center">
13
- The quickest and easiest way to build Schema.org graphs for Nuxt.
13
+ The quickest and easiest way to build Schema.org graphs for Nuxt. Powered by [Unhead](https://unhead.unjs.io).
14
14
  </p>
15
15
 
16
16
  <p align="center">
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.7.0",
6
6
  "bridge": false
7
7
  },
8
- "version": "3.0.0"
8
+ "version": "3.1.0"
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,6 +1,49 @@
1
- import { defineNuxtModule, useLogger, createResolver, addPlugin, addComponent } from '@nuxt/kit';
1
+ import { useNuxt, defineNuxtModule, useLogger, createResolver, addPlugin, addComponent } from '@nuxt/kit';
2
2
  import { schemaOrgComponents, schemaOrgAutoImports } from '@unhead/schema-org/vue';
3
3
  import { installNuxtSiteConfig } from 'nuxt-site-config-kit';
4
+ import { existsSync } from 'node:fs';
5
+
6
+ const DEVTOOLS_UI_ROUTE = "/__nuxt-schema-org";
7
+ const DEVTOOLS_UI_LOCAL_PORT = 3030;
8
+ function setupDevToolsUI(options, resolve, nuxt = useNuxt()) {
9
+ const clientPath = resolve("./client");
10
+ const isProductionBuild = existsSync(clientPath);
11
+ if (isProductionBuild) {
12
+ nuxt.hook("vite:serverCreated", async (server) => {
13
+ const sirv = await import('sirv').then((r) => r.default || r);
14
+ server.middlewares.use(
15
+ DEVTOOLS_UI_ROUTE,
16
+ sirv(clientPath, { dev: true, single: true })
17
+ );
18
+ });
19
+ } else {
20
+ nuxt.hook("vite:extendConfig", (config) => {
21
+ config.server = config.server || {};
22
+ config.server.proxy = config.server.proxy || {};
23
+ config.server.proxy[DEVTOOLS_UI_ROUTE] = {
24
+ target: `http://localhost:${DEVTOOLS_UI_LOCAL_PORT}${DEVTOOLS_UI_ROUTE}`,
25
+ changeOrigin: true,
26
+ followRedirects: true,
27
+ rewrite: (path) => path.replace(DEVTOOLS_UI_ROUTE, "")
28
+ };
29
+ });
30
+ }
31
+ nuxt.hook("devtools:customTabs", (tabs) => {
32
+ tabs.push({
33
+ // unique identifier
34
+ name: "nuxt-schema-org",
35
+ // title to display in the tab
36
+ title: "Schema.org",
37
+ // any icon from Iconify, or a URL to an image
38
+ icon: "carbon:chart-relationship",
39
+ // iframe view
40
+ view: {
41
+ type: "iframe",
42
+ src: DEVTOOLS_UI_ROUTE
43
+ }
44
+ });
45
+ });
46
+ }
4
47
 
5
48
  const module = defineNuxtModule({
6
49
  meta: {
@@ -16,7 +59,7 @@ const module = defineNuxtModule({
16
59
  enabled: true,
17
60
  debug: false,
18
61
  reactive: nuxt.options.dev || !nuxt.options.ssr,
19
- minify: process.env.NODE_ENV === "production"
62
+ minify: import.meta.env.PROD
20
63
  };
21
64
  },
22
65
  async setup(config, nuxt) {
@@ -49,6 +92,8 @@ const module = defineNuxtModule({
49
92
  nuxt.hooks.hook("imports:sources", (autoImports) => {
50
93
  autoImports.unshift(...schemaOrgAutoImports);
51
94
  });
95
+ if (config.debug || nuxt.options.dev)
96
+ setupDevToolsUI(config, resolve);
52
97
  }
53
98
  });
54
99
 
@@ -1,5 +1,7 @@
1
- import { PluginSchemaOrg } from "@unhead/schema-org";
2
- import { defineNuxtPlugin, injectHead, unref, useRouter, useRuntimeConfig, useSiteConfig } from "#imports";
1
+ import { SchemaOrgUnheadPlugin } from "@unhead/schema-org";
2
+ import { joinURL } from "ufo";
3
+ import { computed } from "vue";
4
+ import { defineNuxtPlugin, injectHead, useHead, useRouter, useRuntimeConfig, useSiteConfig } from "#imports";
3
5
  export default defineNuxtPlugin({
4
6
  name: "nuxt-schema-org:init",
5
7
  enforce: "post",
@@ -7,23 +9,31 @@ export default defineNuxtPlugin({
7
9
  const head = injectHead();
8
10
  const config = useRuntimeConfig().public["nuxt-schema-org"];
9
11
  const router = useRouter();
10
- const currentRoute = router.currentRoute;
11
12
  const siteConfig = useSiteConfig();
12
- head.use(PluginSchemaOrg({
13
- minify: config.minify,
14
- resolveMeta: async () => {
15
- const route = unref(currentRoute);
16
- const meta = {
17
- host: siteConfig.url,
18
- trailingSlash: siteConfig.trailingSlash,
19
- inLanguage: siteConfig.currentLocale || siteConfig.defaultLocale,
20
- ...siteConfig,
21
- ...route.meta,
22
- path: route.path
23
- };
13
+ const schemaOrg = computed(() => {
14
+ return {
15
+ ...router.currentRoute.value.meta,
16
+ ...siteConfig,
17
+ url: joinURL(siteConfig.url, router.currentRoute.value.path),
18
+ host: siteConfig.url,
19
+ inLanguage: siteConfig.currentLocale || siteConfig.defaultLocale,
20
+ path: router.currentRoute.value.path
21
+ };
22
+ });
23
+ useHead({
24
+ templateParams: {
25
+ schemaOrg
26
+ }
27
+ });
28
+ head.use(
29
+ SchemaOrgUnheadPlugin({}, async () => {
30
+ const meta = {};
24
31
  await nuxtApp.hooks.callHook("schema-org:meta", meta);
25
32
  return meta;
26
- }
27
- }));
33
+ }, {
34
+ minify: config.minify,
35
+ trailingSlash: siteConfig.trailingSlash
36
+ })
37
+ );
28
38
  }
29
39
  });
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "nuxt-schema-org",
3
3
  "type": "module",
4
- "version": "3.0.0",
5
- "packageManager": "pnpm@8.7.5",
4
+ "version": "3.1.0",
5
+ "packageManager": "pnpm@8.10.0",
6
6
  "description": "Schema.org for Nuxt",
7
7
  "author": "Harlan Wilton <harlan@harlanzw.com>",
8
8
  "license": "MIT",
@@ -35,23 +35,27 @@
35
35
  "dist"
36
36
  ],
37
37
  "dependencies": {
38
- "@nuxt/kit": "^3.7.3",
39
- "@unhead/schema-org": "^1.7.3",
40
- "nuxt-site-config": "^1.2.1",
41
- "nuxt-site-config-kit": "^1.2.1",
42
- "pathe": "^1.1.1"
38
+ "@nuxt/devtools-kit": "^1.0.0",
39
+ "@nuxt/devtools-ui-kit": "^1.0.0",
40
+ "@nuxt/kit": "^3.8.0",
41
+ "@unhead/schema-org": "^1.8.2",
42
+ "nuxt-site-config": "^1.5.5",
43
+ "nuxt-site-config-kit": "^1.5.5",
44
+ "pathe": "^1.1.1",
45
+ "shiki-es": "^0.14.0",
46
+ "sirv": "^2.0.3"
43
47
  },
44
48
  "devDependencies": {
45
- "@antfu/eslint-config": "^0.42.0",
46
- "@nuxt/module-builder": "^0.5.1",
47
- "@nuxt/schema": "^3.7.3",
48
- "@nuxt/test-utils": "^3.7.3",
49
+ "@antfu/eslint-config": "^1.0.0",
50
+ "@nuxt/module-builder": "^0.5.2",
51
+ "@nuxt/schema": "^3.8.0",
52
+ "@nuxt/test-utils": "^3.8.0",
49
53
  "@nuxtjs/eslint-config-typescript": "^12.1.0",
50
54
  "bumpp": "^9.2.0",
51
- "eslint": "8.49.0",
52
- "nuxt": "^3.7.3",
55
+ "eslint": "8.52.0",
56
+ "nuxt": "^3.8.0",
53
57
  "nuxt-windicss": "^2.6.1",
54
- "vitest": "0.34.4"
58
+ "vitest": "0.34.6"
55
59
  },
56
60
  "scripts": {
57
61
  "lint": "eslint . --fix",