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

How to get frontmatter in v4 (client or server) #3554

Closed
Firgrep opened this issue Oct 26, 2024 · 6 comments
Closed

How to get frontmatter in v4 (client or server) #3554

Firgrep opened this issue Oct 26, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@Firgrep
Copy link

Firgrep commented Oct 26, 2024

Is your feature request related to a problem? Please describe.
useConfig() handily exposed frontMatter, which allowed making components with conditions based on certain mdx file metadata.

Describe the solution you'd like
A similar hook or function. I'm not sure if a replacement already exists but I can't find it.

@Firgrep Firgrep added the enhancement New feature or request label Oct 26, 2024
@dimaMachina
Copy link
Collaborator

Hi, where do you want to access frontmatter in mdx page or custom jsx component imported in mdx page?

@Firgrep
Copy link
Author

Firgrep commented Oct 26, 2024

Custom JSX component that sits with the layout, just beneath the children, and renders its contents based on certain conditions from the frontmatter of the mdx page currently in view. E.g.

image

I got this working in v3 making a wrapper component for main property in the old theme config, and inside the wrapper I had a component after the children that got the frontMatter from the old hook and rendered on certain conditions, something like:

image

@dimaMachina
Copy link
Collaborator

I think similar we return activeThemeContext

const { activeThemeContext } = store.getState().normalizePagesResult

In the same way, we can return activeMetadata

@Firgrep
Copy link
Author

Firgrep commented Oct 27, 2024

Yeah, that'd be amazing!

@dimaMachina
Copy link
Collaborator

dimaMachina commented Oct 27, 2024

Hi @Firgrep, I am finishing the Blogpost announcement for Nextra 4 RC.0 with all features and migration guide, so busy for now to add it

I am planning to add this feat in Nextra 4 RC.1

For now, you can access frontMatter (in your client component) via:

const { normalizePagesResult } = useConfig()
console.log(normalizePagesResult.activePath.at(-1).frontMatter)

Hope this unblock you for this moment ;)

@Firgrep
Copy link
Author

Firgrep commented Oct 27, 2024

Hi @dimaMachina , thanks for the hotfix! ;) Really appreciate it!

By the way, I've opened a new issue with regards to the bug, as I found another one and they seemed related. Ref #3567

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants