Repository navigation
Add a Sätteri tab in the remark/rehype recipes - #14277
Conversation
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
|
Preview deployment ✅ Deployment complete!
|
| import getReadingTime from 'reading-time'; | ||
| import { defineMdastPlugin, type MdastNode } from 'satteri'; | ||
|
|
||
| const findRoot = ( |
There was a problem hiding this comment.
This is verbose compared to the remark version but, AFAIK, this is the best way in Sätteri; I've done the same thing when porting my website. Parsing ctx.source instead seems to work with Markdown files but this is not reliable with MDX (components, custom plugins).
There was a problem hiding this comment.
For now yeah, next minor will include a way to get the root before and after mutations, which should work for this usecase
|
|
||
| export const mdastReadingTimePlugin = defineMdastPlugin({ | ||
| name: "mdast-reading-time", | ||
| text(node, context) { |
There was a problem hiding this comment.
Not sure if there is something better than the text() visitor here. Because it runs multiple times for the same file, we need to check if the frontmatter property is set to return early.
| element: { | ||
| filter: ["a"], | ||
| visit(node, context) { | ||
| if (node.properties.href?.startsWith("http")) { |
There was a problem hiding this comment.
I think this will result in a type error, but it's honestly Sätteri's fault, I'll fix it
There was a problem hiding this comment.
I haven't noticed anything locally, and astro check reports nothing. 👀
There was a problem hiding this comment.
It turns out that if you have the latest version of @types/hast it's okay, but Sätteri itself peer deps isn't on latest
|
I see that the root visitor is almost there (withastro/astro#17731). @Princesseuh Would you prefer to wait for it, or does a later update of the recipe work for you? If it's the latter, can I get an explicit approval before merging this? 😄 |
|
I merged the root visitor (note that it's a before / after hooks, but this should work for this use case). If you have the motivation, I'd say to rewrite these docs for the new hooks just to avoid people ruining their performance and never updating after BUT, I'll approve nonetheless, because at the end of the day, the world is infinite, so is our ambition and this is still better than current. |
|
Thank you! 🙌🏽 So, I'm going to merge this and I'll try to quickly update that recipe once withastro/astro#17739 is released. As you said, it's best to showcase best practices with Sätteri for performance! |
Description (required)
Since Astro 7, Sätteri is the default Markdown processor, but our recipes were still using remark/rehype. This adds Sätteri/Unified tabs to them!
external-links.mdx:<Steps />nested inside<Tabs />as the content is different enoughmodified-time.mdxandreading-time.mdx:<Tabs />nested inside<Steps />as the content is pretty similarIf you want to check/play with the plugins:
Note that git is not available on Stackblitz, so you'll need to download the repro, init Git, and make an initial commit.
In addition, I updated a few other things:
external-links.mdx: Removes the callout at the end as the statement is wrong.rehype-external-linksdoes not use the CSScontentproperty but a<span />to inject the content (see https://www.npmjs.com/package/rehype-external-links#fields). So, the icon is in the accessibility tree. Now, I agree this is not the best for accessibility but it doesn't seem like we have control on the<span>(e.g. to setaria-hidden: true).modified-time.mdxandreading-time.mdx, continuing my series on fixing code snippets issues:<head>...</head>is formatted to<head></head>...so I added some content in there instead.<meta charset="utf-8" / >is expected since v5