Support plaintext contentType
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 28/100
- Type d'issue
- Fonctionnalité
- Clarté
- À clarifier
- Activité
- À l'abandon
- Stack technique
- react, typescript
- Domaine
- content
Piste de recherche
Commencez par la configuration de defineDocumentType présentée et suivez la manière dont contentType est validé et dont le contenu des fichiers parvient à computedField ; l’issue ne nomme aucun fichier ni test du dépôt. Pour considérer le travail comme terminé, il faudrait définir un comportement convenu pour contentType: 'plain', son comportement par défaut et la politique de rétrocompatibilité, la gestion du texte par rapport au binaire, ainsi que la documentation et les tests correspondants.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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?
- Langage dominant
- TypeScript
- Étoiles
- 3.5k
- Forks
- 192
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de contentlayerdev/contentlayer
-
Difficulté 3/5 1-2 jours Accessibilité débutants 25/100
contentlayerdev/contentlayer#506 · 84 commentaires · 47 réactions ·
-
Poor/broken monorepo DX: can't specify .contentlayer/ output path, no docs for custom config path Ouvertehelp wanted meta: never-stale needs-research
Difficulté 4/5 3-5 jours Accessibilité débutants 38/100
contentlayerdev/contentlayer#464 · 4 commentaires · 9 réactions ·
-
State of the project Ouvertemeta: never-stale
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 10/100
contentlayerdev/contentlayer#429 · 49 commentaires · 83 réactions ·
-
meta: never-stale topic: markdown/mdx
Difficulté 4/5 3-5 jours Accessibilité débutants 42/100
contentlayerdev/contentlayer#421 · 4 réactions ·
-
meta: never-stale needs-research topic: schema
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
contentlayerdev/contentlayer#420 ·
Toutes les issues de contentlayerdev/contentlayer
Issues similaires
-
bug(cli): hapi doctor inline-media prints a fabricated B:\ helper-script path in packaged installs Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
-
Crush Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
catppuccin/catppuccin#3125 ·
-
Add a SECURITY.md Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
ElementsProject/cln-application#167 · 1 commentaire · 1 réaction ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Quantco/pnpm-licenses#17 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100