facebook / facebook/docusaurus

extend blog `prevItem`/`nextItem` metadata

Đang mở
#9,140 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
feature
Ngôn ngữ chính
TypeScript
Star
66.2k
Fork
10k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
52

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.