Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
How to get post content in javascript from markdown file

I am building a blog site with sveltekit and markdown. I import the .md file using dynamic import but i can only acces the metadata and not the post content written in markdown. Please help

//[slug.js]
export async function get({ params }) {
    const post = await import(`../../posts/${params.slug}.md`)
    console.log(post.default)
    console.log(post.metadata)

    return {
        body: {
            postContent: post.default,
            meta: post.metadata
        }
    }
}

//[slug.svelte]
<script>
    export let postContent, meta
    const { title, date, thumbnail } = meta
</script>

<h1>{title}</h1>
<p>{date}</p>
<img src={thumbnail} alt={title} />
<p>{postContent}</p>

Using post.metadata I can get the post title, date and thumbnail but post.default returns this:

{ render: [Function: render], '$$render': [Function: $$render] }

How can I get the post content?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The solution is to use post.default on the endpoint [slug].js and use <svelte:component this={postContent}/> on the [slug].svelte file.

Here are the files for the solution:

//[slug].js
export async function get({ params }) {
    const post = await import(`../../posts/${params.slug}.md`)

    return {
        body: {
            postContent: post.default,
            meta: post.metadata
        }
    }
}
//[slug].svelte
<script>
    export let postContent, meta
    const { title, date, thumbnail } = meta
</script>

<h1>{title}</h1>
<p>{date}</p>
<img src={thumbnail} alt={title} />

<svelte:component this={postContent} />

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda