Storybook for Markdown files - a React-based UI with backend adapters for Next.js and Vite.
npm install @lavizp/storymarkPeer dependencies required:
npm install react react-dom react-markdown- Create an API route:
// app/api/storymark/route.ts
import { createStorymarkHandler } from 'storymark/next'
export const GET = createStorymarkHandler({ docsPath: './docs' })- Add the UI to a page:
// app/admin/docs/page.tsx
import { StorymarkUI } from 'storymark/ui'
export default function DocsPage() {
return <StorymarkUI />
}- Configure the plugin:
// vite.config.ts
import { defineConfig } from 'vite'
import { storymarkPlugin } from 'storymark/vite'
export default defineConfig({
plugins: [
storymarkPlugin({ docsPath: './docs' })
],
})- Add the UI to your app:
// src/App.tsx
import { StorymarkUI } from 'storymark/ui'
function App() {
return <StorymarkUI />
}Pass an array to docsPath to load markdown files from multiple directories:
// Next.js
export const GET = createStorymarkHandler({
docsPath: ['./docs', './guides', './faq']
})
// Vite
storymarkPlugin({
docsPath: ['./docs', './guides', './faq']
})Each file's ID is prefixed with its folder path to avoid collisions:
// API response:
[
{ id: 'docs/getting-started', title: 'Getting Started', slug: 'docs/getting-started' },
{ id: 'docs/installation', title: 'Installation', slug: 'docs/installation' },
{ id: 'guides/api', title: 'Api', slug: 'guides/api' },
{ id: 'faq/questions', title: 'Questions', slug: 'faq/questions' }
]Fetch a specific file by its full ID:
// GET /api/storymark/docs/getting-started
// GET /api/storymark/guides/apiimport { getMarkdownList, getMarkdownFile } from 'storymark/core'
const files = getMarkdownList('./docs')
// [{ id: 'getting-started', title: 'Getting Started', slug: 'getting-started' }]
const content = getMarkdownFile('./docs', 'getting-started')
// '# Hello\n\nThis is markdown content.'
// Multiple folders
const allFiles = getMarkdownList(['./docs', './guides'])
const content = getMarkdownFile(['./docs', './guides'], 'guides/api')import { StorymarkUI } from 'storymark/ui'
<StorymarkUI
apiEndpoint="/api/storymark"
basePath="/admin/docs"
/>import { createStorymarkHandler } from 'storymark/next'
createStorymarkHandler({
docsPath: './docs',
disableInProduction: false,
})
// Multiple folders
createStorymarkHandler({
docsPath: ['./docs', './guides'],
})import { storymarkPlugin } from 'storymark/vite'
storymarkPlugin({
docsPath: './docs',
disableInProduction: false,
})
// Multiple folders
storymarkPlugin({
docsPath: ['./docs', './guides'],
})MIT