# νŽ˜μ΄μ§€ 메타 정보 μ„€μ •

λ„‰μŠ€νŠΈμ—μ„œ νŽ˜μ΄μ§€μ˜ 메타(meta) νƒœκ·Έ 정보λ₯Ό μ„€μ •ν•˜λŠ” 방법에 λŒ€ν•΄ μ•Œμ•„λ΄…λ‹ˆλ‹€.

# νŽ˜μ΄μ§€ head νƒœκ·Έ μ„€μ •

λ„‰μŠ€νŠΈλ‘œ μ œμž‘λœ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ˜ head νƒœκ·Έ 값은 기본적으둜 λ„‰μŠ€νŠΈ μ„€μ • νŒŒμΌμ— μ •μ˜λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

// nuxt.config.js
export default {
  head: {
    title: 'learn-nuxt',
    htmlAttrs: {
      lang: 'en',
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
  },
}

μœ„ μ½”λ“œκ°€ 적용된 νŽ˜μ΄μ§€λŠ” λΈŒλΌμš°μ €μ— κ·Έλ €μ‘Œμ„ λ•Œ λ‹€μŒκ³Ό 같은 HTML μ½”λ“œλ‘œ λ³€ν™˜λ©λ‹ˆλ‹€.

<html lang="en">
<head>
  <title>learn-nuxt</title>
  <meta data-n-head="ssr" charset="utf-8">
  <meta data-n-head="ssr" name="viewport" content="width=device-width, initial-scale=1">
  <meta data-n-head="ssr" data-hid="description" name="description" content="">
  <link data-n-head="ssr" rel="icon" type="image/x-icon" href="/favicon.ico">
</head>
<!-- ... -->

이 섀정은 λͺ¨λ“  νŽ˜μ΄μ§€μ— λ™μΌν•˜κ²Œ μ μš©λ©λ‹ˆλ‹€. μ—¬κΈ°μ„œ νŽ˜μ΄μ§€λ³„λ‘œ λ‹€λ₯Έ head νƒœκ·Έλ₯Ό μ„€μ •ν•˜κ³  μ‹Άλ‹€λ©΄ μ–΄λ–»κ²Œ ν•΄μ•Ό ν• κΉŒμš”?

# νŽ˜μ΄μ§€λ³„ head νƒœκ·Έ μ„€μ •

νŽ˜μ΄μ§€λ³„λ‘œ λ‹€λ₯Έ head νƒœκ·Έλ₯Ό μ„€μ •ν•˜κ³  싢은 κ²½μš°μ—λŠ” 각 νŽ˜μ΄μ§€ μ»΄ν¬λ„ŒνŠΈμ— μ•„λž˜μ™€ 같은 속성을 μΆ”κ°€ν•©λ‹ˆλ‹€.

<!-- page/home.vue -->
<script>
export default {
  data() {
    return {
      str: 'hi'
    }
  },

  head: {
    title: 'νŽ˜μ΄μ§€ 타이틀',
    meta: [
      {
        hid: 'description',
        name: 'description',
        content: 'νŽ˜μ΄μ§€ μ„€λͺ… λ‚΄μš©',
      },
    ],
    link: [
      {
        rel: 'stylesheet',
        href: 'https://fonts.googleapis.com/css?family=Roboto&display=swap'
      }
    ]
  },
}
</script>

λ§Œμ•½ μ»΄ν¬λ„ŒνŠΈμ— μ •μ˜λ˜μ–΄ μžˆλŠ” λ·° μΈμŠ€ν„΄μŠ€ λ°μ΄ν„°λ‚˜ μ»΄ν“¨ν‹°λ“œ 속성을 메타 νƒœκ·Έμ— κ°’μœΌλ‘œ μ—°κ²°ν•˜κ³  μ‹Άλ‹€λ©΄ μ•„λž˜μ™€ 같이 ν•¨μˆ˜ ν˜•νƒœλ‘œ μž‘μ„±ν•©λ‹ˆλ‹€.

<!-- pages/products/_id.vue -->
<script>
export default {
  data() {
    return {
      productName: 'λ°”μ‚­ν•œ 과자'
    }
  },

  head() {
    return {
      title: `μƒν’ˆ 상세 νŽ˜μ΄μ§€ - ${this.productName}`
    }
  },
}
</script>

기타 meta νƒœκ·Έ μ„€μ • 방법에 λŒ€ν•΄μ„œλŠ” μ•„λž˜ λ¬Έμ„œλ₯Ό μ°Έκ³ ν•©λ‹ˆλ‹€.

# Open Graph νƒœκ·Έ μ„€μ •

OG(Open Graph) νƒœκ·Έλž€ νŠΉμ • νŽ˜μ΄μ§€μ˜ 링크λ₯Ό SNS μƒμ—μ„œ κ³΅μœ ν•  λ•Œ ν•΄λ‹Ή νŽ˜μ΄μ§€μ˜ 정보가 잘 λ“œλŸ¬λ‚  수 μžˆλ„λ‘ 지원해 μ£ΌλŠ” 메타 νƒœκ·Έμž…λ‹ˆλ‹€.

og-tag

μœ„μ™€ 같이 νŽ˜μ΄μŠ€λΆμ΄λ‚˜ μΉ΄μΉ΄μ˜€ν†‘ λ“± SNS μƒμœΌλ‘œ νŠΉμ • 링크λ₯Ό κ³΅μœ ν•˜λ©΄ ν•΄λ‹Ή νŽ˜μ΄μ§€μ˜ title, description, image λ“±μ˜ μ‚¬μ΄νŠΈ 정보λ₯Ό λ°”λ‘œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€. μ•žμ—μ„œ μ•ˆλ‚΄ν•œ head 속성을 μ΄μš©ν•΄ νŽ˜μ΄μ§€ λ³„λ‘œ λ‹€μŒκ³Ό 같이 μ •μ˜ν•©λ‹ˆλ‹€.

<script>
export default {
  head: {
    title: 'μƒν’ˆ 상세 νŽ˜μ΄μ§€',
    meta: [
      {
        hid: 'og:title',
        property: 'og:title',
        content: 'μƒν’ˆ 상세 νŽ˜μ΄μ§€'
      },
      {
        hid: 'og:description',
        property: 'og:description',
        content: 'μƒν’ˆμ˜ 상세 정보λ₯Ό ν™•μΈν•΄λ³΄μ„Έμš”'
      },
      {
        hid: 'og:image',
        property: 'og:image',
        content: 'http://placeimg.com/640/480/fashion'
      },
    ]
  }
}
</script>

OG νƒœκ·Έμ˜ 좔가적인 속성듀은 μ•„λž˜ 곡식 λ¬Έμ„œλ₯Ό μ°Έκ³ ν•˜μ„Έμš” πŸ˜ƒ

Open Graph Protocol (opens new window)