Support plaintext contentType
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 28/100
- Issue-Typ
- Feature
- Klarheit
- Muss geklärt werden
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- react, typescript
- Bereich
- content
Rechercherichtung
Beginne mit der gezeigten Konfiguration von defineDocumentType und verfolge, wie contentType validiert wird und wie Dateiinhalte computedField erreichen; das Issue nennt keine Dateien oder Tests im Repository. Für den Abschluss wären ein vereinbartes Verhalten für contentType: 'plain', seine Standardbelegung und Richtlinie zur Abwärtskompatibilität, der Umgang mit Text gegenüber Binärdaten sowie die entsprechende Dokumentation und Tests erforderlich.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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?
- Vorherrschende Sprache
- TypeScript
- Sterne
- 3.5k
- Forks
- 192
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus contentlayerdev/contentlayer
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 25/100
contentlayerdev/contentlayer#506 · 84 Kommentare · 47 Reaktionen ·
-
Poor/broken monorepo DX: can't specify .contentlayer/ output path, no docs for custom config path Offenhelp wanted meta: never-stale needs-research
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 38/100
contentlayerdev/contentlayer#464 · 4 Kommentare · 9 Reaktionen ·
-
State of the project Offenmeta: never-stale
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 10/100
contentlayerdev/contentlayer#429 · 49 Kommentare · 83 Reaktionen ·
-
meta: never-stale topic: markdown/mdx
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
contentlayerdev/contentlayer#421 · 4 Reaktionen ·
-
meta: never-stale needs-research topic: schema
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
contentlayerdev/contentlayer#420 ·
Alle Issues in contentlayerdev/contentlayer
Ähnliche Issues
-
VerificationGate: ATTRIBUTION quote guard never matches a normal quotation (\b around the quote) Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
danielmiessler/LifeOS#2234 ·
-
T: Bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
-
Mend: dependency security vulnerability untriaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100