All Projects → ymmooot → nuxt-jsonld

ymmooot / nuxt-jsonld

Licence: other
A Nuxt.js module to manage JSON-LD in Vue component.

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects
typescript
32286 projects
CSS
56736 projects

Projects that are alternatives of or similar to nuxt-jsonld

nuxt-ghost
Easy Ghost content API integration with Nuxt.js.
Stars: ✭ 27 (-86.36%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-typo3
TYPO3 Frontend rendered in Vue.js and Nuxt (frontend for EXT:headless)
Stars: ✭ 66 (-66.67%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
Redirect Module
No more cumbersome redirects!
Stars: ✭ 235 (+18.69%)
Mutual labels:  seo, nuxt, nuxtjs
nuxt-speedkit
nuxt-speedkit will help you to improve the lighthouse performance score (100/100) of your website.
Stars: ✭ 401 (+102.53%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-seomatic-meta
A module for connecting Nuxt.js to the Craft CMS SEOmatic plugin via GraphQL. Nuxt-o-matic!
Stars: ✭ 28 (-85.86%)
Mutual labels:  seo, nuxt, nuxtjs
Sitemap Module
Sitemap Module for Nuxt
Stars: ✭ 539 (+172.22%)
Mutual labels:  seo, nuxt, nuxtjs
nuxt-modules
AX2's Nuxt modules
Stars: ✭ 30 (-84.85%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
global-components
Module to register global components for Nuxt.js
Stars: ✭ 57 (-71.21%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
lumen-cms
GraphQL API-First CMS based on NodeJS and Vue 2, Nuxt and Vuetify
Stars: ✭ 77 (-61.11%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-ts-module
A tiny module to use Typescript within Nuxt.js application.
Stars: ✭ 21 (-89.39%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
supabase
An easy way to integrate Supabase with NuxtJS
Stars: ✭ 39 (-80.3%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-stripejs
💳 NuxtJS module for Stripe.js which loads only when required and w/ retry mechanism
Stars: ✭ 17 (-91.41%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
applicationinsights-module
Application Insights module for NuxtJS
Stars: ✭ 14 (-92.93%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
Vuecnodejs
⚽️🎉Vue初/中级项目,CnodeJS社区重构。( a junior project of Vue.js, rewrite cnodejs.org ) 预览(DEMO):
Stars: ✭ 705 (+256.06%)
Mutual labels:  seo, nuxt, nuxtjs
k-domains
A simple module to manage multiple subdomains with just one project
Stars: ✭ 41 (-79.29%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-gsap-module
GSAP module for Nuxt.js
Stars: ✭ 183 (-7.58%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-babel
Use normal .babelrc file with your Nuxt app
Stars: ✭ 32 (-83.84%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-feature-toggle
The nuxt feature toggle module
Stars: ✭ 78 (-60.61%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
vue-plausible
Plausible Analytics Vue.js Plugin and NuxtJS Module
Stars: ✭ 107 (-45.96%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-quasar
Nuxt module for the Quasar Framework
Stars: ✭ 36 (-81.82%)
Mutual labels:  nuxt, nuxtjs, nuxt-module

nuxt-jsonld

version downloads Test codecov nuxt-jsonld

A Nuxt.js module to manage JSON-LD in Vue component.

Please read this if you are using Nuxt2.

Installation

$ yarn add nuxt-jsonld
# or
$ npm install nuxt-jsonld
// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt3';

export default defineNuxtConfig({
  modules: ['nuxt-jsonld'],
});

Usage

Composition API

You can call useJsonld with a json object.
Alternatively, you can pass a function for a reactive json, just as useHead composable.

You can use useJsonld without importing, since it is provided as Nuxt auto-imports functions.
Of course, you can import explicitly from #jsonld.

<script lang="ts" setup>
// You don't need to import explicitly.
// import { useJsonld } from '#jsonld';

// just pass a jsonld object for static jsonld
useJsonld({
  '@context': 'https://schema.org',
  '@type': 'Thing',
  name: 'static json',
});

// pass a function which returns a jsonld object for reactive jsonld
const count = ref(0);
const countUp = () => {
  count.value += 1;
};
useJsonld(() => ({
  '@context': 'https://schema.org',
  '@type': 'Thing',
  name: `reactive json: count is ${count.value}`,
}));
</script>

Options API

Make a jsonld method to your Vue components and return structured data object.

<script lang="ts">
import type { WithContext, ListItem } from 'schema-dts';

export default defineComponent({
  data() {
    return {
      breadcrumbs: [
        {
          url: 'https://example.com',
          text: 'top page',
        },
        {
          url: 'https://example.com/foo',
          text: 'foo',
        },
        {
          url: 'https://example.com/foo/bar',
          text: 'bar',
        },
      ],
    };
  },
  jsonld(): WithContext<ListItem> {
    const items = this.breadcrumbs.map((item, index) => ({
      '@type': 'ListItem',
      position: index + 1,
      item: {
        '@id': item.url,
        name: item.text,
      },
    }));
    return {
      '@context': 'https://schema.org',
      '@type': 'BreadcrumbList',
      itemListElement: items,
    };
  },
});
</script>

Options

disableOptionsAPI

Options API jsonld method is implemented using global mixin.
You can disable it if you don't use it.
(default: false)

// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt3';

export default defineNuxtConfig({
  modules: ['nuxt-jsonld'],
  'nuxt-jsonld': { disableOptionsAPI: true },
});

Or

// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt3';

export default defineNuxtConfig({
  modules: [['nuxt-jsonld', { disableOptionsAPI: true }]],
});

Tips

Hide JSON-LD

If you don't need JSON-LD tag, just return null.

useJsonld(() => {
  if (!props.product) {
    return null;
  }
  return {
    '@context': 'https://schema.org',
    '@type': 'Product',
    name: this.product.name,
  };
});

Multiple JSON-LD from one component

You can return multiple json data as an array.

[
  {
    '@context': 'https://schema.org',
    '@type': 'BreadcrumbList',
    itemListElement: [
      /* breadcrumb items*/
    ],
  },
  {
    '@context': 'https://schema.org',
    '@type': 'NewsArticle',
    mainEntityOfPage: {
      /* article info */
    },
  },
];

Or use @graph notation. #247

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].