เอกสารDocumentationMdxFrontmatter

Frontmatter

เรียนรู้วิธีใช้ frontmatter ในไฟล์ MDX

frontmatter เป็นส่วนสำคัญของไฟล์ MDX ใช้สำหรับกำหนดข้อมูลเกี่ยวกับเนื้อหาของไฟล์ เช่น title, description, author, publication date ฯลฯ

ส่วนหัวเมตาดาต้าถูกกำหนดไว้ที่จุดเริ่มต้นของไฟล์ ระหว่าง --- (ขีดกลางสามตัว) ตอนต้นและตอนท้าย

รูปแบบ

ส่วนหัวเมตาดาต้าถูกกำหนดในรูปแบบ key-value โดย key คือชื่อของเมตาดาต้า และ value คือเนื้อหาของเมตาดาต้านั้น

ตัวอย่าง:

---
title: Document title
description: Document description
---

เมตาดาต้าที่ใช้ได้จะแตกต่างกันไปตามประเภทของเอกสาร (เอกสาร, blog post ฯลฯ)

เมตาดาต้าสำหรับเอกสาร

  • title
  • description
  • links
    • source
    • docs
    • blog
    • api

ตัวอย่าง:

---
title: Document title
description: Document description
links:
  source: https://google.com
  docs: /docs
  blog: /blog
  api: https://google.com
---

เมตาดาต้าสำหรับ blog posts

  • title
  • excerpt
  • date
  • author_id
  • og_image
  • tags
  • links
    • source
    • docs
    • blog
    • api

ตัวอย่าง:

---
title: Post title
date: 2024-08-07 22:33:00
excerpt: Post excerpt
author_id: daltonmenezes
og_image: introducing-blogs-og.jpg
links:
  source: https://google.com
  docs: /docs
  blog: /blog
  api: https://google.com
tags: [next.js, open-graph, blog]
---