vue
Learn how to start using Schema.org with Vitesse.
See the playground for reference.
yarn add -D @unhead/schema-org-vue
Create a file called schemaOrg.ts
inside your modules
folder.
import { type UserModule } from '~/types'
// http://unhead.unjs.io/
export const install: UserModule = async (ctx) => {
// Disables on client build, allows 0kb runtime
if (ctx.isClient && import.meta.env.PROD)
return
const { SchemaOrgUnheadPlugin } = await import('@unhead/schema-org-vue')
ctx.head.use(SchemaOrgUnheadPlugin({
// config
host: 'https://vitesse.example.com'
}, () => {
return {
path: ctx.router.currentRoute.value.path,
...ctx.router.currentRoute.value.meta,
}
}))
}
See the User Config page for all options you can pass.
Modify your vite.config.ts
to enable auto imports of all composables and components.
import { SchemaOrgResolver, schemaAutoImports } from '@unhead/schema-org-vue'
export default defineConfig({
plugins: [
// ...
Components({
resolvers: [
// auto-import @unhead/schema-org-vue components
SchemaOrgResolver(),
],
}),
AutoImport({
imports: [
// auto-import @unhead/schema-org-vuecomposables
{
'@unhead/schema-org-vue': schemaAutoImports,
},
],
}),
]
})
To quickly add the recommended Schema.org to all pages, you can make use Runtime Inferences.
This should be done in your App.vue
.
<script lang="ts" setup>
useSchemaOrg([
// @todo Select Identity: http://unhead.unjs.io/schema-org/guides/identity
defineWebSite({
name: 'My Awesome Website',
}),
defineWebPage(),
])
</script>
Your Vitesse app is now serving basic Schema.org, congrats! 🎉
The next steps are: