From 24f749cb768b7d7830ed9bc7b3b38d35dbbccffd Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 8 Mar 2024 12:43:44 +0200 Subject: docs: bundle assets with Hugo Also: * load any docs' third-party dependencies from node_modules (except for examples) * exclude docsearch from layouts that don't use it * preconnect to algolia only when not examples layout * switch to `RelPermalink` * refactor JS assets into partials --- site/assets/js/application.js | 26 ++--- site/assets/js/code-examples.js | 90 --------------- site/assets/js/partials/code-examples.js | 90 +++++++++++++++ site/assets/js/partials/sidebar.js | 30 +++++ site/assets/js/partials/snippets.js | 168 ++++++++++++++++++++++++++++ site/assets/js/search.js | 15 ++- site/assets/js/snippets.js | 169 ++--------------------------- site/assets/js/stackblitz.js | 67 ++++++++++++ site/assets/js/vendor/clipboard.min.js | 7 -- site/assets/scss/_search.scss | 2 + site/content/docs/5.3/components/alerts.md | 2 +- site/content/docs/5.3/components/modal.md | 2 +- site/content/docs/5.3/components/toasts.md | 2 +- site/content/docs/5.3/docsref.md | 2 +- site/layouts/partials/header.html | 8 +- site/layouts/partials/scripts.html | 83 ++++---------- site/layouts/partials/stylesheet.html | 4 +- 17 files changed, 415 insertions(+), 352 deletions(-) delete mode 100644 site/assets/js/code-examples.js create mode 100644 site/assets/js/partials/code-examples.js create mode 100644 site/assets/js/partials/sidebar.js create mode 100644 site/assets/js/partials/snippets.js create mode 100644 site/assets/js/stackblitz.js delete mode 100644 site/assets/js/vendor/clipboard.min.js (limited to 'site') diff --git a/site/assets/js/application.js b/site/assets/js/application.js index a16defbd4..ef706ed4d 100644 --- a/site/assets/js/application.js +++ b/site/assets/js/application.js @@ -9,22 +9,12 @@ * For details, see https://creativecommons.org/licenses/by/3.0/. */ -(() => { - 'use strict' +/* eslint-disable import/no-unresolved */ +import sidebarScroll from 'js/partials/sidebar.js' +import codeExamples from 'js/partials/code-examples.js' +import snippets from 'js/partials/snippets.js' +/* eslint-enable import/no-unresolved */ - // Scroll the active sidebar link into view - const sidenav = document.querySelector('.bd-sidebar') - const sidenavActiveLink = document.querySelector('.bd-links-nav .active') - - if (sidenav && sidenavActiveLink) { - const sidenavHeight = sidenav.clientHeight - const sidenavActiveLinkTop = sidenavActiveLink.offsetTop - const sidenavActiveLinkHeight = sidenavActiveLink.clientHeight - const viewportTop = sidenavActiveLinkTop - const viewportBottom = viewportTop - sidenavHeight + sidenavActiveLinkHeight - - if (sidenav.scrollTop > viewportTop || sidenav.scrollTop < viewportBottom) { - sidenav.scrollTop = viewportTop - (sidenavHeight / 2) + (sidenavActiveLinkHeight / 2) - } - } -})() +sidebarScroll() +codeExamples() +snippets() diff --git a/site/assets/js/code-examples.js b/site/assets/js/code-examples.js deleted file mode 100644 index 3462da59b..000000000 --- a/site/assets/js/code-examples.js +++ /dev/null @@ -1,90 +0,0 @@ -// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT -// IT'S ALL JUST JUNK FOR OUR DOCS! -// ++++++++++++++++++++++++++++++++++++++++++ - -/*! - * JavaScript for Bootstrap's docs (https://getbootstrap.com/) - * Copyright 2011-2024 The Bootstrap Authors - * Licensed under the Creative Commons Attribution 3.0 Unported License. - * For details, see https://creativecommons.org/licenses/by/3.0/. - */ - -/* global ClipboardJS: false, bootstrap: false */ - -(() => { - 'use strict' - - // Insert copy to clipboard button before .highlight - const btnTitle = 'Copy to clipboard' - const btnEdit = 'Edit on StackBlitz' - - const btnHtml = [ - '
', - '
', - ' ', - '
', - '
' - ].join('') - - // Wrap programmatically code blocks and add copy btn. - document.querySelectorAll('.highlight') - .forEach(element => { - // Ignore examples made by shortcode - if (!element.closest('.bd-example-snippet')) { - element.insertAdjacentHTML('beforebegin', btnHtml) - element.previousElementSibling.append(element) - } - }) - - /** - * - * @param {string} selector - * @param {string} title - */ - function snippetButtonTooltip(selector, title) { - document.querySelectorAll(selector).forEach(btn => { - bootstrap.Tooltip.getOrCreateInstance(btn, { title }) - }) - } - - snippetButtonTooltip('.btn-clipboard', btnTitle) - snippetButtonTooltip('.btn-edit', btnEdit) - - const clipboard = new ClipboardJS('.btn-clipboard', { - target: trigger => trigger.closest('.bd-code-snippet').querySelector('.highlight'), - text: trigger => trigger.closest('.bd-code-snippet').querySelector('.highlight').textContent.trimEnd() - }) - - clipboard.on('success', event => { - const iconFirstChild = event.trigger.querySelector('.bi').firstElementChild - const tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger) - const namespace = 'http://www.w3.org/1999/xlink' - const originalXhref = iconFirstChild.getAttributeNS(namespace, 'href') - const originalTitle = event.trigger.title - - tooltipBtn.setContent({ '.tooltip-inner': 'Copied!' }) - event.trigger.addEventListener('hidden.bs.tooltip', () => { - tooltipBtn.setContent({ '.tooltip-inner': btnTitle }) - }, { once: true }) - event.clearSelection() - iconFirstChild.setAttributeNS(namespace, 'href', originalXhref.replace('clipboard', 'check2')) - - setTimeout(() => { - iconFirstChild.setAttributeNS(namespace, 'href', originalXhref) - event.trigger.title = originalTitle - }, 2000) - }) - - clipboard.on('error', event => { - const modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-' - const fallbackMsg = `Press ${modifierKey}C to copy` - const tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger) - - tooltipBtn.setContent({ '.tooltip-inner': fallbackMsg }) - event.trigger.addEventListener('hidden.bs.tooltip', () => { - tooltipBtn.setContent({ '.tooltip-inner': btnTitle }) - }, { once: true }) - }) -})() diff --git a/site/assets/js/partials/code-examples.js b/site/assets/js/partials/code-examples.js new file mode 100644 index 000000000..d81191a96 --- /dev/null +++ b/site/assets/js/partials/code-examples.js @@ -0,0 +1,90 @@ +// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT +// IT'S ALL JUST JUNK FOR OUR DOCS! +// ++++++++++++++++++++++++++++++++++++++++++ + +/* + * JavaScript for Bootstrap's docs (https://getbootstrap.com/) + * Copyright 2011-2024 The Bootstrap Authors + * Licensed under the Creative Commons Attribution 3.0 Unported License. + * For details, see https://creativecommons.org/licenses/by/3.0/. + */ + +/* global bootstrap: false */ + +import ClipboardJS from 'clipboard' + +export default () => { + // Insert copy to clipboard button before .highlight + const btnTitle = 'Copy to clipboard' + const btnEdit = 'Edit on StackBlitz' + + const btnHtml = [ + '
', + '
', + ' ', + '
', + '
' + ].join('') + + // Wrap programmatically code blocks and add copy btn. + document.querySelectorAll('.highlight') + .forEach(element => { + // Ignore examples made by shortcode + if (!element.closest('.bd-example-snippet')) { + element.insertAdjacentHTML('beforebegin', btnHtml) + element.previousElementSibling.append(element) + } + }) + + /** + * + * @param {string} selector + * @param {string} title + */ + function snippetButtonTooltip(selector, title) { + document.querySelectorAll(selector).forEach(btn => { + bootstrap.Tooltip.getOrCreateInstance(btn, { title }) + }) + } + + snippetButtonTooltip('.btn-clipboard', btnTitle) + snippetButtonTooltip('.btn-edit', btnEdit) + + const clipboard = new ClipboardJS('.btn-clipboard', { + target: trigger => trigger.closest('.bd-code-snippet').querySelector('.highlight'), + text: trigger => trigger.closest('.bd-code-snippet').querySelector('.highlight').textContent.trimEnd() + }) + + clipboard.on('success', event => { + const iconFirstChild = event.trigger.querySelector('.bi').firstElementChild + const tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger) + const namespace = 'http://www.w3.org/1999/xlink' + const originalXhref = iconFirstChild.getAttributeNS(namespace, 'href') + const originalTitle = event.trigger.title + + tooltipBtn.setContent({ '.tooltip-inner': 'Copied!' }) + event.trigger.addEventListener('hidden.bs.tooltip', () => { + tooltipBtn.setContent({ '.tooltip-inner': btnTitle }) + }, { once: true }) + event.clearSelection() + iconFirstChild.setAttributeNS(namespace, 'href', originalXhref.replace('clipboard', 'check2')) + + setTimeout(() => { + iconFirstChild.setAttributeNS(namespace, 'href', originalXhref) + event.trigger.title = originalTitle + }, 2000) + }) + + clipboard.on('error', event => { + const modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-' + const fallbackMsg = `Press ${modifierKey}C to copy` + const tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger) + + tooltipBtn.setContent({ '.tooltip-inner': fallbackMsg }) + event.trigger.addEventListener('hidden.bs.tooltip', () => { + tooltipBtn.setContent({ '.tooltip-inner': btnTitle }) + }, { once: true }) + }) +} diff --git a/site/assets/js/partials/sidebar.js b/site/assets/js/partials/sidebar.js new file mode 100644 index 000000000..c43f41481 --- /dev/null +++ b/site/assets/js/partials/sidebar.js @@ -0,0 +1,30 @@ +// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT +// IT'S ALL JUST JUNK FOR OUR DOCS! +// ++++++++++++++++++++++++++++++++++++++++++ + +/* + * JavaScript for Bootstrap's docs (https://getbootstrap.com/) + * Copyright 2011-2024 The Bootstrap Authors + * Licensed under the Creative Commons Attribution 3.0 Unported License. + * For details, see https://creativecommons.org/licenses/by/3.0/. + */ + +export default () => { + // Scroll the active sidebar link into view + const sidenav = document.querySelector('.bd-sidebar') + const sidenavActiveLink = document.querySelector('.bd-links-nav .active') + + if (!sidenav || !sidenavActiveLink) { + return + } + + const sidenavHeight = sidenav.clientHeight + const sidenavActiveLinkTop = sidenavActiveLink.offsetTop + const sidenavActiveLinkHeight = sidenavActiveLink.clientHeight + const viewportTop = sidenavActiveLinkTop + const viewportBottom = viewportTop - sidenavHeight + sidenavActiveLinkHeight + + if (sidenav.scrollTop > viewportTop || sidenav.scrollTop < viewportBottom) { + sidenav.scrollTop = viewportTop - (sidenavHeight / 2) + (sidenavActiveLinkHeight / 2) + } +} diff --git a/site/assets/js/partials/snippets.js b/site/assets/js/partials/snippets.js new file mode 100644 index 000000000..1771612cf --- /dev/null +++ b/site/assets/js/partials/snippets.js @@ -0,0 +1,168 @@ +// NOTICE!!! Initially embedded in our docs this JavaScript +// file contains elements that can help you create reproducible +// use cases in StackBlitz for instance. +// In a real project please adapt this content to your needs. +// ++++++++++++++++++++++++++++++++++++++++++ + +/* + * JavaScript for Bootstrap's docs (https://getbootstrap.com/) + * Copyright 2011-2024 The Bootstrap Authors + * Licensed under the Creative Commons Attribution 3.0 Unported License. + * For details, see https://creativecommons.org/licenses/by/3.0/. + */ + +/* global bootstrap: false */ + +export default () => { + // -------- + // Tooltips + // -------- + // Instantiate all tooltips in a docs or StackBlitz + document.querySelectorAll('[data-bs-toggle="tooltip"]') + .forEach(tooltip => { + new bootstrap.Tooltip(tooltip) + }) + + // -------- + // Popovers + // -------- + // Instantiate all popovers in docs or StackBlitz + document.querySelectorAll('[data-bs-toggle="popover"]') + .forEach(popover => { + new bootstrap.Popover(popover) + }) + + // ------------------------------- + // Toasts + // ------------------------------- + // Used by 'Placement' example in docs or StackBlitz + const toastPlacement = document.getElementById('toastPlacement') + if (toastPlacement) { + document.getElementById('selectToastPlacement').addEventListener('change', function () { + if (!toastPlacement.dataset.originalClass) { + toastPlacement.dataset.originalClass = toastPlacement.className + } + + toastPlacement.className = `${toastPlacement.dataset.originalClass} ${this.value}` + }) + } + + // Instantiate all toasts in docs pages only + document.querySelectorAll('.bd-example .toast') + .forEach(toastNode => { + const toast = new bootstrap.Toast(toastNode, { + autohide: false + }) + + toast.show() + }) + + // Instantiate all toasts in docs pages only + // js-docs-start live-toast + const toastTrigger = document.getElementById('liveToastBtn') + const toastLiveExample = document.getElementById('liveToast') + + if (toastTrigger) { + const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample) + toastTrigger.addEventListener('click', () => { + toastBootstrap.show() + }) + } + // js-docs-end live-toast + + // ------------------------------- + // Alerts + // ------------------------------- + // Used in 'Show live alert' example in docs or StackBlitz + + // js-docs-start live-alert + const alertPlaceholder = document.getElementById('liveAlertPlaceholder') + const appendAlert = (message, type) => { + const wrapper = document.createElement('div') + wrapper.innerHTML = [ + `' + ].join('') + + alertPlaceholder.append(wrapper) + } + + const alertTrigger = document.getElementById('liveAlertBtn') + if (alertTrigger) { + alertTrigger.addEventListener('click', () => { + appendAlert('Nice, you triggered this alert message!', 'success') + }) + } + // js-docs-end live-alert + + // -------- + // Carousels + // -------- + // Instantiate all non-autoplaying carousels in docs or StackBlitz + document.querySelectorAll('.carousel:not([data-bs-ride="carousel"])') + .forEach(carousel => { + bootstrap.Carousel.getOrCreateInstance(carousel) + }) + + // ------------------------------- + // Checks & Radios + // ------------------------------- + // Indeterminate checkbox example in docs and StackBlitz + document.querySelectorAll('.bd-example-indeterminate [type="checkbox"]') + .forEach(checkbox => { + if (checkbox.id.includes('Indeterminate')) { + checkbox.indeterminate = true + } + }) + + // ------------------------------- + // Links + // ------------------------------- + // Disable empty links in docs examples only + document.querySelectorAll('.bd-content [href="#"]') + .forEach(link => { + link.addEventListener('click', event => { + event.preventDefault() + }) + }) + + // ------------------------------- + // Modal + // ------------------------------- + // Modal 'Varying modal content' example in docs and StackBlitz + // js-docs-start varying-modal-content + const exampleModal = document.getElementById('exampleModal') + if (exampleModal) { + exampleModal.addEventListener('show.bs.modal', event => { + // Button that triggered the modal + const button = event.relatedTarget + // Extract info from data-bs-* attributes + const recipient = button.getAttribute('data-bs-whatever') + // If necessary, you could initiate an Ajax request here + // and then do the updating in a callback. + + // Update the modal's content. + const modalTitle = exampleModal.querySelector('.modal-title') + const modalBodyInput = exampleModal.querySelector('.modal-body input') + + modalTitle.textContent = `New message to ${recipient}` + modalBodyInput.value = recipient + }) + } + // js-docs-end varying-modal-content + + // ------------------------------- + // Offcanvas + // ------------------------------- + // 'Offcanvas components' example in docs only + const myOffcanvas = document.querySelectorAll('.bd-example-offcanvas .offcanvas') + if (myOffcanvas) { + myOffcanvas.forEach(offcanvas => { + offcanvas.addEventListener('show.bs.offcanvas', event => { + event.preventDefault() + }, false) + }) + } +} diff --git a/site/assets/js/search.js b/site/assets/js/search.js index b095d3bbd..95d920c44 100644 --- a/site/assets/js/search.js +++ b/site/assets/js/search.js @@ -2,18 +2,25 @@ // IT'S ALL JUST JUNK FOR OUR DOCS! // ++++++++++++++++++++++++++++++++++++++++++ -(() => { - 'use strict' +/*! + * JavaScript for Bootstrap's docs (https://getbootstrap.com/) + * Copyright 2024 The Bootstrap Authors + * Licensed under the Creative Commons Attribution 3.0 Unported License. + * For details, see https://creativecommons.org/licenses/by/3.0/. + */ + +import docsearch from '@docsearch/js' +(() => { const searchElement = document.getElementById('docsearch') - if (!window.docsearch || !searchElement) { + if (!searchElement) { return } const siteDocsVersion = searchElement.getAttribute('data-bd-docs-version') - window.docsearch({ + docsearch({ apiKey: '3151f502c7b9e9dafd5e6372b691a24e', indexName: 'bootstrap', appId: 'AK7KMZKZHQ', diff --git a/site/assets/js/snippets.js b/site/assets/js/snippets.js index 94d8f6dee..3fce5e437 100644 --- a/site/assets/js/snippets.js +++ b/site/assets/js/snippets.js @@ -1,170 +1,15 @@ -// NOTICE!!! Initially embedded in our docs this JavaScript -// file contains elements that can help you create reproducible -// use cases in StackBlitz for instance. -// In a real project please adapt this content to your needs. -// ++++++++++++++++++++++++++++++++++++++++++ - -/*! +/* * JavaScript for Bootstrap's docs (https://getbootstrap.com/) * Copyright 2011-2024 The Bootstrap Authors * Licensed under the Creative Commons Attribution 3.0 Unported License. * For details, see https://creativecommons.org/licenses/by/3.0/. */ -/* global bootstrap: false */ - -(() => { - 'use strict' - - // -------- - // Tooltips - // -------- - // Instantiate all tooltips in a docs or StackBlitz - document.querySelectorAll('[data-bs-toggle="tooltip"]') - .forEach(tooltip => { - new bootstrap.Tooltip(tooltip) - }) - - // -------- - // Popovers - // -------- - // Instantiate all popovers in docs or StackBlitz - document.querySelectorAll('[data-bs-toggle="popover"]') - .forEach(popover => { - new bootstrap.Popover(popover) - }) - - // ------------------------------- - // Toasts - // ------------------------------- - // Used by 'Placement' example in docs or StackBlitz - const toastPlacement = document.getElementById('toastPlacement') - if (toastPlacement) { - document.getElementById('selectToastPlacement').addEventListener('change', function () { - if (!toastPlacement.dataset.originalClass) { - toastPlacement.dataset.originalClass = toastPlacement.className - } - - toastPlacement.className = `${toastPlacement.dataset.originalClass} ${this.value}` - }) - } - - // Instantiate all toasts in docs pages only - document.querySelectorAll('.bd-example .toast') - .forEach(toastNode => { - const toast = new bootstrap.Toast(toastNode, { - autohide: false - }) - - toast.show() - }) - - // Instantiate all toasts in docs pages only - // js-docs-start live-toast - const toastTrigger = document.getElementById('liveToastBtn') - const toastLiveExample = document.getElementById('liveToast') - - if (toastTrigger) { - const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample) - toastTrigger.addEventListener('click', () => { - toastBootstrap.show() - }) - } - // js-docs-end live-toast - - // ------------------------------- - // Alerts - // ------------------------------- - // Used in 'Show live alert' example in docs or StackBlitz - - // js-docs-start live-alert - const alertPlaceholder = document.getElementById('liveAlertPlaceholder') - const appendAlert = (message, type) => { - const wrapper = document.createElement('div') - wrapper.innerHTML = [ - `' - ].join('') - - alertPlaceholder.append(wrapper) - } - - const alertTrigger = document.getElementById('liveAlertBtn') - if (alertTrigger) { - alertTrigger.addEventListener('click', () => { - appendAlert('Nice, you triggered this alert message!', 'success') - }) - } - // js-docs-end live-alert - - // -------- - // Carousels - // -------- - // Instantiate all non-autoplaying carousels in docs or StackBlitz - document.querySelectorAll('.carousel:not([data-bs-ride="carousel"])') - .forEach(carousel => { - bootstrap.Carousel.getOrCreateInstance(carousel) - }) - - // ------------------------------- - // Checks & Radios - // ------------------------------- - // Indeterminate checkbox example in docs and StackBlitz - document.querySelectorAll('.bd-example-indeterminate [type="checkbox"]') - .forEach(checkbox => { - if (checkbox.id.includes('Indeterminate')) { - checkbox.indeterminate = true - } - }) - - // ------------------------------- - // Links - // ------------------------------- - // Disable empty links in docs examples only - document.querySelectorAll('.bd-content [href="#"]') - .forEach(link => { - link.addEventListener('click', event => { - event.preventDefault() - }) - }) - - // ------------------------------- - // Modal - // ------------------------------- - // Modal 'Varying modal content' example in docs and StackBlitz - // js-docs-start varying-modal-content - const exampleModal = document.getElementById('exampleModal') - if (exampleModal) { - exampleModal.addEventListener('show.bs.modal', event => { - // Button that triggered the modal - const button = event.relatedTarget - // Extract info from data-bs-* attributes - const recipient = button.getAttribute('data-bs-whatever') - // If necessary, you could initiate an Ajax request here - // and then do the updating in a callback. - - // Update the modal's content. - const modalTitle = exampleModal.querySelector('.modal-title') - const modalBodyInput = exampleModal.querySelector('.modal-body input') +// Note that this file is not published; we only include it in scrpts.html +// for StackBlitz to work - modalTitle.textContent = `New message to ${recipient}` - modalBodyInput.value = recipient - }) - } - // js-docs-end varying-modal-content +/* eslint-disable import/no-unresolved */ +import snippets from 'js/partials/snippets.js' +/* eslint-enable import/no-unresolved */ - // ------------------------------- - // Offcanvas - // ------------------------------- - // 'Offcanvas components' example in docs only - const myOffcanvas = document.querySelectorAll('.bd-example-offcanvas .offcanvas') - if (myOffcanvas) { - myOffcanvas.forEach(offcanvas => { - offcanvas.addEventListener('show.bs.offcanvas', event => { - event.preventDefault() - }, false) - }) - } -})() +snippets() diff --git a/site/assets/js/stackblitz.js b/site/assets/js/stackblitz.js new file mode 100644 index 000000000..c6f44b0f4 --- /dev/null +++ b/site/assets/js/stackblitz.js @@ -0,0 +1,67 @@ +// NOTICE!!! Initially embedded in our docs this JavaScript +// file contains elements that can help you create reproducible +// use cases in StackBlitz for instance. +// In a real project please adapt this content to your needs. +// ++++++++++++++++++++++++++++++++++++++++++ + +/*! + * JavaScript for Bootstrap's docs (https://getbootstrap.com/) + * Copyright 2024 The Bootstrap Authors + * Licensed under the Creative Commons Attribution 3.0 Unported License. + * For details, see https://creativecommons.org/licenses/by/3.0/. + */ + +import sdk from '@stackblitz/sdk' +// https://gohugo.io/hugo-pipes/js/#options +import { + cssCdn, docsVersion, jsBundleCdn, jsSnippetFile +} from '@params' // eslint-disable-line import/no-unresolved + +// Open in StackBlitz logic +document.querySelectorAll('.btn-edit').forEach(btn => { + btn.addEventListener('click', event => { + const codeSnippet = event.target.closest('.bd-code-snippet') + const exampleEl = codeSnippet.querySelector('.bd-example') + + const htmlSnippet = exampleEl.innerHTML + const jsSnippet = codeSnippet.querySelector('.btn-edit').getAttribute('data-sb-js-snippet') + // Get extra classes for this example + const classes = Array.from(exampleEl.classList).join(' ') + + sdk.openBootstrapSnippet(htmlSnippet, jsSnippet, classes) + }) +}) + +sdk.openBootstrapSnippet = (htmlSnippet, jsSnippet, classes) => { + const markup = ` + + + + + + + Bootstrap Example + <${'script'} src="${jsBundleCdn}"> + + + + +${htmlSnippet.replace(/^/gm, ' ')} + + +` + + const jsSnippetContent = jsSnippet ? jsSnippetFile : null + const project = { + files: { + 'index.html': markup, + 'index.js': jsSnippetContent + }, + title: 'Bootstrap Example', + description: `Official example from ${window.location.href}`, + template: jsSnippet ? 'javascript' : 'html', + tags: ['bootstrap'] + } + + sdk.openProject(project, { openFile: 'index.html' }) +} diff --git a/site/assets/js/vendor/clipboard.min.js b/site/assets/js/vendor/clipboard.min.js deleted file mode 100644 index 1103f811e..000000000 --- a/site/assets/js/vendor/clipboard.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * clipboard.js v2.0.11 - * https://clipboardjs.com/ - * - * Licensed MIT © Zeno Rocha - */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return n={686:function(t,e,n){"use strict";n.d(e,{default:function(){return b}});var e=n(279),i=n.n(e),e=n(370),u=n.n(e),e=n(817),r=n.n(e);function c(t){try{return document.execCommand(t)}catch(t){return}}var a=function(t){t=r()(t);return c("cut"),t};function o(t,e){var n,o,t=(n=t,o="rtl"===document.documentElement.getAttribute("dir"),(t=document.createElement("textarea")).style.fontSize="12pt",t.style.border="0",t.style.padding="0",t.style.margin="0",t.style.position="absolute",t.style[o?"right":"left"]="-9999px",o=window.pageYOffset||document.documentElement.scrollTop,t.style.top="".concat(o,"px"),t.setAttribute("readonly",""),t.value=n,t);return e.container.appendChild(t),e=r()(t),c("copy"),t.remove(),e}var f=function(t){var e=1}} +{{< js-docs name="live-alert" file="site/assets/js/partials/snippets.js" >}} ### Link color diff --git a/site/content/docs/5.3/components/modal.md b/site/content/docs/5.3/components/modal.md index 3ca7cc4d2..e00931e81 100644 --- a/site/content/docs/5.3/components/modal.md +++ b/site/content/docs/5.3/components/modal.md @@ -481,7 +481,7 @@ Below is a live demo followed by example HTML and JavaScript. For more informati {{< /example >}} -{{< js-docs name="varying-modal-content" file="site/assets/js/snippets.js" >}} +{{< js-docs name="varying-modal-content" file="site/assets/js/partials/snippets.js" >}} ### Toggle between modals diff --git a/site/content/docs/5.3/components/toasts.md b/site/content/docs/5.3/components/toasts.md index a7d1cb713..4beae7dc8 100644 --- a/site/content/docs/5.3/components/toasts.md +++ b/site/content/docs/5.3/components/toasts.md @@ -87,7 +87,7 @@ Click the button below to show a toast (positioned with our utilities in the low We use the following JavaScript to trigger our live toast demo: -{{< js-docs name="live-toast" file="site/assets/js/snippets.js" >}} +{{< js-docs name="live-toast" file="site/assets/js/partials/snippets.js" >}} ### Translucent diff --git a/site/content/docs/5.3/docsref.md b/site/content/docs/5.3/docsref.md index d0fc42f3d..6b811f47d 100644 --- a/site/content/docs/5.3/docsref.md +++ b/site/content/docs/5.3/docsref.md @@ -46,4 +46,4 @@ sitemap_exclude: true {{< scss-docs name="variable-gradient" file="scss/_variables.scss" >}} -{{< js-docs name="live-toast" file="site/assets/js/snippets.js" >}} +{{< js-docs name="live-toast" file="site/assets/js/partials/snippets.js" >}} diff --git a/site/layouts/partials/header.html b/site/layouts/partials/header.html index ba5889328..3f259ac5e 100644 --- a/site/layouts/partials/header.html +++ b/site/layouts/partials/header.html @@ -7,11 +7,13 @@ -{{ if .IsHome }}{{ .Site.Title | markdownify }} · {{ .Site.Params.subtitle | markdownify }}{{ else }}{{ .Title | markdownify }} · {{ .Site.Title | markdownify }} v{{ .Site.Params.docs_version }}{{ end }} - - +{{ if (ne .Page.Layout "examples") -}} + +{{- end }} + +{{ if .IsHome }}{{ .Site.Title | markdownify }} · {{ .Site.Params.subtitle | markdownify }}{{ else }}{{ .Title | markdownify }} · {{ .Site.Title | markdownify }} v{{ .Site.Params.docs_version }}{{ end }} {{ with .Params.robots -}} diff --git a/site/layouts/partials/scripts.html b/site/layouts/partials/scripts.html index 046f659a9..00c5c9782 100644 --- a/site/layouts/partials/scripts.html +++ b/site/layouts/partials/scripts.html @@ -4,70 +4,31 @@ {{- end }} - - -{{ if eq .Page.Layout "docs" -}} - -{{- end }} - -{{- $vendor := resources.Match "js/vendor/*.js" -}} -{{- $js := resources.Match "js/*.js" -}} -{{- $targetDocsJSPath := path.Join "/docs" .Site.Params.docs_version "assets/js/docs.js" -}} -{{- $docsJs := append $js $vendor | resources.Concat $targetDocsJSPath -}} +{{- $esbuildOptions := dict "target" "es2019" -}} +{{- $targetDocsJSPath := path.Join "/docs" .Site.Params.docs_version -}} {{- if hugo.IsProduction -}} - {{- $docsJs = $docsJs | resources.Minify -}} + {{- $esbuildOptions = merge $esbuildOptions (dict "minify" "true") -}} {{- end }} - - -{{ if eq .Page.Layout "docs" -}} - - -${htmlSnippet.replace(/^/gm, ' ')} - - -` +{{- if (ne .Page.Layout "examples") -}} +{{- $searchJs := resources.Get "js/search.js" | js.Build $esbuildOptions | resources.Copy (path.Join $targetDocsJSPath "/assets/js/search.js") }} + +{{- end -}} - const jsSnippetContent = jsSnippet ? '{{ os.ReadFile "site/assets/js/snippets.js" }}' : null - const project = { - files: { - 'index.html': markup, - 'index.js': jsSnippetContent - }, - title: 'Bootstrap Example', - description: `Official example from ${window.location.href}`, - template: jsSnippet ? 'javascript' : 'html', - tags: ['bootstrap'] - } - - StackBlitzSDK.openProject(project, { openFile: 'index.html' }) - } - -{{- end }} +{{ if eq .Page.Layout "docs" -}} +{{- /* Disable minify options for snippets.js so that the file's readable on StackBlitz */ -}} +{{- $snippetsFile := resources.Get "js/snippets.js" | js.Build (merge $esbuildOptions (dict "minify" "false")) -}} +{{- $esbuildParams := dict + "cssCdn" .Site.Params.cdn.css + "jsBundleCdn" .Site.Params.cdn.js_bundle + "docsVersion" .Site.Params.docs_version + "jsSnippetFile" $snippetsFile.Content +-}} +{{- $esbuildOptions = merge $esbuildOptions (dict "params" $esbuildParams) -}} +{{- $stackblitzJs := resources.Get "js/stackblitz.js" | js.Build $esbuildOptions | resources.Copy (path.Join $targetDocsJSPath "/assets/js/stackblitz.js") }} + +{{- end -}} diff --git a/site/layouts/partials/stylesheet.html b/site/layouts/partials/stylesheet.html index f675d7212..69e75a271 100644 --- a/site/layouts/partials/stylesheet.html +++ b/site/layouts/partials/stylesheet.html @@ -1,5 +1,3 @@ - - {{ if hugo.IsProduction -}} {{ if eq .Page.Params.direction "rtl" -}} @@ -21,5 +19,5 @@ {{- $style := resources.Get "scss/docs.scss" | toCSS $sassOptions | postCSS $postcssOptions }} - + {{- end }} -- cgit v1.2.3