contentlayerdev / contentlayerdev/contentlayer

Add support for named scopes ("computed collection")

オープン
#71 コメント 1 件 リアクション 6 件 担当者 0 名 GitHub で見る
feature
主要言語
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 のエクスポートを追跡することから始めます。ドキュメントのフィールドが現在どのようにページデータになるかを確認し、その後、実装前にスコープの命名と一意性の挙動を明確にします。名前付きスコープでソートまたはフィルタリングを定義でき、文書化されたインポートパターンを通じて公開されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
next.js, typescript
領域
data, developer-experience, tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。