1

https://nuxtjs.org/examples/seo-twitter-ogにある SEO ドキュメントの指示に従って、OpenGraph タグを Nuxt.js アプリに統合しました。

コンポーネントを使用して子コンポーネントからタグを設定していSocialHeadます。このコンポーネントの内容は次のとおりです。

<template>
  <span v-if="false" />
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: '',
    },
    description: {
      type: String,
      default: '',
    },
    url: {
      type: String,
      default: '',
    },
    image: {
      type: String,
      default: '/images/hero/brain-og.png',
    },
  },
  head() {
    return {
      title: this.title,
      meta: [
        {
          hid: 'og:title',
          name: 'og:title',
          content: this.title.replace(' - M.academy', ''),
        },
        {
          hid: 'description',
          name: 'description',
          content: this.description,
        },
        {
          hid: 'og:description',
          property: 'og:description',
          content: this.description,
        },
        {
          hid: 'og:url',
          property: 'og:url',
          content: process.env.baseUrl + this.url,
        },
        {
          hid: 'og:type',
          property: 'og:type',
          content: 'website',
        },
        {
          hid: 'og:image',
          property: 'og:image',
          content: process.env.baseUrl + this.image,
        },
        {
          hid: 'og:image:secure_url',
          property: 'og:image:secure_url',
          content: process.env.baseUrl + this.image,
        },
        {
          hid: 'og:image:alt',
          property: 'og:image:alt',
          content: this.description,
        },
        {
          hid: 'twitter:title',
          name: 'twitter:title',
          content: this.title.replace(' - M.academy', ''),
        },
        {
          hid: 'twitter:card',
          name: 'twitter:card',
          content: 'summary_large_image',
        },
        {
          hid: 'twitter:image',
          name: 'twitter:image',
          content: process.env.baseUrl + this.image,
        },
        {
          hid: 'twitter:description',
          name: 'twitter:description',
          content: this.description,
        },
        {
          hid: 'twitter:site',
          name: 'twitter:site',
          content: '@mdotacademy',
        },
        {
          hid: 'twitter:creator',
          name: 'twitter:creator',
          content: '@markshust',
        },
      ],
    }
  },
}
</script>

私は Google Chrome の「Open Graph Preview」拡張機能をローカルで使用していますが、それらはすべて正しく動作し、プレビューしているように見えます。

ここに画像の説明を入力 ここに画像の説明を入力

ただし、これらの更新を本番環境にデプロイして再度確認すると、使用しているすべての Open Graph プレビュー ツールでタグが見つからないようです。

ここに画像の説明を入力 ここに画像の説明を入力

また、LinkedIn と Twitter のオープン グラフ プレビュー ツールを次の場所でテストしました。

ページのソースを表示し、 https://www.opengraph.xyz/のようなツールを使用しているときにタグが表示されるため、少し行き詰まっていますが、実際の LinkedIn および Twitter 検証ツールは使用していません。

私がテストしたページはhttps://m.academy/courses/build-12-factor-nodejs-app-docker/です

4

1 に答える 1