Skip to content

Commit

Permalink
fix: avoid duplicate tags and node prop being exposed
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Nov 25, 2024
1 parent 13391b6 commit 8489595
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 835 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"dependencies": {
"@nuxt/devtools-kit": "^1.6.1",
"@nuxt/kit": "^3.14.1592",
"@unhead/schema-org": "^1.11.11",
"nuxt-site-config": "^3.0.3",
"@unhead/schema-org": "^1.11.13",
"nuxt-site-config": "^3.0.4",
"pathe": "^1.1.2",
"pkg-types": "^1.2.1",
"sirv": "^3.0.0"
Expand Down
1,009 changes: 190 additions & 819 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/runtime/app/composables/useSchemaOrg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function useSchemaOrg<T extends Input>(input: T): ActiveHeadEntry<UnheadA
key: 'schema-org-graph',
nodes: input,
...config.scriptAttributes,
tagPriority: 'high',
}
// simple usage for dev
if (import.meta.dev) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/app/plugins/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
defineNuxtPlugin,
defineWebPage,
defineWebSite,
useSchemaOrg,
useSiteConfig,
} from '#imports'
import { useSchemaOrg } from '../composables/useSchemaOrg'
import { maybeAddIdentitySchemaOrg } from '../utils/shared'

export default defineNuxtPlugin({
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/app/plugins/i18n/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
defineWebSite,
useLocalePath,
useRuntimeConfig,
useSchemaOrg,
useSiteConfig,
} from '#imports'
import { resolveSitePath } from 'site-config-stack/urls'
import { resolveSitePath } from 'nuxt-site-config/urls'
import { hasProtocol, withHttps } from 'ufo'
import { useSchemaOrg } from '../../composables/useSchemaOrg'
import { maybeAddIdentitySchemaOrg } from '../../utils/shared'

export default defineNuxtPlugin({
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/app/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import {
createSitePathResolver,
useSiteConfig,
} from '#imports'
import { SchemaOrgUnheadPlugin, useSchemaOrg } from '@unhead/schema-org'
import { SchemaOrgUnheadPlugin } from '@unhead/schema-org/vue'
import { injectHead } from '@unhead/vue'
import { defu } from 'defu'
import { useRoute } from 'nuxt/app'
import { camelCase } from 'scule'
import { withoutTrailingSlash } from 'ufo'
import { computed } from 'vue'
import { useSchemaOrg } from '../composables/useSchemaOrg'
import { useSchemaOrgConfig } from './config'

export function initPlugin(nuxtApp: NuxtApp) {
Expand Down
10 changes: 0 additions & 10 deletions test/fixtures/basic/app.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
<script lang="ts" setup>
import { computed, definePerson, useSchemaOrg } from '#imports'
useSchemaOrg([
definePerson({
name: computed(() => {
return 'Harlan'
}),
jobTitle: 'Software Engineer',
}),
])
</script>

<template>
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ export default defineNuxtConfig({
modules: [
NuxtSchemaOrg,
],

site: {
url: 'https://nuxtseo.com',
name: 'Nuxt SEO',
},

schemaOrg: {
// identity: 'Organization',
defaults: false,
},

compatibilityDate: '2024-11-25',
})
12 changes: 12 additions & 0 deletions test/fixtures/basic/pages/about.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script lang="ts" setup>
import { defineWebPage, useSchemaOrg } from '#imports'
useSchemaOrg([defineWebPage({
'@type': 'AboutPage',
'name': 'About',
})])
</script>

<template>
<div>about</div>
</template>
6 changes: 6 additions & 0 deletions test/fixtures/basic/pages/empty.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script lang="ts" setup>
</script>

<template>
<div>about</div>
</template>

0 comments on commit 8489595

Please sign in to comment.