svelteness / kit-docs

Documentation integration for SvelteKit.
https://kitdocs.vercel.app
MIT License
457 stars 32 forks source link

Allow docs / sidebar from root #95

Closed CaptainCodeman closed 10 months ago

CaptainCodeman commented 10 months ago

Enables docs to be in the root of the site instead of nested in any subfolder (/docs in the example). Example of where this would be useful (to keep existing URLs).

The layout.js page would change to return an empty string for the root path:

export const load = createKitDocsLoader({
  sidebar: {
    '/': '',
  },
});

Other references to /docs would be removed, page.js for example:

export function load() {
  throw redirect(307, '/getting-started/introduction');
}

I used 'index' to represent the root when the sidebar is requested which was also used for the root meta request - it's possible this could interfere with someone having a docs folder called /index so might benefit from changing to some special character (such as ~). Another alternative might be to make the route param optional (/[[dir]].sidebar/+server.js) instead.