nextra icon indicating copy to clipboard operation
nextra copied to clipboard

is it possible to create a variable that can be accessed under the scope of all the mdx files inside pages/?

Open FidelVe opened this issue 1 year ago • 1 comments

Hello, I would like to know if it is possible to declare a variable (maybe in _app.js?) that its content can be accessed inside all the documents (.mdx files) inside the pages/ folder.

currently im importing this variable at the top of all the .mdx files like this:

import index from "path/to/index.json"
import Link from "next/link"

some text with <Link href={index["link-1"]}>some link here</Link>

I would like to be able to have index and Link be globally available under the scope of all the .mdx files inside the pages/ folder so that I only need to do this inside an .mdx file

some text with <Link href={index["link-1"]}>some link here</Link>

FidelVe avatar Oct 27 '23 03:10 FidelVe

for Link question it can be done via https://nextra.site/docs/docs-theme/theme-configuration#mdx-components option for index - not sure what is a proper way to do it, maybe to assign it to globalThis variable aka globalThis.myVar = index in _app.js?

dimaMachina avatar Dec 02 '23 02:12 dimaMachina