Nextra
repository·main·Indexed 11 days ago
https://github.com/shuding/nextraA site generation framework powered by Next.js, optimized for creating documentation and blog sites with minimal configuration. It includes specialized themes like nextra-theme-docs and nextra-theme-blog, and supports advanced features such as MDX customization, LaTeX (via KaTeX and MathJax), Mermaid diagrams, and remote content rendering using MDXRemote.
What's inside Nextra
- The Nextra Docs Theme is a specialized theme designed for documentation websites. It provides a structured layout suitable for technical documentation, typically including features like sidebars, navigation, and content rendering optimized for reading technical guides.
Overview of Nextra Docs Theme features
mainThe Nextra Docs Theme is a comprehensive theme for building modern documentation websites. It includes built-in support for:
- A top navigation bar
- A search bar
- A pages sidebar
- A table of contents (TOC)
- Various built-in components
Overview of Nextra
mainNextra is a simple, powerful, and flexible site generation framework built on top of Next.js. It is designed to help developers build documentation sites and blogs with ease.Use nextra-theme-docs for documentation sites
mainnextra-theme-docsis a specialized theme designed for building documentation websites using Nextra. It provides the layout, navigation, and UI components necessary for a professional documentation experience.You can see a live implementation of this theme at nextra.site.
Use nextra-theme-blog for blog sites
mainnextra-theme-blogis a specialized theme for Nextra designed specifically for building blog websites. It provides the layout and components necessary to render blog posts within a Nextra-powered project.Key features of SWR
mainSWR provides several built-in features for managing data fetching and state:
- Caching & Performance: Built-in cache, request deduplication, and fast page navigation.
- Revalidation Strategies: Polling on interval, revalidation on focus, and revalidation on network recovery.
- UI/UX Enhancements: Local mutation (Optimistic UI), pagination and scroll position recovery, and React Suspense support.
- Compatibility: SSR / ISR / SSG support, TypeScript ready, and React Native support.
- Robustness: Smart error retry and data dependency management.
Use the Nextra Blog Theme
mainThe Nextra Blog Theme is a specialized theme designed for creating blog-style websites within a Nextra project. It provides layouts and components optimized for chronological content delivery, typically including features like tags, RSS feeds, and file lists.Use a single `_meta.global` file
mainInstead of multiple
_metafiles in different directories, you can define your entire site structure in a single_meta.global.jsfile.Note: When using a global file, folder items must include an
itemsfield to define their children. You cannot use both_meta.globaland local_metafiles in the same project.// _meta.global.js export default { fruits: { type: 'page', title: '✨ Fruits', items: { apple: '🍎 Apple', banana: '🍌 BaNaNa' } } }Serializable options requirement for Turbopack
mainWhen using Turbopack, the
nextraconfiguration function only supports JSON serializable values.Because
remarkPlugins,rehypePlugins, andrecmaPluginsare functions, they cannot be passed in themdxOptionswhen Turbopack is enabled. These plugin options are only supported when using the standard Webpack-based development mode or duringnext build(where Webpack is still used for builds).If you attempt to pass non-serializable plugins while using Turbopack, you will encounter the following error:
Error: loader nextra/loader for match "./{src/app,app}/**/page.{md,mdx}" does not have serializable options. Ensure that options passed are plain JavaScript objects and values.import nextra from 'nextra' // This configuration will FAIL with Turbopack because plugins are functions const withNextra = nextra({ mdxOptions: { remarkPlugins: [myRemarkPlugin], rehypePlugins: [myRehypePlugin], recmaPlugins: [myRecmaPlugin] } })Understand the difference between isLoading and isValidating in SWR
mainWhen using
useSWR, you can distinguish between initial loading and background revalidation usingisLoadingandisValidatingto improve User Experience (UX).isValidating: Becomestruewhenever there is an ongoing request, regardless of whether data has already been loaded.isLoading: Becomestrueonly when there is an ongoing request and data has not been loaded yet.
UX Pattern: Use
isLoadingto show a skeleton or full-page loader when no data is available. UseisValidatingto show a subtle indicator (like a spinner) when data is already present but being refreshed in the background.Note: Fallback data and data preserved via
keepPreviousDataare not considered "loaded data," so you may still have data to display even ifisLoadingis true.function Stock() { const { data, isLoading, isValidating } = useSWR(STOCK_API, fetcher, { refreshInterval: 3000 }) // If it's still loading the initial data, there is nothing to display. // We return a skeleton here. if (isLoading) return <div className="skeleton" /> // Otherwise, display the data and a spinner that indicates a background // revalidation. return ( <> <div>${data}</div> {isValidating ? <div className="spinner" /> : null} </> ) }Extend Cache Providers (Experimental)
mainWhen
<SWRConfig>components are nested, you can extend the existing cache provider. Theproviderfunction receives the upper-level cache provider as its first argument, allowing you to wrap or augment it.<SWRConfig value={{ provider: cache => newCache }}>...</SWRConfig>Use `page.mdx` to define route-specific UI
mainIn Nextra, the
page.mdxfile follows the Next.js App Router convention to define the UI unique to a specific route. While Next.js natively supports.js,.jsx, or.tsxextensions for pages, Nextra extends this capability by allowing you to use.mdand.mdxextensions. This enables you to write your route content using Markdown or MDX directly within your App Router structure.app/ docs/ page.mdx <-- Defines the UI for /docs getting-started/ page.mdx <-- Defines the UI for /docs/getting-started