Skip to Content
HelloWorld

Create: 2023-03-23

Update: 2024-01-04
迁移至 Nextra 3

Update: 2025-03-03
升级至 Nextra 4

Update: 2026-01-26
删除 Nextra3 相关, 修改部分配置

更新至 Nextra 4

创建 app 文件夹

不使用 4.4 版本更新的复制页面功能

app/[[...mdxPath]]/page.jsx
import { generateStaticParamsFor, importPage } from "nextra/pages"; import { useMDXComponents as getMDXComponents } from "../../mdx-components"; export const generateStaticParams = generateStaticParamsFor("mdxPath"); export async function generateMetadata(props) { const params = await props.params; const { metadata } = await importPage(params.mdxPath); return metadata; } const Wrapper = getMDXComponents().wrapper; export default async function Page(props) { const params = await props.params; const { default: MDXContent, toc, metadata, } = await importPage(params.mdxPath); return ( <Wrapper toc={toc} metadata={metadata}> <MDXContent {...props} params={params} /> </Wrapper> ); }
app/layout.jsx
import { Footer, Layout, Navbar, LastUpdated } from "nextra-theme-docs"; import { Head, Search } from "nextra/components"; import { getPageMap } from "nextra/page-map"; import "nextra-theme-docs/style.css"; export const metadata = { title: { template: "%s - Life.Exec(Me);", }, }; const navbar = <Navbar logo={<span>Life.Exec(Me);</span>} />; const footer = ( <Footer> <span> <a href="https://nextra.site/" target="_blank"> Power By Nextra </a> <br /> 2023 - {new Date().getFullYear()} ©{" "} <a href="https://aifaistrue.tk" target="_blank"> aifaistrue.tk </a> </span> </Footer> ); export default async function RootLayout({ children }) { return ( <html lang="zh-CN" dir="/" suppressHydrationWarning> <Head> {/* Your additional tags should be passed as `children` of `<Head>` element */} </Head> <body> <Layout navbar={navbar} pageMap={await getPageMap()} docsRepositoryBase="https://aifaistrue.tk/docs" footer={footer} editLink={null} feedback={{ content: "" }} search={<Search placeholder={"搜索"} />} toc={{ title: "此页面", backToTop: "回到顶部" }} // ... Your additional layout options > {children} </Layout> </body> </html> ); }

将原本的 pages 文件夹重命名为 content
删除 theme.config.jsx

mdx-components.js
import { useMDXComponents as getThemeComponents } from "nextra-theme-docs"; // nextra-theme-blog or your custom theme // Get the default MDX components const themeComponents = getThemeComponents(); // Merge components export function useMDXComponents(components) { return { ...themeComponents, ...components, }; }
next.config.mjs
import nextra from "nextra"; const withNextra = nextra({ // ... Other Nextra config options defaultShowCopyCode: true, }); // You can include other Next.js configuration options here, in addition to Nextra settings: export default withNextra({ distDir: "build", //导出目录 output: "export", //配置静态导出 trailingSlash: true, //配置输出时导出路由 html images: { unoptimized: true, //关闭图像优化 }, });
next-sitemap.config.js
/** @type {import('next-sitemap').IConfig} */ module.exports = { siteUrl: "https://aifaistrue.tk", generateRobotsTxt: true, autoLastmod: false, //静态生成lastmod会同一时间遂Pass generateIndexSitemap: false, exclude: ["*/_meta"], };
package.json
{ "name": "website", "version": "0.0.1", "description": "Nextra docs", "scripts": { "dev": "next dev -p 8081", "build": "next build", "postbuild": "next-sitemap --config next-sitemap.config.js && pagefind --site .next/server/app --output-path public/_pagefind", "start": "next start" }, "dependencies": { "next": "latest", "next-sitemap": "latest", "nextra": "latest", "nextra-theme-docs": "latest", "react": "latest", "react-dom": "latest" }, "devDependencies": { "pagefind": "latest" } }

持续更新中