histoire 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/client/app/App.vue +1 -1
- package/dist/client/app/codegen/vue3.js +28 -4
- package/dist/client/app/codegen/vue3.ts +32 -4
- package/dist/client/app/components/app/AppHeader.vue +10 -3
- package/dist/client/app/components/base/BaseTab.vue +46 -0
- package/dist/client/app/components/exposed/Story.vue +21 -1
- package/dist/client/app/components/exposed/Variant.vue +1 -0
- package/dist/client/app/components/misc/CheckerboardPattern.vue +32 -0
- package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -0
- package/dist/client/app/components/search/SearchItem.vue +5 -9
- package/dist/client/app/components/{StoryControls.vue → story/StoryControls.vue} +3 -3
- package/dist/client/app/components/story/StoryDocs.vue +37 -0
- package/dist/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
- package/{src/client/app/components → dist/client/app/components/story}/StoryListFolder.vue +5 -5
- package/{src/client/app/components → dist/client/app/components/story}/StoryListItem.vue +11 -6
- package/dist/client/app/components/story/StoryResponsivePreview.vue +214 -0
- package/dist/client/app/components/{StorySourceCode.vue → story/StorySourceCode.vue} +4 -8
- package/{src/client/app/components → dist/client/app/components/story}/StoryVariantGridItem.vue +14 -6
- package/dist/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
- package/dist/client/app/components/story/StoryVariantSingleView.vue +182 -0
- package/dist/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
- package/dist/client/app/global-components.js +2 -0
- package/dist/client/app/global-components.ts +3 -0
- package/dist/client/app/index.js +4 -0
- package/dist/client/app/index.ts +4 -0
- package/dist/client/app/router.js +1 -1
- package/dist/client/app/router.ts +1 -1
- package/dist/client/app/sandbox.js +37 -3
- package/dist/client/app/sandbox.ts +37 -3
- package/dist/client/app/stores/story.d.ts +15 -0
- package/dist/client/app/style/main.css +15 -0
- package/dist/client/app/style/sandbox.css +5 -0
- package/dist/client/app/style/transitions.css +12 -0
- package/dist/client/app/types.d.ts +1 -0
- package/dist/client/app/types.ts +1 -0
- package/dist/client/app/util/const.d.ts +2 -0
- package/dist/client/app/util/const.js +2 -0
- package/dist/client/app/util/const.ts +2 -0
- package/dist/client/app/util/mapping.js +3 -0
- package/dist/client/app/util/mapping.ts +2 -0
- package/dist/client/app/util/preview-settings.d.ts +16 -0
- package/dist/client/app/util/preview-settings.js +15 -0
- package/dist/client/app/util/preview-settings.ts +26 -0
- package/dist/client/app/util/reactivity.d.ts +1 -0
- package/dist/client/app/util/reactivity.js +16 -0
- package/dist/client/app/util/reactivity.ts +22 -0
- package/dist/client/app/util/scroll.d.ts +2 -0
- package/dist/client/app/util/scroll.js +24 -0
- package/dist/client/app/util/scroll.ts +27 -0
- package/dist/client/app/{composable → util}/variant.d.ts +0 -0
- package/dist/client/app/{composable → util}/variant.js +0 -0
- package/dist/client/app/{composable → util}/variant.ts +0 -0
- package/dist/client/server/Story.server.vue +25 -2
- package/dist/client/server/index.js +2 -0
- package/dist/client/server/index.ts +3 -0
- package/dist/controls.d.ts +1 -0
- package/dist/controls.js +1 -0
- package/dist/node/build.js +13 -8
- package/dist/node/collect.js +12 -3
- package/dist/node/config.d.ts +24 -2
- package/dist/node/config.js +44 -4
- package/dist/node/markdown.d.ts +2 -0
- package/dist/node/markdown.js +48 -0
- package/dist/node/plugin.js +29 -2
- package/dist/node/util/slugify.d.ts +1 -0
- package/dist/node/util/slugify.js +22 -0
- package/dist/style.css +826 -171
- package/package.json +14 -4
- package/src/client/app/App.vue +1 -1
- package/src/client/app/codegen/vue3.ts +32 -4
- package/src/client/app/components/app/AppHeader.vue +10 -3
- package/src/client/app/components/base/BaseTab.vue +46 -0
- package/src/client/app/components/exposed/Story.vue +21 -1
- package/src/client/app/components/exposed/Variant.vue +1 -0
- package/src/client/app/components/misc/CheckerboardPattern.vue +32 -0
- package/src/client/app/components/sandbox/SandboxVue3.vue +6 -0
- package/src/client/app/components/search/SearchItem.vue +5 -9
- package/src/client/app/components/{StoryControls.vue → story/StoryControls.vue} +3 -3
- package/src/client/app/components/story/StoryDocs.vue +37 -0
- package/src/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
- package/{dist/client/app/components → src/client/app/components/story}/StoryListFolder.vue +5 -5
- package/{dist/client/app/components → src/client/app/components/story}/StoryListItem.vue +11 -6
- package/src/client/app/components/story/StoryResponsivePreview.vue +214 -0
- package/src/client/app/components/{StorySourceCode.vue → story/StorySourceCode.vue} +4 -8
- package/{dist/client/app/components → src/client/app/components/story}/StoryVariantGridItem.vue +14 -6
- package/src/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
- package/src/client/app/components/story/StoryVariantSingleView.vue +182 -0
- package/src/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
- package/src/client/app/global-components.ts +3 -0
- package/src/client/app/index.ts +4 -0
- package/src/client/app/router.ts +1 -1
- package/src/client/app/sandbox.ts +37 -3
- package/src/client/app/style/main.css +15 -0
- package/src/client/app/style/sandbox.css +5 -0
- package/src/client/app/style/transitions.css +12 -0
- package/src/client/app/types.ts +1 -0
- package/src/client/app/util/const.ts +2 -0
- package/src/client/app/util/mapping.ts +2 -0
- package/src/client/app/util/preview-settings.ts +26 -0
- package/src/client/app/util/reactivity.ts +22 -0
- package/src/client/app/util/scroll.ts +27 -0
- package/src/client/app/{composable → util}/variant.ts +0 -0
- package/src/client/server/Story.server.vue +25 -2
- package/src/client/server/index.ts +3 -0
- package/src/controls.ts +1 -0
- package/src/node/build.ts +15 -8
- package/src/node/collect.ts +12 -3
- package/src/node/config.ts +69 -6
- package/src/node/markdown.ts +56 -0
- package/src/node/plugin.ts +31 -2
- package/src/node/util/slugify.ts +26 -0
- package/tailwind.config.cjs +79 -4
- package/dist/client/app/components/StoryVariantSingleView.vue +0 -173
- package/src/client/app/components/StoryVariantSingleView.vue +0 -173
package/dist/node/build.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import { join } from 'pathe';
|
|
2
|
-
import { build as viteBuild, createServer as createViteServer
|
|
2
|
+
import { build as viteBuild, createServer as createViteServer } from 'vite';
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
4
|
import { lookup as lookupMime } from 'mrmime';
|
|
5
|
+
import pc from 'picocolors';
|
|
6
|
+
import { performance } from 'perf_hooks';
|
|
5
7
|
import { APP_PATH } from './alias.js';
|
|
6
8
|
import { createVitePlugins } from './plugin.js';
|
|
7
9
|
import { findAllStories } from './stories.js';
|
|
8
10
|
import { useCollectStories } from './collect.js';
|
|
9
11
|
export async function build(ctx) {
|
|
12
|
+
const startTime = performance.now();
|
|
10
13
|
await findAllStories(ctx);
|
|
11
14
|
// Collect story data
|
|
12
|
-
const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
|
|
13
|
-
const plugins = [];
|
|
14
|
-
const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue');
|
|
15
|
-
if (!hasVuePlugin) {
|
|
16
|
-
plugins.push((await import('@vitejs/plugin-vue')).default());
|
|
17
|
-
}
|
|
18
15
|
const server = await createViteServer({
|
|
19
|
-
plugins,
|
|
16
|
+
plugins: await createVitePlugins(ctx),
|
|
20
17
|
});
|
|
21
18
|
await server.pluginContainer.buildStart({});
|
|
22
19
|
const { executeStoryFile, destroy: destroyCollectStories } = useCollectStories({
|
|
@@ -28,6 +25,9 @@ export async function build(ctx) {
|
|
|
28
25
|
}
|
|
29
26
|
await server.close();
|
|
30
27
|
await destroyCollectStories();
|
|
28
|
+
const storyCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ? 1 : 0), 0);
|
|
29
|
+
const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0);
|
|
30
|
+
const emptyStoryCount = ctx.storyFiles.length - storyCount;
|
|
31
31
|
const results = await viteBuild({
|
|
32
32
|
plugins: await createVitePlugins(ctx),
|
|
33
33
|
build: {
|
|
@@ -50,6 +50,11 @@ export async function build(ctx) {
|
|
|
50
50
|
// Sandbox
|
|
51
51
|
const sandboxOutput = result.output.find(o => o.name === 'sandbox' && o.type === 'chunk');
|
|
52
52
|
await writeHtml(sandboxOutput.fileName, styleOutput.fileName, '__sandbox.html', ctx);
|
|
53
|
+
const duration = performance.now() - startTime;
|
|
54
|
+
if (emptyStoryCount) {
|
|
55
|
+
console.warn(pc.yellow(`⚠️ ${emptyStoryCount} empty story file`));
|
|
56
|
+
}
|
|
57
|
+
console.log(pc.green(`✅ Built ${storyCount} stories (${variantCount} variants) in ${Math.round(duration / 1000 * 100) / 100}s`));
|
|
53
58
|
}
|
|
54
59
|
async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, ctx) {
|
|
55
60
|
const code = `<!DOCTYPE html>
|
package/dist/node/collect.js
CHANGED
|
@@ -9,7 +9,13 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
9
9
|
export function useCollectStories(options, ctx) {
|
|
10
10
|
const { server } = options;
|
|
11
11
|
const { destroy: destroyDomEnv } = createDomEnv();
|
|
12
|
-
const node = new ViteNodeServer(server
|
|
12
|
+
const node = new ViteNodeServer(server, {
|
|
13
|
+
deps: {
|
|
14
|
+
inline: [
|
|
15
|
+
/histoire\/dist/,
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
});
|
|
13
19
|
const runner = new ViteNodeRunner({
|
|
14
20
|
root: server.config.root,
|
|
15
21
|
base: server.config.base,
|
|
@@ -20,6 +26,9 @@ export function useCollectStories(options, ctx) {
|
|
|
20
26
|
}
|
|
21
27
|
return node.fetchModule(id);
|
|
22
28
|
},
|
|
29
|
+
resolveId(id, importer) {
|
|
30
|
+
return node.resolveId(id, importer);
|
|
31
|
+
},
|
|
23
32
|
});
|
|
24
33
|
function clearCache() {
|
|
25
34
|
node.fetchCache.clear();
|
|
@@ -33,11 +42,11 @@ export function useCollectStories(options, ctx) {
|
|
|
33
42
|
const storyData = [];
|
|
34
43
|
await run(storyFile, storyData, el);
|
|
35
44
|
if (storyData.length === 0) {
|
|
36
|
-
console.warn(pc.yellow(
|
|
45
|
+
console.warn(pc.yellow(`⚠️ No story found for ${storyFile.path}`));
|
|
37
46
|
return;
|
|
38
47
|
}
|
|
39
48
|
else if (storyData.length > 1) {
|
|
40
|
-
console.warn(pc.yellow(
|
|
49
|
+
console.warn(pc.yellow(`⚠️ Multiple stories not supported: ${storyFile.path}`));
|
|
41
50
|
}
|
|
42
51
|
storyFile.story = storyData[0];
|
|
43
52
|
const file = {
|
package/dist/node/config.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { UserConfig as ViteConfig } from 'vite';
|
|
1
|
+
import { UserConfig as ViteConfig, ConfigEnv as ViteConfigEnv } from 'vite';
|
|
2
2
|
import { TreeFile } from './tree.js';
|
|
3
|
+
import type MarkdownIt from 'markdown-it';
|
|
3
4
|
declare type CustomizableColors = 'primary' | 'gray';
|
|
4
5
|
declare type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
|
|
5
6
|
declare type GrayColorKeys = ColorKeys | '750' | '850' | '950';
|
|
6
7
|
interface ResponsivePreset {
|
|
7
8
|
label: string;
|
|
8
9
|
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
interface BackgroundPreset {
|
|
13
|
+
label: string;
|
|
14
|
+
color: string;
|
|
9
15
|
}
|
|
10
16
|
export interface HistoireConfig {
|
|
11
17
|
/**
|
|
@@ -79,6 +85,10 @@ export interface HistoireConfig {
|
|
|
79
85
|
[key in ColorKeys]?: string;
|
|
80
86
|
};
|
|
81
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Add a link to the main logo
|
|
90
|
+
*/
|
|
91
|
+
logoHref?: string;
|
|
82
92
|
};
|
|
83
93
|
/**
|
|
84
94
|
* Setup file exposting a default function executed when setting up each story preview.
|
|
@@ -92,10 +102,22 @@ export interface HistoireConfig {
|
|
|
92
102
|
* Predefined responsive sizes for story playgrounds.
|
|
93
103
|
*/
|
|
94
104
|
responsivePresets?: ResponsivePreset[];
|
|
105
|
+
/**
|
|
106
|
+
* Background color of the story preview.
|
|
107
|
+
*/
|
|
108
|
+
backgroundPresets?: BackgroundPreset[];
|
|
109
|
+
/**
|
|
110
|
+
* Class added to the html root of the story preview when dark mode is enabled.
|
|
111
|
+
*/
|
|
112
|
+
sandboxDarkClass?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Customize the markdown-it renderer
|
|
115
|
+
*/
|
|
116
|
+
markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>;
|
|
95
117
|
/**
|
|
96
118
|
* Vite config override
|
|
97
119
|
*/
|
|
98
|
-
vite?: ViteConfig;
|
|
120
|
+
vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>);
|
|
99
121
|
}
|
|
100
122
|
export declare function getDefaultConfig(): HistoireConfig;
|
|
101
123
|
export declare const configFileNames: string[];
|
package/dist/node/config.js
CHANGED
|
@@ -26,36 +26,67 @@ export function getDefaultConfig() {
|
|
|
26
26
|
{
|
|
27
27
|
label: 'Mobile (Small)',
|
|
28
28
|
width: 320,
|
|
29
|
+
height: 560,
|
|
29
30
|
},
|
|
30
31
|
{
|
|
31
32
|
label: 'Mobile (Medium)',
|
|
32
|
-
width:
|
|
33
|
+
width: 360,
|
|
34
|
+
height: 640,
|
|
33
35
|
},
|
|
34
36
|
{
|
|
35
37
|
label: 'Mobile (Large)',
|
|
36
|
-
width:
|
|
38
|
+
width: 414,
|
|
39
|
+
height: 896,
|
|
37
40
|
},
|
|
38
41
|
{
|
|
39
42
|
label: 'Tablet',
|
|
40
43
|
width: 768,
|
|
44
|
+
height: 1024,
|
|
41
45
|
},
|
|
42
46
|
{
|
|
43
47
|
label: 'Laptop (Small)',
|
|
44
48
|
width: 1024,
|
|
49
|
+
height: null,
|
|
45
50
|
},
|
|
46
51
|
{
|
|
47
52
|
label: 'Laptop (Large)',
|
|
48
|
-
width:
|
|
53
|
+
width: 1366,
|
|
54
|
+
height: null,
|
|
49
55
|
},
|
|
50
56
|
{
|
|
51
57
|
label: 'Desktop',
|
|
52
58
|
width: 1920,
|
|
59
|
+
height: null,
|
|
53
60
|
},
|
|
54
61
|
{
|
|
55
62
|
label: '4K',
|
|
56
63
|
width: 3840,
|
|
64
|
+
height: null,
|
|
57
65
|
},
|
|
58
66
|
],
|
|
67
|
+
backgroundPresets: [
|
|
68
|
+
{
|
|
69
|
+
label: 'Transparent',
|
|
70
|
+
color: 'transparent',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
label: 'White',
|
|
74
|
+
color: '#fff',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
label: 'Light gray',
|
|
78
|
+
color: '#aaa',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: 'Dark gray',
|
|
82
|
+
color: '#333',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
label: 'Black',
|
|
86
|
+
color: '#000',
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
sandboxDarkClass: 'dark',
|
|
59
90
|
};
|
|
60
91
|
}
|
|
61
92
|
export const configFileNames = [
|
|
@@ -86,12 +117,21 @@ export async function loadConfigFile(configFile) {
|
|
|
86
117
|
try {
|
|
87
118
|
const server = await createServer();
|
|
88
119
|
await server.pluginContainer.buildStart({});
|
|
89
|
-
const node = new ViteNodeServer(server
|
|
120
|
+
const node = new ViteNodeServer(server, {
|
|
121
|
+
deps: {
|
|
122
|
+
inline: [
|
|
123
|
+
/histoire\/dist/,
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
});
|
|
90
127
|
const runner = new ViteNodeRunner({
|
|
91
128
|
root: path.dirname(configFile),
|
|
92
129
|
fetchModule(id) {
|
|
93
130
|
return node.fetchModule(id);
|
|
94
131
|
},
|
|
132
|
+
resolveId(id, importer) {
|
|
133
|
+
return node.resolveId(id, importer);
|
|
134
|
+
},
|
|
95
135
|
});
|
|
96
136
|
const result = await runner.executeFile(configFile);
|
|
97
137
|
await server.close();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import shiki from 'shiki';
|
|
3
|
+
import anchor from 'markdown-it-anchor';
|
|
4
|
+
import attrs from 'markdown-it-attrs';
|
|
5
|
+
import emoji from 'markdown-it-emoji';
|
|
6
|
+
import { slugify } from './util/slugify.js';
|
|
7
|
+
export async function createMarkdownRenderer() {
|
|
8
|
+
const highlighter = await shiki.getHighlighter({
|
|
9
|
+
theme: 'github-dark',
|
|
10
|
+
});
|
|
11
|
+
const md = new MarkdownIt({
|
|
12
|
+
highlight: (code, lang) => `<div class="htw-relative htw-not-prose __histoire-code"><div class="htw-absolute htw-top-0 htw-right-0 htw-text-xs htw-text-white/40">${lang}</div>${highlighter.codeToHtml(code, {
|
|
13
|
+
lang,
|
|
14
|
+
})}</div>`,
|
|
15
|
+
linkify: true,
|
|
16
|
+
html: true,
|
|
17
|
+
breaks: true,
|
|
18
|
+
});
|
|
19
|
+
md.use(anchor, {
|
|
20
|
+
slugify,
|
|
21
|
+
permalink: anchor.permalink.ariaHidden({}),
|
|
22
|
+
})
|
|
23
|
+
.use(attrs)
|
|
24
|
+
.use(emoji);
|
|
25
|
+
// External links
|
|
26
|
+
{
|
|
27
|
+
const defaultRender = md.renderer.rules.link_open || function (tokens, idx, options, env, self) {
|
|
28
|
+
return self.renderToken(tokens, idx, options);
|
|
29
|
+
};
|
|
30
|
+
md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
|
|
31
|
+
const hrefIndex = tokens[idx].attrIndex('href');
|
|
32
|
+
const classIndex = tokens[idx].attrIndex('class');
|
|
33
|
+
if (hrefIndex >= 0 && !tokens[idx].attrs[hrefIndex][1].startsWith('/') && (classIndex < 0 || !tokens[idx].attrs[classIndex][1].includes('header-anchor'))) {
|
|
34
|
+
// If you are sure other plugins can't add `target` - drop check below
|
|
35
|
+
const aIndex = tokens[idx].attrIndex('target');
|
|
36
|
+
if (aIndex < 0) {
|
|
37
|
+
tokens[idx].attrPush(['target', '_blank']); // add new attribute
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
tokens[idx].attrs[aIndex][1] = '_blank'; // replace value of existing attr
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// pass token to default renderer.
|
|
44
|
+
return defaultRender(tokens, idx, options, env, self);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return md;
|
|
48
|
+
}
|
package/dist/node/plugin.js
CHANGED
|
@@ -5,6 +5,7 @@ import { APP_PATH, DIST_CLIENT_PATH } from './alias.js';
|
|
|
5
5
|
import { notifyStoryChange } from './stories.js';
|
|
6
6
|
import { makeTree } from './tree.js';
|
|
7
7
|
import { parseColor } from './colors.js';
|
|
8
|
+
import { createMarkdownRenderer } from './markdown.js';
|
|
8
9
|
export const STORIES_ID = '$histoire-stories';
|
|
9
10
|
export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`;
|
|
10
11
|
export const SETUP_ID = '$histoire-setup';
|
|
@@ -23,8 +24,8 @@ export async function createVitePlugins(ctx) {
|
|
|
23
24
|
if (ctx.config.vite) {
|
|
24
25
|
plugins.push({
|
|
25
26
|
name: 'histoire-vite-config-override',
|
|
26
|
-
config() {
|
|
27
|
-
return ctx.config.vite;
|
|
27
|
+
config(config, env) {
|
|
28
|
+
return typeof ctx.config.vite === 'function' ? ctx.config.vite(config, env) : ctx.config.vite;
|
|
28
29
|
},
|
|
29
30
|
});
|
|
30
31
|
}
|
|
@@ -188,6 +189,8 @@ if (import.meta.hot) {
|
|
|
188
189
|
};
|
|
189
190
|
},
|
|
190
191
|
});
|
|
192
|
+
// Custom blocks
|
|
193
|
+
plugins.push(...await createCustomBlocksPlugins(ctx));
|
|
191
194
|
if (ctx.mode === 'build') {
|
|
192
195
|
// Add file name in build mode to have components names instead of <Anonymous>
|
|
193
196
|
const include = [/\.vue$/];
|
|
@@ -209,3 +212,27 @@ if (import.meta.hot) {
|
|
|
209
212
|
}
|
|
210
213
|
return plugins;
|
|
211
214
|
}
|
|
215
|
+
async function createCustomBlocksPlugins(ctx) {
|
|
216
|
+
const plugins = [];
|
|
217
|
+
let md = await createMarkdownRenderer();
|
|
218
|
+
if (ctx.config.markdown) {
|
|
219
|
+
const result = await ctx.config.markdown(md);
|
|
220
|
+
if (result) {
|
|
221
|
+
md = result;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
plugins.push({
|
|
225
|
+
name: 'histoire-vue-docs-block',
|
|
226
|
+
transform(code, id) {
|
|
227
|
+
if (!id.includes('?vue&type=docs'))
|
|
228
|
+
return;
|
|
229
|
+
if (!id.includes('lang.md'))
|
|
230
|
+
return;
|
|
231
|
+
const html = md.render(code);
|
|
232
|
+
return `export default Comp => {
|
|
233
|
+
Comp.doc = ${JSON.stringify(html)}
|
|
234
|
+
}`;
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
return plugins;
|
|
238
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const slugify: (str: string) => string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// From vitepress
|
|
2
|
+
// string.js slugify drops non ascii chars so we have to
|
|
3
|
+
// use a custom implementation here
|
|
4
|
+
import { remove as removeDiacritics } from 'diacritics';
|
|
5
|
+
// eslint-disable-next-line no-control-regex
|
|
6
|
+
const rControl = /[\u0000-\u001f]/g;
|
|
7
|
+
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g;
|
|
8
|
+
export const slugify = (str) => {
|
|
9
|
+
return (removeDiacritics(str)
|
|
10
|
+
// Remove control characters
|
|
11
|
+
.replace(rControl, '')
|
|
12
|
+
// Replace special characters
|
|
13
|
+
.replace(rSpecial, '-')
|
|
14
|
+
// Remove continuous separators
|
|
15
|
+
.replace(/-{2,}/g, '-')
|
|
16
|
+
// Remove prefixing and trailing separators
|
|
17
|
+
.replace(/^-+|-+$/g, '')
|
|
18
|
+
// ensure it doesn't start with a number (#121)
|
|
19
|
+
.replace(/^(\d)/, '_$1')
|
|
20
|
+
// lowercase
|
|
21
|
+
.toLowerCase());
|
|
22
|
+
};
|