ccozens / learning_blog

Svelte learning blog
https://learning-blog-teal.vercel.app
0 stars 0 forks source link

use vite glob import to generate path list for nav #34

Closed ccozens closed 1 year ago

ccozens commented 1 year ago

Thanks to a chat with perplexity

export async function getPaths(): Promise<string[]> {
  const modules = import.meta.glob('./src/routes/**/*.svelte');
  const paths: string[] = [];

  for (const path in modules) {
    if (Object.prototype.hasOwnProperty.call(modules, path)) {
      const modulePath = path.replace('./src/routes', '').replace('.svelte', '');
      paths.push(modulePath);
    }
  }

  return paths;
}
ccozens commented 1 year ago

perplexity's function didn't work but done anyway. docs in learning_blog/creating_nav.md