igorskyflyer / npm-astro-post-excerpt

⭐ An Astro component that renders post excerpts for your Astro blog - directly from your Markdown and MDX files! 💎 Featured on Astro's official Integrations library: https://astro.build/integrations?search=igor.dvlpr 😍
https://www.npmjs.com/package/@igor.dvlpr/astro-post-excerpt
MIT License
19 stars 2 forks source link

Switch to astro v2 #21

Closed igorskyflyer closed 1 year ago

igorskyflyer commented 1 year ago

🚀 Astro v2 upgrade 👨🏼‍🚀

bronze commented 1 year ago

I keep getting The required prop post is not valid, aborting now..

Im in Astro 2.0. Is that expected or am i just doing it wrong? :)

igorskyflyer commented 1 year ago

I keep getting The required prop post is not valid, aborting now..

Im in Astro 2.0. Is that expected or am i just doing it wrong? :)

Sorry that you're getting this issue but could you provide a way for me to reproduce the issue or at least look at your code, via a repository, code snippet, etc.


💡 But here is some insight first - as described in the component's README:

Post - this prop represents the post whose excerpt you want to generate and render, usually obtained via Astro.glob(), thus, you should insert this component inside your posts loop, see Astro API for more info.

If this prop is not supplied or not valid, the component will throw an error.

Meaning you should insert this component inside your posts loop, like seen here on my own Astro site:

Judging by the error you're getting - without seeing the code - it seems like you're either not rendering the component inside your posts loop or the provided prop post is of the wrong type.

I can tell you more if you provide me a reproducible code/site. 😚

Note: Astro v2 shouldn't cause this, judging by their migration guide.

bronze commented 1 year ago

this is my PostPreview.astro https://gist.github.com/bronze/e47ee1490190bd6b3609644349d2feec a bit of a frankenstein im afraid :) im thinking maybe its something on here?

const {
  post: {data: post, slug},
} = Astro.props

ps: thank your for responding

igorskyflyer commented 1 year ago

this is my PostPreview.astro gist.github.com/bronze/e47ee1490190bd6b3609644349d2feec a bit of a frankenstein im afraid :) im thinking maybe its something on here?

const {
  post: {data: post, slug},
} = Astro.props

ps: thank your for responding

Ah, yes, looking at your code, specifically lines:

I can see what's wrong, as I mentioned earlier, you're passing a prop of the CollectionEntry type instead of a prop of MarkdownInstance<Record<string, any>> type. This was a breaking change introduced in Astro v2 indeed that occurred when you switched to Collections.

Markdown documents fetched with Astro.glob() function - the old way - are of the proper MarkdownInstance<Record<string, any>> type.


I haven't played with the new Astro but I am curious though 🤔 on line 11 what does post.data contain and what its type?

You could try now on line 45:

<PostExcerpt post={post.data} words={20} addEllipsis={false} />

Does that work? This is just a theory.


If that doesn't work then Astro has made even more breaking changes and you'll have to wait until I release the new version that's compatible with Astro v2. 😌

bronze commented 1 year ago

Trying post.data breaks everything. I really dont know what the data is doing there, actually. I was trying to make pagination work and i got that from a theme on the astro.build site. here it is: https://github.com/one-aalam/astro-ink/blob/58be5b256ae5f0f0bf90cf140e41046873f949ff/src/components/PostPreview.astro from the Astro Ink Theme

igorskyflyer commented 1 year ago

Trying post.data breaks everything. I really dont know what the data is doing there, actually. I was trying to make pagination work and i got that from a theme on the astro.build site. here it is: one-aalam/astro-ink@58be5b2/src/components/PostPreview.astro from the Astro Ink Theme

Well, at least we tried 😅 That's why I said it's just a thought. Anyway, now we can be certain that the Collections break the old behavior of Markdown files. 😕

I'll have to implement a solution that works with Astro v2, as intended in this issue. 🤓

Sorry that we couldn't fix it on-the-fly here. 😪

bronze commented 1 year ago

No problem! Thank you very much for taking your time on it! :D

igorskyflyer commented 1 year ago

No problem! Thank you very much for taking your time on it! :D

Sure, no problem! I'll be looking into converting my site to Astro v2 and solving this issue, tomorrow hopefully. 🤩

Thanks for your feedback and for using my component. 🤗

igorskyflyer commented 1 year ago

🚀 Follow v2 migration guide Astro v2 migration guide. 👨🏼‍🚀

igorskyflyer commented 1 year ago

No problem! Thank you very much for taking your time on it! :D

@bronze, I've released a new version that works with both Astro \<v2 and Astro >=v2, upgrade my component in your package, and inform me if it works for you now. 🤩