nuxt-structured-data
v0.0.3
Published
[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![License][license-src]][license-href]
Downloads
4
Readme
nuxt-structured-data
Setup
- Add
nuxt-structured-data
dependency to your project
yarn add nuxt-structured-data # or npm install nuxt-structured-data
- Add
nuxt-structured-data
to themodules
section ofnuxt.config.js
{
modules: [
'nuxt-structured-data',
]
}
Usage
In every page, this module will inject a json-ld script based on structuredData
property value.
Example
pages/schools/_slug.vue
export default {
async asyncData({ app, error, params }) {
try {
const response = await app.$axios.get(`SCHOOL_API_ROUTE/${params.slug}`)
return {
structuredData: {
"@type": "School",
address: {
"@type": "PostalAddress",
addressLocality: response.data.city,
addressCountry: "FR",
streetAddress: response.data.street,
postalCode: response.data.zip_code
},
email: response.data.email,
telephone: response.data.tel,
logo: response.data.logo
}
};
} catch (err) {
error({
statusCode: 404,
message: "Cannot find this school"
})
}
}
}
Development
- Clone this repository
- Install dependencies using
yarn install
ornpm install
- Start development server using
npm run dev
License
Copyright (c) Quentin Neyraud [email protected]