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

131
Vistas
Next.js markdown-blog page code not working
import { Blogs } from "../../components/Data"
import Image from "next/image";
import Link from "next/link";
import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'

export default function index({ posts }) {
    // const Short_Blog = Blogs.map(item =>
    //     <div className="BLOGS_Projects" key={item}>
    //         <div className="BLOGS_Projects_Image">
    //             <Image
    //                 className='BLOGS_Projects_image'
    //                 src={item['img-1']}
    //                 layout='fill'
    //             // objectFit='contain'
    //             />
    //         </div>
    //         {/* if someone clicks on this link i want them to go to [project].js and send This item to [projcet].js */}
    //         <Link href={'/blogs/' + Blogs.indexOf(item)}>
    //             <a>{item['title']}</a>
    //         </Link>
    //         <p>{item['desc']}</p>
    //     </div>
    // );

    return (
        <div className="BLOGS_Container">
            <div className="BLOGS_Sub_Container">

                <div className="BLOGS_New">

                    <h1 style={{ marginLeft: 25 + 'px' }}>Cyber-Security Blogs</h1>

                    <div className="BLOGS_Present">

                        {posts.map( post =>{
                            <h1 style={{zIndex: '10000'}}>{post}</h1>
                        })}

                    </div>

                </div>

            </div>
        </div>
    )
}

export async function getStaticProps() {
    const files = fs.readdirSync(path.join('posts'))

    const posts = files.map((filename) => {
        const slug = filename.replace('.md', '')

        const markdownWithMeta = fs.readFileSync(path.join('posts', filename), 'utf-8')

        const { data: frontmatter } = matter(markdownWithMeta)

        return {
            slug,
            frontmatter
        }
    })

    return {
        props: {
            posts,
        },
    }
}

The posts object does exist but when I try to use it in the HTML, it doesn't show up anyone got any idea why this is happening? the posts.map that I used is not giving any errors but it also doesn't show any h1 html in actual page, the actual page seems blank.

enter image description here

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

0

You need to return the element to render inside the callback of map function.

1st way

{posts.map((post) => {
  return <h1 style={{ zIndex: "10000" }}>{post}</h1>;
})}

2nd way

{posts.map((post) => (
  <h1 style={{ zIndex: "10000" }}>{post}</h1>
))}
about 4 years ago · Juan Pablo Isaza Denunciar

0

React will not render plain html content as a string. You need to use the dangerouslySetInnerHTML prop, like so:

{
  posts.map((post) => {
    return <div dangerouslySetInnerHTML={{__html: post}}></div>
  })
}

You can read more about it here:

https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml

Alternatively you can use something like next-mdx-remote, which you can learn about here:

https://github.com/hashicorp/next-mdx-remote

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