Skip to content

Commit c23e913

Browse files
julien-deramondmdo
andauthored
Docs: fix Bootstrap bundle loading consistency between dev and static builds (#42237)
* Docs: fix Bootstrap bundle loading consistency between dev and static builds * Finish the fix for loading single copy of Bootstrap JS --------- Co-authored-by: Mark Otto <[email protected]>
1 parent 15099a0 commit c23e913

5 files changed

Lines changed: 32 additions & 19 deletions

File tree

site/src/assets/application.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import snippets from './partials/snippets.js'
1414
import stickyNav from './partials/sticky.js'
1515
import tocDrawer from './partials/toc.js'
1616

17-
sidebarScroll()
18-
snippets()
19-
stickyNav()
20-
tocDrawer()
17+
export default () => {
18+
sidebarScroll()
19+
snippets()
20+
stickyNav()
21+
tocDrawer()
22+
}

site/src/assets/search.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import docsearch from '@docsearch/js'
1313

14-
(() => {
14+
export default () => {
1515
// These values will be replaced by Astro's Vite plugin
1616
const CONFIG = {
1717
apiKey: '__API_KEY__',
@@ -56,4 +56,4 @@ import docsearch from '@docsearch/js'
5656
})
5757
}
5858
})
59-
})()
59+
}

site/src/assets/stackblitz.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ const CONFIG = {
2222
}
2323

2424
// Open in StackBlitz logic
25-
document.querySelectorAll('.btn-edit').forEach(btn => {
26-
btn.addEventListener('click', event => {
27-
const codeSnippet = event.target.closest('.bd-code-snippet')
28-
const exampleEl = codeSnippet.querySelector('.bd-example')
25+
export default () => {
26+
document.querySelectorAll('.btn-edit').forEach(btn => {
27+
btn.addEventListener('click', event => {
28+
const codeSnippet = event.target.closest('.bd-code-snippet')
29+
const exampleEl = codeSnippet.querySelector('.bd-example')
2930

30-
const htmlSnippet = exampleEl.innerHTML
31-
const jsSnippet = codeSnippet.querySelector('.btn-edit').getAttribute('data-sb-js-snippet')
32-
// Get extra classes for this example
33-
const classes = Array.from(exampleEl.classList).join(' ')
31+
const htmlSnippet = exampleEl.innerHTML
32+
const jsSnippet = codeSnippet.querySelector('.btn-edit').getAttribute('data-sb-js-snippet')
33+
// Get extra classes for this example
34+
const classes = Array.from(exampleEl.classList).join(' ')
3435

35-
openBootstrapSnippet(htmlSnippet, jsSnippet, classes)
36+
openBootstrapSnippet(htmlSnippet, jsSnippet, classes)
37+
})
3638
})
37-
})
39+
}
3840

3941
const openBootstrapSnippet = (htmlSnippet, jsSnippet, classes) => {
4042
const indexHtml = `<!doctype html>
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
22
---
33

4-
<script src="../assets/stackblitz.js"></script>
4+
<script>
5+
import stackblitz from '../assets/stackblitz.js'
6+
7+
stackblitz()
8+
</script>

site/src/components/Scripts.astro

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ interface Props {
99
const { layout } = Astro.props
1010
---
1111

12-
<script src="../assets/application.js"></script>
13-
<script src="../assets/search.js"></script>
12+
<script>
13+
import application from '../assets/application.js'
14+
import search from '../assets/search.js'
15+
16+
application()
17+
search()
18+
</script>
1419

1520
{layout === 'docs' && <DocsScripts />}

0 commit comments

Comments
 (0)