Contentlayer 的三個面向包含
- 把內容轉換成 Data
- 結構化 Data
- 定義 Data type
在 Contentlayer 中加入新 data type 的方法
graph LR
DefineDocumentType[定義 DocumentType]:::gNode
DefineDocumentType --> MakeSource[透過 markSource 轉換]:::gNode
MakeSource --> |mdx -> json|ImportData[Import Data and Render]:::gNode
classDef web fill:#f9f,stroke:#333,stroke-width:4px;
classDef gNode fill:#7dd3fc,color:#111
classDef bNode fill:#C96868
classDef wNode fill:#FADFA1,color:#333`
定義 DocumentType
在 contentlayer.config.ts 新增需要的 data schema
| |
透過 makeSource 轉換
| |
Import Data and Render
以 Local source 為例,執行時 .contentlayer/generated 會有對應 Data Type 的資料夾 Daily 將 mdx 轉換成 json
.contentlayer/generated/_index.mjs 也可以看到自動產生的 allDailies 可使用,在對應 component 中 import 並呈現結果即可。