facebook / facebook/docusaurus

extend blog `prevItem`/`nextItem` metadata

Abierto
#9,140 2 comentarios 0 reacciones 0 asignados Ver en GitHub
feature
Lenguaje dominante
TypeScript
Estrellas
66.2k
Forks
10k
Merge medio
1 d 3 h
PR fusionados (30 d)
52

Descripción

### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/main/CONTRIBUTING.md#issues).

### Description

Extend the metadata that is passed to blog paginator buttons.

### Has this been requested on Canny?

Not that I'm aware of.

### Motivation

As part of my custom blog implementation, I would like to add more context to the paginator buttons for blogs. These includes, but is not limited to `authors` and `date`.

![CleanShot 2023-07-10 at 10 08 35@2x](https://github.com/facebook/docusaurus/assets/32957606/82121db2-87ba-407c-bd77-d20cadffe314)

### API design

Considering that the stock UI of the paginator buttons only requires `title` and `permalink`, I think it would make sense to allow developers to extend the metadata of each blog using a generator function. This way, a developer can choose the props they need and then swizzle the paginator component to update the UI.

```js
plugins: [
[
'@docusaurus/plugin-content-blog',
{
metadataGenerator({
defaultMetadataGenerator,
content
}) {}
},
],
]

```

I'm not that familiar with the docusaurus codebase, but I assume another factor to keep in mind is to find a solution that generalizes nicely to the docs plugin too?

---

An alternative solution, that I've already implemented is to extend the metadata directly in the plugin internals, which would give developers the flexibility to do more structural changes when swizzling.

### Have you tried building it?

I've made a minimal [fork](https://github.com/Pondorasti/docusaurus/commit/9363b5f99e6791e5b6d5703a51f908697f0737d1) that updates [loadContent()](https://github.com/Pondorasti/docusaurus/blob/9363b5f99e6791e5b6d5703a51f908697f0737d1/packages/docusaurus-plugin-content-blog/src/index.ts#L102) from `docusaurus-plugin-content-blog` to pass additional metadata to `prevItem/nextItem` props.

Again, this is just a quick POC and I'm open to solutions that handle the problem in a more generic way.

### Self-service

- [X] I'd be willing to contribute this feature to Docusaurus myself.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.