In this lesson, you'll learn about the path
configuration for Keystatic collections and singletons. It gives you a lot of flexibility over where your content should be stored on your file system.
[00:00] Each collection and singleton in key static takes an optional path property, which is where your content is going to be stored. Right now it's set to post slash star, and so as a result our posts are stored in post and then star means the slug for each file. But say you wanted to put all of your content, all your collections inside a content directory. [00:20] Well, you could change the path to content slash posts, but saving that means Key static will not find these 2 existing posts anymore. In the admin UI, you can see there is 0 posts, but let's create 1. And KeyStarrick now lists 1 post and, as expected, a new [00:40] content folder with posts and then our posts here has been created. So we don't need to recreate our post. We can grab these 2 and drag them inside this folder. And now if I refresh the admin UI, we will have our 3 posts listed here. Couple more things to cover. You can see right now each post is its own markdoc file, and this is what happens if your [00:59] path ends without a trailing slash. If I add a trailing slash, this means something different for key static. It's going to expect each post to be a folder with the slug name and then an index dot markdoc file in each. And that can be useful when you want multiple files for each collection entry. Once again, we're back to 0 posts and let's create 1. [01:22] And when I have 1 post and if we look at the code base, you can see that this one was created in a directory with an index dot markdoc file. If you need more complex path structures, you can also use the star in the middle of a segment. So say you had here my folder. And again, trailing slash or not will define if it's a single file [01:42] or a directory. We're back to 0 posts. So the slug of our post was hello. So inside content slash post, we have the hello directory and then my, so hello my folder. And because there is no trailing slash, folder is the name of the file. So the [02:02] differentiator here, the slug, is set at the directory level midway through the directory tree. And one last thing I wanna show you, if you want to use nested slugs that span across multiple directories, you can use the double star symbol. And you can see that now all of our posts are being recognized because KeyStatic is [02:22] looking inside the post directory and then any nested directories inside of it. This is possible because behind the scenes, key static supports the slash symbol part of the slug. So you can see here the slug is actually a string with slashes.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!