facebook / facebook/docusaurus

extend blog `prevItem`/`nextItem` metadata

オープン
#9,140 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
feature
主要言語
TypeScript
スター
66.2k
フォーク
10k
平均マージ
1日 3時間
マージ済み PR(30日)
52

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。