contentlayerdev / contentlayerdev/contentlayer
Add support for named scopes ("computed collection")
- 主要語言
- TypeScript
- 星號
- 3.5k
- 分支
- 192
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Defining a document type brings the entirety of content for that document into the data object that we import into pages. I'm potentially importing much more information than I need to work with. It also forces me to write filtering logic in the template. And while this is a fairly typical pattern with Next.js, it's not a pleasant developer experience.
Proposal is to allow for named scopes when defining a document type. Something like this:
```js
const Doc = defineDocumentType(() => ({
name: "Doc",
// ...
fields: { /* ... */ },
scopes: [
{
name: "mostRecent",
resolve: (docs) => /* sorting/filtering logic ... */
}
]
))
```
I don't have a strong opinion on how this would then be used, but maybe something like this:
```js
import { allDocs, mostRecentDocs } from ".contentlayer/data"
```
The key decision here is finding a balance between being too magical (appending "Docs" to the scope name) and having to validate that scopes across all types be unique.
(Inpsired from a conversation with @smnh.)
貢獻指南
研究方向
首先追蹤 defineDocumentType 和產生的 .contentlayer/data 匯出。檢視文件欄位目前如何成為頁面資料,然後在實作之前確定 scope 的命名和唯一性行為。完成標準是:具名的 scope 可以定義排序或篩選,並透過有文件說明的匯入模式公開。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- next.js, typescript
- 領域
- data, developer-experience, tooling
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 30/100