Skip to content

Multiple MD files into one page for FAQ site #445

Answered by pngwn
VitroidFPV asked this question in Q&A
Discussion options

You must be logged in to vote

If you are using vite or sveltekit then you could use glob imports:

const modules = import.meta.globEager("**/glob_that_matches_dir")

modules will be an object that is something like this:

const modules = {
  "../content/post_one.svx": {
    metadata: { Category: '...', Question: '...', Answer: '...' },
    default: Component 
  },
  ...
}

So you should be able to do something like:

<script>
  const modules = 
    import.meta.globEager("**/glob_that_matches_dir");
  
  let grouped_modules = {};

  for (const k in modules) {
    const cat = modules[k].metadata.Category;
    if (grouped_modules[cat]) {
      grouped_modules[cat].push(modules[k]);
    } else {
      grouped_modules[cat] = [m…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@VitroidFPV
Comment options

@AyushSehrawat
Comment options

Answer selected by VitroidFPV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #444 on April 10, 2022 10:40.