shuding / nextra

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

How to configure basePath in Nextra #137

Closed YikSanChan closed 2 years ago

YikSanChan commented 3 years ago

Hi,

I am using nextra-theme-docs. After I deploy the app on GitLab CI, my GitLab pages are live,

image

however, as you can see, assets loading fails.

image

This is because my site is live on http://aiinfra.book.pri.ibanyu.com/docs/, however it tries to load assets from http://aiinfra.book.pri.ibanyu.com/_next/static/chunks/main-b8578ac1074c64daef74.js. This is not working, while http://aiinfra.book.pri.ibanyu.com/docs/_next/static/chunks/main-b8578ac1074c64daef74.js exist. (Note the latter has a /docs inside)

I wonder how to configure my nextra app so that my app loads asset from http://aiinfra.book.pri.ibanyu.com/docs/_next/ rather than http://aiinfra.book.pri.ibanyu.com/_next/.

I have tried to edit my theme.config.js to update path: "/" to path: "/docs", and also add basePath: "/docs" (according to nextjs docs), however neither helps.

Any help? Thanks!

YikSanChan commented 3 years ago

Ah i figure out why, I should add basePath: "/docs" to next.config.js rather than theme.config.js.

@shuding Is this a good practice?

varunharidas commented 2 years ago

Same issue not working for me, this is the config, throws 404

const withNextra = require('nextra')('nextra-theme-blog', './theme.config.js')
module.exports = withNextra()
module.exports = {
  basePath: '/docs',
}
thtmnisamnstr commented 2 years ago

@varunharidas You should only have one module.exports below:

const withNextra = require('nextra')('nextra-theme-blog', './theme.config.js')
module.exports = withNextra()
module.exports = {
  basePath: '/docs',
}

Instead, it should be:

const withNextra = require('nextra')({
    theme: 'nextra-theme-blog',
    themeConfig: './theme.config.js',
    // optional: add `unstable_staticImage: true` to enable Nextra's auto image import
})
module.exports = withNextra({
    basePath: '/docs',
})

You can check out the rtdl-docs repo and the associated GitHub Pages site for a working example.

dimaMachina commented 2 years ago

closing since basePath works, if anyone has a similar problem, I'll reopen the issue

raproid commented 2 years ago

@B2o5T what about broken paths in search results when I add basePath: '/docs',? The search results now have doubled the docs part of the path: localhost:3000/docs/docs/app-chain/components/app-chain-testnet-faucet

dimaMachina commented 2 years ago

@raproid do you use latest beta?

raproid commented 2 years ago

@B2o5T no, I'm using "next": "^12.2.0", "nextra": "^2.0.0-beta.6", "nextra-theme-docs": "^2.0.0-beta.6",

raproid commented 2 years ago

So, it's the beta 6.

dimaMachina commented 2 years ago

Try to use beta 21

raproid commented 2 years ago
image

getting this when using beta 21

raproid commented 2 years ago

How to import and declare callouts correctly in beta 21?

dimaMachina commented 2 years ago

import { Callout } from ‘nextra-theme-docs’

raproid commented 2 years ago

worked it out, thx

How to fix the position of the theme switcher? It's on the left and facing left beyond the screen.

image
raproid commented 2 years ago

and if there's not .md/.mdx file within a section but another section instead I'm getting 404. e.g. if I click on Affiliated Chains I'm getting 404 as there's only a folder within this folder, no .md/.mdx file to generate a page from.

image
raproid commented 2 years ago

Is the search index built locally? Testing it on localhost, I'm typing a word that sure is in many files in many subfolders under pages yet I see no search results for it at all. What search engine does Nextra use by default? And how is the index built?

dimaMachina commented 2 years ago

How to fix the position of the theme switcher?

Will be fixed in next release https://github.com/shuding/nextra/pull/763

dimaMachina commented 2 years ago

Is the search index built locally?

Try to next build and next start, in dev env there are some limitations

raproid commented 2 years ago

@B2o5T what about this bug? https://github.com/shuding/nextra/issues/137#issuecomment-1232224587

dimaMachina commented 2 years ago

Can you show a reproduction repo with this issue?

raproid commented 2 years ago

Of course. https://github.com/raproid/raproid.github.io/tree/stage

yarn then yarn next

raproid commented 2 years ago

And then try to go App Chains > Affiliated Chains

raproid commented 2 years ago

Also, what tab tag is to use in beta 21?

gives me the "Error: Expected object `Nextra` to be defined: you likely forgot to import, pass, or provide it." error. That tab tag worked in beta 6.
dimaMachina commented 2 years ago

Hi @raproid, will take a look at near days

raproid commented 2 years ago

@B2o5T Hi!

Any news about

  1. What to replace with the tag in latest betas?
  2. The bug? You can see it live on https://raproid-github-io.vercel.app/ under App Chains > Affiliated Chains and the direct link is https://raproid-github-io.vercel.app/app-chain/affiliated-chain/bnb-sidechain/

Basically, Nextra treats sidebar menu items as active links, regardless if an item is an actual page or a folder. Ofc the user sees 404 when clicking on an item that is a folder.

dimaMachina commented 2 years ago

for the 1st - you should use import { Tabs, Tab } from 'nextra-theme-docs' for 2nd I didn't take a look yet

raproid commented 2 years ago

@B2o5T would be really nice if you could. That's a major bug for Nextra. Beta 24 is very good. Thank you for your work!

dimaMachina commented 2 years ago

@raproid I can confirm the existing issue on the current beta, but on the not released version of nextra it works fine, so wait little bit, it will be fixed on next beta

PR that fixes your issue https://github.com/shuding/nextra/pull/811

NasirAbdullahSyed commented 10 months ago

The basePath should not be tied to NextJS's own config, imho.

Theme should have its own basePath.

I currently use Nextra within an existing project SaaS platform, so if I change the basePath, it breaks the entire app's routing.

iqbal125 commented 10 months ago

The basePath should not be tied to NextJS's own config, imho.

Theme should have its own basePath.

I currently use Nextra within an existing project SaaS platform, so if I change the basePath, it breaks the entire app's routing.

Yes I agree, it seems they want nextra to be its own standalone app, but I want to integrate into an existing app where the "/" is already taken.

NotDemonix commented 7 months ago

Any updates here? I wanna do it too

Coderamrin commented 5 months ago

The basePath should not be tied to NextJS's own config, imho. Theme should have its own basePath. I currently use Nextra within an existing project SaaS platform, so if I change the basePath, it breaks the entire app's routing.

Yes I agree, it seems they want nextra to be its own standalone app, but I want to integrate into an existing app where the "/" is already taken.

Have you found any solution? How to use nextra on an existing next js project under /docs route

Edit: Found solution on this issue: https://github.com/shuding/nextra/issues/291