Skip to content

Commit

Permalink
feat: Story title is now optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Apr 19, 2022
1 parent f1db6d1 commit e2e3921
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions examples/vue3/src/components/Introduction.story.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<Story>
This is a demo book using Vue 3.
</Story>
</template>
4 changes: 2 additions & 2 deletions packages/histoire/src/client/server/Story.server.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineComponent({
props: {
title: {
type: String,
required: true,
default: null,
},
layout: {
Expand Down Expand Up @@ -36,7 +36,7 @@ export default defineComponent({
const story: Story = {
id: attrs.data.id,
title: props.title,
title: props.title ?? attrs.data.fileName,
layout: props.layout,
icon: props.icon,
iconColor: props.iconColor,
Expand Down
7 changes: 6 additions & 1 deletion packages/histoire/src/node/stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chokidar from 'chokidar'
import { globby } from 'globby'
import Case from 'case'
import { join } from 'pathe'
import { join, basename } from 'pathe'
import { Context } from './context.js'
import type { StoryFile } from './types.js'

Expand Down Expand Up @@ -47,10 +47,15 @@ function getAbsoluteFilePath (relativeFilePath: string) {
function addStory (relativeFilePath: string) {
const absoluteFilePath = getAbsoluteFilePath(relativeFilePath)
const fileId = Case.kebab(relativeFilePath)
let fileName = basename(relativeFilePath)
if (fileName.includes('.')) {
fileName = fileName.substring(0, fileName.indexOf('.'))
}

const file: StoryFile = {
id: fileId,
path: absoluteFilePath,
fileName,
moduleId: `/${relativeFilePath}`,
}
context.storyFiles.push(file)
Expand Down
4 changes: 4 additions & 0 deletions packages/histoire/src/node/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export interface StoryFile {
* Absolute path
*/
path: string
/**
* File name without extension
*/
fileName: string
/**
* Generated path for tree UI
*/
Expand Down

0 comments on commit e2e3921

Please sign in to comment.