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

define page title in sidebar from frontMatter.title if page is not specified in _meta.json #755

Merged
merged 7 commits into from Sep 2, 2022

Conversation

dimaMachina
Copy link
Collaborator

@dimaMachina dimaMachina commented Aug 29, 2022

fixes #747

use item.frontMatter.title either item.name as sidebar title if page is not specified in _meta.json

@changeset-bot
Copy link

changeset-bot bot commented Aug 29, 2022

🦋 Changeset detected

Latest commit: dc6d390

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Aug 29, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
nextra-theme-docs-dev ✅ Ready (Inspect) Visit Preview Sep 2, 2022 at 5:05PM (UTC)
nextra-v2 ✅ Ready (Inspect) Visit Preview Sep 2, 2022 at 5:05PM (UTC)
1 Ignored Deployment
Name Status Preview Updated
nextra ⬜️ Ignored (Inspect) Sep 2, 2022 at 5:05PM (UTC)

Comment on lines +225 to +230
const title = extendedMeta.title || (type !== 'separator' && a.name)

const getItem = (): Item => ({
...a,
type,
title: title || (type === 'separator' ? undefined : getTitle(a.name)),
...(title && { title }),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed title package since we no need it here
Example: getTitle will convert page name getting-started to Getting-Started so it's not really helpful

Comment on lines -27 to +28
const meta =
pageMap.find((item): item is MetaJsonFile => item.name === META_FILENAME)
?.meta || {}
const meta = pageMap.find(
(item): item is MetaJsonFile => item.kind === 'Meta'
)!.data
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now _meta.json fill be always exist in pageMap and in fileMap even it's not exist on disk, this _meta.json will contain all pages with the title as item.frontMatter.title or item.name

Comment on lines -32 to +31
if (item.name === META_FILENAME) continue
if (item.kind === 'Meta') continue
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explicitly added kind property, so TypeScript will be much smarter to understand of which kind of file is processed

@dimaMachina dimaMachina merged commit e4cfb83 into core Sep 2, 2022
@dimaMachina dimaMachina deleted the take-sidebar-title-from-frontmatter branch September 2, 2022 17:08
tatukoivisto pushed a commit to tatukoivisto/nextra that referenced this pull request Aug 20, 2023
…specified in `_meta.json` (shuding#755)

* define page title in sidebar from `frontMatter.title` if page is not specified in `_meta.json`

* fix typecheck

* Update packages/nextra-theme-blog/src/utils/parent.ts

* remove sortDate

* `addPage` no longer need accept `frontMatter` (shuding#789)

* update snapshots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant