mattjennings / sveltekit-blog-template

A SvelteKit blog template
https://sveltekit-blog-template.vercel.app
MIT License
229 stars 35 forks source link

Using variables in headings #22

Open anthonyko opened 1 year ago

anthonyko commented 1 year ago

Great blog template!

Just started using it and am wondering what I should be modifying so that I can get variables to render properly in the table of contents side panel.

I've got my markdown in my post as:

# This year is: {thisYear}

The post body renders fine, but the ToC looks like this:

CleanShot 2023-03-30 at 19 45 59@2x
mattjennings commented 1 year ago

Ah, the headings get injected to the post metadata here, which happens before the mdsvex transformation, so that's why the brackets are there.

You could query the parsed html here in lib/data/posts.js for each heading in post.metadata.headings (like ToC does) and use their innerText values instead. I think that would work.