-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
manager-head.html
55 lines (49 loc) · 1.2 KB
/
manager-head.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<script>
( function redirectIfStoryMoved() {
const PREVIOUSLY_EXPERIMENTAL_COMPONENTS = [
'alignmentmatrixcontrol',
'borderboxcontrol',
'bordercontrol',
'boxcontrol',
'customselectcontrol-v2',
'dimensioncontrol',
'navigation',
'navigator',
'progressbar',
'tabs',
'theme',
];
const REDIRECTS = [
{
from: /\/components-deprecated-/,
to: '/components-',
},
{
from: new RegExp(
`\/components-experimental-(?=${ PREVIOUSLY_EXPERIMENTAL_COMPONENTS.map(
( str ) => `${ str }\\b`
).join( '|' ) })`
),
to: '/components-',
},
];
const params = new URLSearchParams( window.location.search );
const matchedRedirect = REDIRECTS.find( ( { from } ) =>
from.test( params.get( 'path' ) )
);
if ( ! matchedRedirect ) {
return;
}
params.set(
'path',
params
.get( 'path' )
.replace( matchedRedirect.from, matchedRedirect.to )
);
const { pathname, origin } = window.location;
// The decodeURIComponent keeps the slashes intact, to match how Storybook presents the `path` param.
const newUrl =
new URL( pathname, origin ) + '?' + decodeURIComponent( params );
window.location.replace( newUrl );
} )();
</script>