shuding / nextra

Simple, powerful and flexible site generation framework with everything you love from Next.js.
https://nextra.site
MIT License
11.29k stars 1.24k forks source link

i18n `_meta.en.json` tags is resulting in 404 pages #3139

Open samyakb opened 3 weeks ago

samyakb commented 3 weeks ago

I am trying to add Nextra docs on subroute with i18n support, but the _meta.en.json or _meta.es.json is not getting picked up by nextra.

My next config is

const withNextra = require("nextra")({  
  theme: "nextra-theme-docs",  
  themeConfig: "./src/theme.config.jsx",  
  i18n: {  
   locales: ["en", "es"],  
   defaultLocale: "en",  
   localeDetection: false,  
  },  
});

module.exports = withNextra(nextConfig);

My middleware code is

// middleware.ts

export const middleware = async (request) => {
// ...REDACTED
const pathnameIsMissingLocale: boolean = SUPPORTED_LOCALES.every(  
  (locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`  
);  

if (pathnameIsMissingLocale) {  
  const locale = getLocale(request);  
  return NextResponse.redirect(  
   new URL(search ? `/${locale}/${pathname}${search}` : `/${locale}/${pathname}`, request.url)  
  );  
}
}

The middleware adds the locale and redirects the path if locale does not exist in path.

The _meta.en.json under Pages directory is like this

{  
    "index": {  
       "title": "Documentation",  
       "type": "page",  
       "href": "/docs"  
    },  
    "frameworks": {  
       "title": "Frameworks",  
       "type": "page",  
       "href": "/docs/frameworks"  
    },  
    "faqs": {  
       "title": "FAQs",  
       "type": "page",  
       "href": "/docs/faqs"  
    }  
}

And the

{  
    "index": {  
       "title": "Documentation Spanish",  
       "type": "page",  
       "href": "/docs"  
    },  
    "frameworks": {  
       "title": "Frameworks Spanish",  
       "type": "page",  
       "href": "/docs/frameworks"  
    },  
    "faqs": {  
       "title": "FAQs Spanish",  
       "type": "page",  
       "href": "/docs/faqs"  
    }  
}

But I am getting 404 page for /en/docs and /es/docs

The pages directory tree is this

src/pages/
├── [lang]
│   └── docs
│       ├── faqs.en.mdx
│       ├── faqs.es.mdx
│       ├── frameworks.en.mdx
│       ├── frameworks.es.mdx
│       ├── frameworks.mdx
│       ├── index.en.mdx
│       └── index.es.mdx
├── _meta.en.json
└── _meta.es.json

Am I doing anything wrong here ?

samyakb commented 3 weeks ago

Is this related to this PR ?

ignore loading pageMap for dynamic locale /[locale]

dimaMachina commented 3 weeks ago

Use v2 example https://github.com/shuding/nextra/tree/main/examples/swr-site

Or v3 example https://github.com/shuding/nextra/tree/v3/examples/swr-site

Migration guide https://the-guild.dev/blog/nextra-3

samyakb commented 2 weeks ago

I am using Nextra versions

"nextra": "^2.13.4",
"nextra-theme-docs": "^2.13.4",

After following the v2 Example, I am still getting 404 pages.

This is the directory structure I used, changed to locale to use en-US than en, but en also didnt work.


src/pages
├── docs
│   ├── faqs.en-US.mdx
│   ├── frameworks.en-US.mdx
│   └── index.en-US.mdx
└── _meta.en-US.json