Skip to content

Commit 73c5999

Browse files
authored
Merge pull request #10822 from marmelab/fix/link-storybook
Fix(doc): Update storybook link when switching documentation page
2 parents c75dd3c + b091b6e commit 73c5999

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

docs/_layouts/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<meta name="viewport" content="width=device-width, initial-scale=1" />
1111
<meta name="apple-mobile-web-app-capable" content="yes" />
1212
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
13-
{% if page.storybook_path %}<meta name="storybook_path" content="{{ page.storybook_path }}" />{% endif %}
13+
<meta name="storybook_path" content="{{ page.storybook_path }}" />
1414
<link
1515
rel="canonical"
1616
href="{{ page.name | replace: '.md', '.html' | relative_url }}"

docs/js/ra-navigation.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
let allMenus, navLinks, versionsLinks;
22

3+
const STORYBOOK_PATH_META_SELECTOR = 'meta[name="storybook_path"]';
4+
35
function hideTips() {
46
const tipElement = document.getElementById('tip');
57
const tipContainer = document.getElementById('tip-container');
@@ -58,11 +60,11 @@ function buildPageToC() {
5860
hasInnerContainers: true,
5961
});
6062

61-
const storybookPathMeta = document.querySelector(
62-
'meta[name="storybook_path"]'
63-
);
63+
const storybookPathMetaContent = document.querySelector(
64+
STORYBOOK_PATH_META_SELECTOR
65+
).content;
6466
const tocList = document.querySelector('.toc-list');
65-
if (!tocList || !storybookPathMeta) {
67+
if (!tocList || !storybookPathMetaContent) {
6668
return;
6769
}
6870

@@ -71,13 +73,13 @@ function buildPageToC() {
7173

7274
const storybookLink = document.createElement('a');
7375
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}`;
7577
storybookLink.textContent = 'Storybook';
7678
storybookLink.target = '_blank';
7779
storybookLink.rel = 'noopener noreferrer';
7880

7981
const storybookLaunchIcon = document.createElement('img');
80-
storybookLaunchIcon.src = '/img/icons/launch.png';
82+
storybookLaunchIcon.src = './img/icons/launch.png';
8183
storybookLaunchIcon.alt = 'Open Storybook';
8284
storybookLaunchIcon.className = 'toc-link-icon';
8385

@@ -106,6 +108,15 @@ function replaceContent(text) {
106108
content.innerHTML = tmpContent.innerHTML;
107109
}
108110

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+
109120
window.scrollTo(0, 0);
110121

111122
buildPageToC();

0 commit comments

Comments
 (0)