1
1
let allMenus , navLinks , versionsLinks ;
2
2
3
+ const STORYBOOK_PATH_META_SELECTOR = 'meta[name="storybook_path"]' ;
4
+
3
5
function hideTips ( ) {
4
6
const tipElement = document . getElementById ( 'tip' ) ;
5
7
const tipContainer = document . getElementById ( 'tip-container' ) ;
@@ -58,11 +60,11 @@ function buildPageToC() {
58
60
hasInnerContainers : true ,
59
61
} ) ;
60
62
61
- const storybookPathMeta = document . querySelector (
62
- 'meta[name="storybook_path"]'
63
- ) ;
63
+ const storybookPathMetaContent = document . querySelector (
64
+ STORYBOOK_PATH_META_SELECTOR
65
+ ) . content ;
64
66
const tocList = document . querySelector ( '.toc-list' ) ;
65
- if ( ! tocList || ! storybookPathMeta ) {
67
+ if ( ! tocList || ! storybookPathMetaContent ) {
66
68
return ;
67
69
}
68
70
@@ -71,13 +73,13 @@ function buildPageToC() {
71
73
72
74
const storybookLink = document . createElement ( 'a' ) ;
73
75
storybookLink . className = 'toc-link' ;
74
- storybookLink . href = `https://react-admin-storybook.vercel.app?path=/story/${ storybookPathMeta . content } ` ;
76
+ storybookLink . href = `https://react-admin-storybook.vercel.app?path=/story/${ storybookPathMetaContent } ` ;
75
77
storybookLink . textContent = 'Storybook' ;
76
78
storybookLink . target = '_blank' ;
77
79
storybookLink . rel = 'noopener noreferrer' ;
78
80
79
81
const storybookLaunchIcon = document . createElement ( 'img' ) ;
80
- storybookLaunchIcon . src = '/img/icons/launch.png' ;
82
+ storybookLaunchIcon . src = '. /img/icons/launch.png' ;
81
83
storybookLaunchIcon . alt = 'Open Storybook' ;
82
84
storybookLaunchIcon . className = 'toc-link-icon' ;
83
85
@@ -106,6 +108,15 @@ function replaceContent(text) {
106
108
content . innerHTML = tmpContent . innerHTML ;
107
109
}
108
110
111
+ const newStorybookPathMeta = tmpElement . querySelector (
112
+ STORYBOOK_PATH_META_SELECTOR
113
+ ) ;
114
+
115
+ const newStorybookPathContent = newStorybookPathMeta ?. content ?? '' ;
116
+ document
117
+ . querySelector ( STORYBOOK_PATH_META_SELECTOR )
118
+ . setAttribute ( 'content' , newStorybookPathContent ) ;
119
+
109
120
window . scrollTo ( 0 , 0 ) ;
110
121
111
122
buildPageToC ( ) ;
0 commit comments