contentlayerdev / contentlayerdev/contentlayer
Combine `fields` and `computedFields`
- Linguagem predominante
- TypeScript
- Estrelas
- 3.5k
- Forks
- 192
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
Today we have `fields` and `computedFields`. The definitions in `computedFields` expects a function to which Contentlayer passes the processed document.
I'd rather be able to define all my fields in one place and allow the options of that field definition (presence of `resolve`) to determine whether or not it should be computed. Thus, I could have a doc type def like this:
```js
const Page = defineDocumentType(() => ({
// ...
fields: {
title: { type: 'string', required: true },
url_path: {
type: 'string',
resolve: (doc) => doc._raw.flattenedPath.replace(/pages\/?/, ''),
},
},
}))
```
To do this and still support current use cases, it'd be beneficial to not just pass the processed doc object, but also input data. (See #76 for an example use case.) IOW the shape of the `doc` passed to the `resolve` function might include the following properties:
- `_raw` would still be there as it is today
- `frontmatter` would contain the raw frontmatter content
- `body` (configurable) would contain the processed body
Guia de contribuição
Direção de pesquisa
Comece revisando as definições e o tratamento atuais de `fields` e `computedFields` e, em seguida, leia o caso de uso referenciado em #76. Considera-se concluído quando as definições de campos puderem usar `resolve` para valores calculados, preservando os casos de uso atuais e expondo `_raw`, o `frontmatter` bruto e dados `body` processados configuráveis.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- typescript
- Domínio
- tooling
- Tipo de issue
- Funcionalidade
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 30/100