Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use front matter as overview page title #1503

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-fireants-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rspress/core': patch
---

release
1 change: 1 addition & 0 deletions packages/document/docs/en/api/index.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
overview: true
title: API Overview
---
17 changes: 16 additions & 1 deletion packages/document/docs/en/guide/default-theme/overview-page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,24 @@ overview: true
---
```

::: note

The title of the overview page can be configured through frontmatter. The default value is `Overview`. After `title` is configured in frontmatter, there is no need to write an H1 title in the markdown content.

```md
---
overview: true
title: Overview
---

This is an Overview page of our website.
```

:::

### 2. Configuring `_meta.json`

The content structure of the preview page will be automatically generated according to `_meta.json` and the corresponding h1, h2 titles of the article. For example, the configuration of `api/_meta.json` is as follows:
The content structure of the overview page will be automatically generated according to `_meta.json` and the corresponding h1, h2 titles of the article. For example, the configuration of `api/_meta.json` is as follows:

```json
[
Expand Down
1 change: 1 addition & 0 deletions packages/document/docs/zh/api/index.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
overview: true
title: API 概览
---
15 changes: 15 additions & 0 deletions packages/document/docs/zh/guide/default-theme/overview-page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ overview: true
---
```

::: note

预览页的标题可以通过 frontmatter 进行配置,默认为 `Overview`,在 frontmatter 中配置了 `title` 后,正文中不需要再写 H1 标题。

```md
---
overview: true
title: Overview
---

This is an Overview page of our website.
```

:::

### 2. 配置 `_meta.json`

预览页面的内容结构会根据 `_meta.json` 及其对应文章的 h1、h2 标题自动生成。比如 `api/_meta.json` 的配置如下:
Expand Down
10 changes: 5 additions & 5 deletions packages/theme-default/src/components/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ export function Overview(props: {
.filter(Boolean);
}, [groups, query]);

const overviewTitle = title || 'Overview';

return (
<div className="overview-index mx-auto px-8">
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between">
{!title && (
<h1 className="text-3xl leading-10 tracking-tight mb-4 sm:mb-0">
Overview
</h1>
)}
<h1 className="text-3xl leading-10 tracking-tight mb-4 sm:mb-0">
{overviewTitle}
</h1>
{/* Added search input */}
<SearchInput query={query} setQuery={setQuery} searchRef={searchRef} />
</div>
Expand Down