Support plaintext contentType
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 28/100
- Issue 類型
- 功能
- 描述清晰度
- 需要釐清
- 活躍度
- 停滯
- 技術堆疊
- react, typescript
- 領域
- content
研究方向
從所示的 defineDocumentType 設定開始,追蹤 contentType 如何驗證,以及檔案內容如何到達 computedField;issue 沒有指出 repository 中的檔案或測試。要完成這項工作,需要就 contentType: 'plain' 的行為、其預設設定與向後相容政策、文字與二進位內容的處理方式,以及相應的文件和測試達成共識。
由索引模型根據 Issue 內容生成。
描述
I am trying to use .tsx files as input for a documentType. My use case is to turn them into JSON objects representing the associated components' properties via react-docgen-typescript.
The plan would be to have a computedField that uses react-docgen-typescript to parse the raw file content into a JSON object representing the properties.
But, Contentlayer doesn't support .tsxfiles, yet.
I tried this with the following config, assuming contentType: 'data' would just load the content of the files but was taught on Discord that it is only for frontmatter.
export const ComponentProp = defineDocumentType(() => ({
name: 'ComponentProp',
filePathPattern: `lib-src/**/*.tsx`,
contentType: 'data',
}));
Proposed solution
Add a contentType: 'plain' that just loads the entire file and leaves processing up to the user.
This contentType would solve my use-case but even better, enable users of Contentlayer to use it for their use-cases which we are not yet aware of or that are needed by only a small minority.
Implications
Default contentType
Currently, Contentlayer treats files as markdown by default. Assuming we add a 'plain' type I would suggest changing this behavior to read files as plaintext by default. That, however, could be a breaking change!
I am not 100% sure how Contentlayer currently treats files but use-cases of people who currently parse non *.md files as markdown would be broken.
Plain text defaults
Going with the above Contentlayer would start to treat all file extensions it doesn't know as plaintext.
This implies that Contentlayer assumes to be used on text files only. It would lead to errors when handling binary file types, such as jpg or mp3.
There should be documentation and logging around this fact. The question here is whether Contentlayer could confirm that a file it is processing is a text file or not?
Alternative implementation
A backward-compatible way of introducing plaintext file types would be to add a contentType: 'plain' as an additional, optional feature to use.
However, I could see people getting confused by having a plaintext interpretation available but this not being the treatment that Contentlayer default to.
Ont he other hand, Contentlayer is a system for handling content and might find it's audience largely in people processing markdown files which would justify leaving the default interpretation as markdown.
Open questions
- Is defaulting to plain text a good idea?
- Can we determine a file to be a text file?
- Should we potentially switch to requiring conentType to be set explicitly?
- 主要語言
- TypeScript
- 星號
- 3.5k
- 分支
- 192
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
contentlayerdev/contentlayer 的其他 Issue
-
Error when building with contentlayer 0.3.4 and Next.js 13 App Router可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 3/5 1-2 天 新手友好度 25/100
contentlayerdev/contentlayer#506 · 84 則留言 · 47 個 reaction ·
-
Poor/broken monorepo DX: can't specify .contentlayer/ output path, no docs for custom config path未關閉help wanted meta: never-stale needs-research
難度 4/5 3-5 天 新手友好度 38/100
contentlayerdev/contentlayer#464 · 4 則留言 · 9 個 reaction ·
-
meta: never-stale
難度 5/5 一週以上 新手友好度 10/100
contentlayerdev/contentlayer#429 · 49 則留言 · 83 個 reaction ·
-
meta: never-stale topic: markdown/mdx
難度 4/5 3-5 天 新手友好度 42/100
contentlayerdev/contentlayer#421 · 4 個 reaction ·
-
meta: never-stale needs-research topic: schema
難度 5/5 一週以上 新手友好度 25/100
contentlayerdev/contentlayer#420 ·
查看 contentlayerdev/contentlayer 的全部 Issue
相似的 Issue
-
🐛 Bug: Calendar work items cannot be opened on mobile可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 1/5 1 小時以內 新手友好度 75/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 72/100
jaegertracing/jaeger-ui#4596 ·
維護者通常 1 天內回覆
-
area:tui enhancement platform:macos
難度 2/5 1-3 小時 新手友好度 66/100
anthropics/claude-code#101490 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 66/100
netlify/netlify-mcp#75 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆