Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-scroll-area": "1.2.0-rc.7",
"@radix-ui/react-slot": "^1.0.2",
"@storybook/docs-mdx": "4.0.0-next.1",
"@storybook/docs-mdx": "3.1.1--canary.16.129f63c.0",
"@storybook/global": "^5.0.0",
"@storybook/icons": "^1.2.10",
"@tanstack/react-virtual": "^3.3.0",
Expand Down
62 changes: 62 additions & 0 deletions code/core/src/core-server/utils/StoryIndexGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ describe('StoryIndexGenerator', () => {
"type": "story",
},
"b--docs": {
"headings": [
"Story One",
],
"id": "b--docs",
"importPath": "./src/B.stories.ts",
"name": "docs",
Expand Down Expand Up @@ -570,6 +573,9 @@ describe('StoryIndexGenerator', () => {
"type": "story",
},
"d--docs": {
"headings": [
"Story One",
],
"id": "d--docs",
"importPath": "./src/D.stories.jsx",
"name": "docs",
Expand Down Expand Up @@ -670,6 +676,9 @@ describe('StoryIndexGenerator', () => {
"type": "story",
},
"h--docs": {
"headings": [
"Story One",
],
"id": "h--docs",
"importPath": "./src/H.stories.mjs",
"name": "docs",
Expand Down Expand Up @@ -917,6 +926,9 @@ describe('StoryIndexGenerator', () => {
{
"entries": {
"b--docs": {
"headings": [
"Story One",
],
"id": "b--docs",
"importPath": "./src/B.stories.ts",
"name": "docs",
Expand All @@ -930,6 +942,9 @@ describe('StoryIndexGenerator', () => {
"type": "docs",
},
"b--metaofnoname": {
"headings": [
"Docs with of",
],
"id": "b--metaofnoname",
"importPath": "./errors/MetaOfNoName.mdx",
"name": "MetaOfNoName",
Expand Down Expand Up @@ -982,6 +997,9 @@ describe('StoryIndexGenerator', () => {
{
"entries": {
"b--docs": {
"headings": [
"Story One",
],
"id": "b--docs",
"importPath": "./src/B.stories.ts",
"name": "docs",
Expand All @@ -995,6 +1013,9 @@ describe('StoryIndexGenerator', () => {
"type": "docs",
},
"b--name": {
"headings": [
"Docs with of",
],
"id": "b--name",
"importPath": "./errors/MetaOfName.mdx",
"name": "name",
Expand Down Expand Up @@ -1051,6 +1072,9 @@ describe('StoryIndexGenerator', () => {
{
"entries": {
"a--docs": {
"headings": [
"Docs with of",
],
"id": "a--docs",
"importPath": "./errors/A.mdx",
"name": "docs",
Expand Down Expand Up @@ -1161,6 +1185,9 @@ describe('StoryIndexGenerator', () => {
{
"entries": {
"duplicate-a--docs": {
"headings": [
"Story One",
],
"id": "duplicate-a--docs",
"importPath": "./duplicate/A.stories.js",
"name": "docs",
Expand Down Expand Up @@ -1240,6 +1267,9 @@ describe('StoryIndexGenerator', () => {
{
"entries": {
"my-component-a--docs": {
"headings": [
"Story One",
],
"id": "my-component-a--docs",
"importPath": "./docs-id-generation/A.stories.jsx",
"name": "docs",
Expand Down Expand Up @@ -1282,6 +1312,9 @@ describe('StoryIndexGenerator', () => {
{
"entries": {
"a--metaof": {
"headings": [
"Docs with of",
],
"id": "a--metaof",
"importPath": "./src/docs2/MetaOf.mdx",
"name": "MetaOf",
Expand All @@ -1299,6 +1332,9 @@ describe('StoryIndexGenerator', () => {
"type": "docs",
},
"a--second-docs": {
"headings": [
"Second Docs",
],
"id": "a--second-docs",
"importPath": "./src/docs2/SecondMetaOf.mdx",
"name": "Second Docs",
Expand Down Expand Up @@ -1330,6 +1366,7 @@ describe('StoryIndexGenerator', () => {
"type": "story",
},
"componentreference--docs": {
"headings": [],
"id": "componentreference--docs",
"importPath": "./src/docs2/ComponentReference.mdx",
"name": "docs",
Expand All @@ -1343,6 +1380,9 @@ describe('StoryIndexGenerator', () => {
"type": "docs",
},
"docs2-yabbadabbadooo--docs": {
"headings": [
"Docs with title",
],
"id": "docs2-yabbadabbadooo--docs",
"importPath": "./src/docs2/Title.mdx",
"name": "docs",
Expand All @@ -1356,6 +1396,9 @@ describe('StoryIndexGenerator', () => {
"type": "docs",
},
"notitle--docs": {
"headings": [
"Docs with no title",
],
"id": "notitle--docs",
"importPath": "./src/docs2/NoTitle.mdx",
"name": "docs",
Expand Down Expand Up @@ -1417,6 +1460,9 @@ describe('StoryIndexGenerator', () => {
{
"entries": {
"a--metaof": {
"headings": [
"Docs with of",
],
"id": "a--metaof",
"importPath": "./src/docs2/MetaOf.mdx",
"name": "MetaOf",
Expand All @@ -1434,6 +1480,9 @@ describe('StoryIndexGenerator', () => {
"type": "docs",
},
"a--second-docs": {
"headings": [
"Second Docs",
],
"id": "a--second-docs",
"importPath": "./src/docs2/SecondMetaOf.mdx",
"name": "Second Docs",
Expand Down Expand Up @@ -1465,6 +1514,7 @@ describe('StoryIndexGenerator', () => {
"type": "story",
},
"componentreference--info": {
"headings": [],
"id": "componentreference--info",
"importPath": "./src/docs2/ComponentReference.mdx",
"name": "Info",
Expand All @@ -1478,6 +1528,9 @@ describe('StoryIndexGenerator', () => {
"type": "docs",
},
"docs2-yabbadabbadooo--info": {
"headings": [
"Docs with title",
],
"id": "docs2-yabbadabbadooo--info",
"importPath": "./src/docs2/Title.mdx",
"name": "Info",
Expand All @@ -1491,6 +1544,9 @@ describe('StoryIndexGenerator', () => {
"type": "docs",
},
"notitle--info": {
"headings": [
"Docs with no title",
],
"id": "notitle--info",
"importPath": "./src/docs2/NoTitle.mdx",
"name": "Info",
Expand Down Expand Up @@ -1551,6 +1607,9 @@ describe('StoryIndexGenerator', () => {
"type": "story",
},
"b--twostoryreferences": {
"headings": [
"This file references two story files",
],
"id": "b--twostoryreferences",
"importPath": "./complex/TwoStoryReferences.mdx",
"name": "TwoStoryReferences",
Expand Down Expand Up @@ -1592,6 +1651,9 @@ describe('StoryIndexGenerator', () => {
{
"entries": {
"my-component-b--docs": {
"headings": [
"Docs with of",
],
"id": "my-component-b--docs",
"importPath": "./docs-id-generation/B.docs.mdx",
"name": "docs",
Expand Down
4 changes: 4 additions & 0 deletions code/core/src/core-server/utils/StoryIndexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ export class StoryIndexGenerator {
type: 'docs',
tags,
storiesImports: [],
headings: indexInputs.map((input) => input.name).filter(Boolean) as string[],
});
}

Expand All @@ -438,6 +439,8 @@ export class StoryIndexGenerator {
const { analyze } = await import('@storybook/docs-mdx');
const result = await analyze(content);

// console.log({ absolutePath, headings: result.headings });

// Templates are not indexed
if (result.isTemplate) {
return false;
Expand Down Expand Up @@ -522,6 +525,7 @@ export class StoryIndexGenerator {
storiesImports: sortedDependencies.map((dep) => dep.entries[0].importPath),
type: 'docs',
tags,
headings: result.headings || [],
};
return docsEntry;
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ describe('docs entries from story extraction', () => {
"dependents": [],
"entries": [
{
"headings": [
"Story One",
],
"id": "a--docs",
"importPath": "./src/A.stories.js",
"name": "docs",
Expand Down
13 changes: 13 additions & 0 deletions code/core/src/core-server/utils/stories-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ describe('useStoriesJson', () => {
{
"entries": {
"a--metaof": {
"headings": [
"Docs with of",
],
"id": "a--metaof",
"importPath": "./src/docs2/MetaOf.mdx",
"name": "MetaOf",
Expand All @@ -127,6 +130,9 @@ describe('useStoriesJson', () => {
"type": "docs",
},
"a--second-docs": {
"headings": [
"Second Docs",
],
"id": "a--second-docs",
"importPath": "./src/docs2/SecondMetaOf.mdx",
"name": "Second Docs",
Expand Down Expand Up @@ -217,6 +223,7 @@ describe('useStoriesJson', () => {
"type": "story",
},
"docs2-componentreference--docs": {
"headings": [],
"id": "docs2-componentreference--docs",
"importPath": "./src/docs2/ComponentReference.mdx",
"name": "docs",
Expand All @@ -230,6 +237,9 @@ describe('useStoriesJson', () => {
"type": "docs",
},
"docs2-notitle--docs": {
"headings": [
"Docs with no title",
],
"id": "docs2-notitle--docs",
"importPath": "./src/docs2/NoTitle.mdx",
"name": "docs",
Expand All @@ -243,6 +253,9 @@ describe('useStoriesJson', () => {
"type": "docs",
},
"docs2-yabbadabbadooo--docs": {
"headings": [
"Docs with title",
],
"id": "docs2-yabbadabbadooo--docs",
"importPath": "./src/docs2/Title.mdx",
"name": "docs",
Expand Down
Loading