#help me understand Astro - how to get markdown files to display
24 messages · Page 1 of 1 (latest)
are you using content collections?
once you organized your markdown files following this guide ↑ , you will be able to get the files for your tabs following that part ↓:
https://docs.astro.build/en/guides/content-collections/#querying-collections
You can import markdown files from anywhere in your project, and use them as components.
---
// Import a single file
import * as myPost from '../pages/post/my-post.md';
// Import multiple files with Astro.glob
const posts = await Astro.glob('../markdown/*.md');
---
You can use the Content component to render that markdown, and access the frontmatter using frontmatter.
// src/pages/index.astro
---
const tabs = await Astro.glob('../markdown/tabs/*.md');
---
{tabs.map({frontmatter, Content} => (
<>
<h2>{frontmatter.title}</h2>
<Content/>
</>
)}
And yes! Content collections will be a lot nicer if you're willing to set it up
so i would have to write
title: my post name
Yes, in this example. But if you don't want to use frontmatter, you could also grab the headings if you use h1 headings. However, for content collections, frontmatter works much better (and is much more flexible)
so my markdown files should be in content directory ?
if you're using content collections yes. src/content/ is reserved for content collections, so if you're not using them, use something else
you need to define a collection to use content collections. the validator for the frontmatter you expect to be inside each content entry
https://docs.astro.build/en/guides/content-collections/#defining-collections
Hello, can I ask something about markdown rendering here?
I don't know where to ask actually and I'm new
Hi @idle pier! It's probably best to open a new #1019713903481081876 post, but yes, we'd be happy to answer