You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/configure/sidebar-and-urls.md
+21-18Lines changed: 21 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -137,52 +137,55 @@ When Storybook generates the titles for all matching stories, they'll retain the
137
137
138
138
### Story Indexers
139
139
140
-
Story Indexers are usually responsible of crawling through your filesystem on your given glob path, and retrieve the stories that match that glob, afterwards Storybook analyzes these stories and create entries for these stories in the `index.json` (formerly `stories.json`). This `index.json` is used to populate the sidebar links based on the `title` retrieved for each story from the story file.
141
-
142
-
For CSF, it is either auto generated or retrieved from the meta configuration.
140
+
Story Indexers are a set of heuristics used by Storybook to crawl your filesystem based on a given glob pattern searching for matching stories, which is then used to generate an index.json (formerly stories.json) file responsible for populating the sidebar with the necessary information. By default, this heuristic will look for files that contain the following scheme \*.stories.@(js|jsx|ts|tsx). However, if you need, you can create your custom story indexer that you can use to include stories that have a different naming convention. For example:
143
141
144
142
<!-- prettier-ignore-start -->
145
143
146
144
<CodeSnippets
147
145
paths={[
148
-
'common/csf-3-example-title.ts.mdx',
146
+
'common/storybook-main-csf-indexer.ts.mdx',
149
147
]}
150
148
/>
151
149
152
150
<!-- prettier-ignore-end -->
153
151
154
-
While for "Docs Only" pages, that title resides in the `title` attribute of the `Meta` tag. If the `title` attribute does not exist, Storybook indexer will be looking for the `of` attribute to retrieve a CSF story and get the title from there.
152
+
### Processing custom titles
153
+
154
+
Out of the box, Storybook automatically infers the story's title based on a set of patterns, including, for example, the file's physical location. If you're working on creating a custom story indexer and you want to handle the titles based on your set of rules, you can adjust it and provide a `makeTitle` function inside the `loadCsf` function. Below is a condensed table and examples of how these patterns work and how they relate to stories.
|`titlePrefix`| Prefixes the indexed story title based on the [configuration](./overview.md#with-a-configuration-object). |
159
+
|`title`| Requires CSF and MDX.<br/>Infers the story title based on the information defined in the metadata. |
160
+
|`name`| Requires CSF and MDX.<br/> Overrides the story title based on the provided [name](../writing-stories/introduction.md#rename-stories) property. |
161
+
|`component`| Requires CSF.<br/> Generates the title based on the component property defined in the metadata. |
162
+
|`of`| Requires MDX.<br/> Retrieves the title based on the referenced story file. |
163
+
|`story export`| Requires CSF. <br/> Defines the title based on the [named story export](../api/csf.md#named-story-exports). |
164
+
|`filename`| Enabled with custom indexers.<br/> Defines the story title based on the filename parsed with the indexer. |
Typically Storybook provides indexing capabilities for files that end with `.(story|stories).@(js|ts|jsx|tsx|mdx)`. If you feel the need to include stories that have different naming convention, e.g. [`20478`](https://github.com/storybookjs/storybook/issues/20478), you will need to introduce a new story indexer.
167
-
168
177
<!-- prettier-ignore-start -->
169
178
170
179
<CodeSnippets
171
180
paths={[
172
-
'common/storybook-main-csf-indexer.js.mdx',
181
+
'common/storybook-main-story-indexer-main.ts.mdx'
173
182
]}
174
183
/>
175
184
176
185
<!-- prettier-ignore-end -->
177
186
178
-
Another example listed below for indexing `.md` & `.html` files which is already implemented by one of our community addons [`Markdown Docs`](https://storybook.js.org/addons/@sheriffmoose/storybook-md/).
187
+
<divclass="aside">
179
188
180
-
<!-- prettier-ignore-start -->
189
+
💡 Story indexers are a great way to get non-developers playing with your components and stories. They can do much more than documented here; we encourage you to check out the [`@storybook-extras/markdown`](https://storybook.js.org/addons/@storybook-extras/markdown/) to learn more about these techniques.
0 commit comments