SvelteKit Blog: Add frontmatter data to posts

Jan 8, 2022
< >

Notice. This was written pre SvelteKit 1.0.0. With the release of SvelteKit 1.0.0 some things changed. Especially the folder and routing structure. The solution in this blog post isn’t compatible with version 1.0.0.

With mdsvex it was possible to transform my markdown files to html files. Besides the post text, the markdown files contain a frontmatter with pieces of information about the post title and the creation date.

I wanted to access the information in my blog post layout file (link to post) to add this information to the header of the post.

Sketch of the task: How to get the frontmatter data to the blog post layout file.

But I didn’t really know how to access the data in the blog-post layout file.

But then I read the mdsvex doc and was surprised.

With mdsvex and svelte props this was super easy because mdsvex passes the frontmatter data to available props in the layout file.

The frontmatter data is injected to the mdsvex layout file.


</ >