facebook / facebook/docusaurus

extend blog `prevItem`/`nextItem` metadata

Aperta
#9,140 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
feature
Lingua principale
TypeScript
Stelle
66.2k
Fork
10k
Merge medio
1g 3h
PR unite (30g)
52

Descrizione

### 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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.