Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

355
Visualizações
Vite glob import - accessing body / payload in SvelteKit?

I'm using the glob import functionality of Vite to bring in multiple markdown files to a SvelteKit page:

<script context="module">
    export async function load() {
        const employmentsMeta =
            import.meta.globEager('./employments/*.md');
        return {
            props: {
                employmentsMeta: employmentsMeta
            }
        };
    }
</script>

<script>
    export let employmentsMeta;
</script>

This works well for me to access the metadata via employmentsMeta[Object.keys(employmentsMeta)[0]]['metadata']. I'm having difficulty accessing the actual contents of the markdown file, however - no matter how I attempt to access it, it seems to be coming back as undefined.

For example, console.log(employmentsMeta[Object.keys(employmentsMeta)[0]['default']]) returns undefined, despite my understanding that there's a default export object in there, and the metadata access working as intended.

How do I access the payload / body of the imported markdown?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have a similar use-case, with markdown files in SvelteKit as blog posts.

In your example, I'd get the file contents as html like this:

const contents = employmentsMeta[Object.keys(employmentsMeta)[0]].default.render();

contents here is an object like this:

{
  html: '/* a string with the markdown content parsed as html */',
  css: { code: '', map: null },
  head: '',
}

I guess you have to use mdsvex for the md->html conversion to happen.

EDIT: I should mention that I do this in an endpoint ([slug].json.js), return the results, and get them in the route, as doing it in the load function was throwing an error (...default.render is not a function) client-side.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda