I have a <BlogPost/> component which basically takes in the information of a blogpost and displays it as a small tile. Basically used to make a menu of sorts. Now to pass down the information of the blogpost, I import all of my markdown files by using Astro.glob("../blog/*.md"). Its all good but, apparently this also inherits the Layouts that my markdown files inherit. Is there any way to override this?
#Astro global import inherits the layout as well.
1 messages · Page 1 of 1 (latest)
@edgy salmon can I see your folder structure?
what's inside blog/index.astro?
also check https://github.com/Gers2017/gers2017.github.io/blob/main/src/pages/posts/hello-friend.md?plain=1
not sure if this helps but there's a blog layout that overrides the normal layout
---
layout: ../../layouts/BlogLayout.astro
---
import '../../styles/global.css';
import BlogPost from "../../components/blogpost.astro";
let posts = await Astro.glob("../blog/*.md");
---
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vaimer's blog</title>
</head>
<body>
<div class="main-title"></div>
<div class="blogs-container">
{posts.map(post => (
<BlogPost
title={post.frontmatter.title} date={post.frontmatter.date} description={post.frontmatter.description}
/>
))}
</div>
</body>
</html>
<style>
body {
background-color: #222;
}
</style>
this is blog/index.astro
yeah I also have this in my .md file
when I import the markdown file
I automatically inherit blogs.astro layout
in blog/index.astro
maybe use a base layout for the .md files and wrap your BlogPost with a layout variant
https://docs.astro.build/en/core-concepts/layouts/#markdown-layouts
https://docs.astro.build/en/guides/markdown-content/#markdown-and-mdx-pages
the layout component: "This component will wrap your Markdown content, providing a page shell and any other included page template elements."
first of all let me name my files properly, and then make the repository public
so you can properly see whats going on
ignore the great name I've given to this
I am doing the same thing right? Using a base layout for the markdown files
I just don't get why importing the md files also inherits the layout
inside BlogListItem
---
const { title, date, description, is_normal_post } = Astro.props;
---
<div class="container">
{
is_normal_post ? (
<div class="title">{title}</div>
<div class="description">{description}</div>
<div class="date">{date}</div>
) : (
<h1>{title}</h1>
)
}
</div>
<div class="blogs-container">
{posts.map(post => (
<BlogListItem
title={post.frontmatter.title}
date={post.frontmatter.date}
description={post.frontmatter.description}
is_normal_post={true} // <---- idk change it for a variable
/>
))}
</div>
I'll add this later, but this isn't relevant to layouts is it? blog/index.astro is supposed to display all the blogpost names and such using the BlogListItem.astro component (sorry I messed up the name earlier).
I don't really need 2 layouts
only 1 for the blogposts themselves
/ for the homepage
/blog for browsing blogs
/blogs/[blogname] for the blogs themselves
So adding a layout for /blog would be unnecessary
dammnit astro why does Astro.glob() inherit layouts
aaa
you could make your life easier by making 2 components
what will they be?
hmm
one being a wrapper for your big bloody blog post and another one as the preview or list item (btw astro has a blog example)
yeah I just found it
don't I already have that? 😅 im new to this. I already have the list item preview component. And the markdown files inherit the blogpost layout, aren't layouts just wrappers?
vaimer.subscribe_to('blog', (users)=> users.find('gers').notify())
yeah layouts are wrappers
but you want your .md files to behave like two different components right?
idk I tweaked the blog example to my needs
md files are just pages for all I care, im only importing them for the frontmatter.
smh the astro discord server isn't even responding
neovim moment (jk vscode moment)
what about this (and the .md files have none or a basic layout)
{posts.map(post => (
<!-- import other css -->
<BlogListItem
title={post.frontmatter.title}
date={post.frontmatter.date}
description={post.frontmatter.description}
/>
))}
// --------
<!-- import other css -->
{posts.map(post => (
<RealBlogPost
title={post.frontmatter.title}
date={post.frontmatter.date}
description={post.frontmatter.description}
/>
))}
}
I even tried making a baselayout
did nothing
ReadBlogPost?
you mean an actual blogpost?
where is the <slot />?
ye
no this is the index.astro
here's the layout
background is red for testing (I can't see red because the BlogLayout styles cancel this for some reason)
thats teh whole problem
external styles don't work either
the thing is
the second I remove the import
everything works
wait
maybe I have to do scoped styles?
in teh BlogLayout
thats the last hope
nvm im stupid they're already scoped
@coarse condor fixed it
but yes it still inherits the layout, I just had to fix the BlogLayout itself
so weird
nice
I had to sleep last night so I forgot to say this but thanks a lot for your time and help @coarse condor, rlly appreciate it 