From 9d44bd99c41748b88e21b9841dca458e1c64f6c4 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Thu, 23 Apr 2026 11:13:48 -0700 Subject: [PATCH] Clean up some Astro and Docs stuff --- eslint.config.js | 1 - site/.prettierrc.json | 1 + site/astro.config.ts | 14 +- site/src/assets/application.js | 4 +- site/src/assets/partials/sidebar.js | 4 +- site/src/assets/partials/snippets.js | 9 +- site/src/assets/partials/sticky.js | 4 +- site/src/assets/partials/toc.js | 6 +- site/src/assets/search.js | 4 +- site/src/assets/snippets.js | 13 - site/src/assets/stackblitz.js | 7 +- site/src/components/Ads.astro | 4 +- site/src/components/DocsScripts.astro | 3 + site/src/components/DocsSidebar.astro | 23 +- .../src/components/HelperReferenceTable.astro | 33 +-- site/src/components/NewBadge.astro | 6 +- site/src/components/PageMeta.astro | 192 +++++++++----- site/src/components/ReferenceTable.astro | 195 +++++++------- site/src/components/TableOfContents.astro | 4 +- .../components/UtilityReferenceTable.astro | 161 ++++++------ site/src/components/head/Head.astro | 39 +-- site/src/components/head/Scss.astro | 1 + site/src/components/head/ScssProd.astro | 1 + site/src/components/head/Stylesheet.astro | 5 - site/src/components/header/LinkItem.astro | 6 +- site/src/components/header/Navigation.astro | 33 ++- site/src/components/home/CSSVariables.astro | 5 +- site/src/components/home/GetStarted.astro | 6 +- site/src/components/home/MastHead.astro | 4 +- site/src/components/icons/CssTricksIcon.astro | 4 +- site/src/components/icons/HamburgerIcon.astro | 2 +- site/src/components/icons/MdnIcon.astro | 13 +- site/src/components/icons/Symbols.astro | 101 ++++++-- .../shortcodes/ButtonPlayground.astro | 135 +++++----- .../components/shortcodes/CSSVariables.astro | 4 +- site/src/components/shortcodes/Callout.astro | 4 +- .../components/shortcodes/CloseButton.astro | 12 +- site/src/components/shortcodes/Code.astro | 240 +++++++++--------- site/src/components/shortcodes/CodeCopy.astro | 8 +- site/src/components/shortcodes/Details.astro | 24 +- site/src/components/shortcodes/Example.astro | 24 +- .../shortcodes/MenuPlacementPlayground.astro | 71 +++--- .../NavbarPlacementPlayground.astro | 30 +-- .../shortcodes/ResizableExample.astro | 13 +- site/src/components/shortcodes/Swatch.astro | 86 ++++--- site/src/layouts/BaseLayout.astro | 10 +- site/src/layouts/DocsLayout.astro | 43 ++-- site/src/layouts/ExamplesLayout.astro | 12 +- site/src/layouts/partials/ThemeToggler.astro | 21 +- site/src/libs/clipboard.ts | 2 +- site/src/libs/data.ts | 7 + site/src/libs/utils.ts | 27 +- site/tsconfig.json | 2 +- 53 files changed, 918 insertions(+), 765 deletions(-) delete mode 100644 site/src/assets/snippets.js diff --git a/eslint.config.js b/eslint.config.js index d807078449a1..e0351f153fca 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -288,7 +288,6 @@ const eslintConfig = [ 'site/src/assets/application.js', 'site/src/assets/partials/*.js', 'site/src/assets/search.js', - 'site/src/assets/snippets.js', 'site/src/assets/stackblitz.js', 'site/src/plugins/*.js' ], diff --git a/site/.prettierrc.json b/site/.prettierrc.json index a723ce1e1ee0..b3ef3394272b 100644 --- a/site/.prettierrc.json +++ b/site/.prettierrc.json @@ -1,6 +1,7 @@ { "$schema": "http://json.schemastore.org/prettierrc", "arrowParens": "always", + "plugins": ["prettier-plugin-astro"], "printWidth": 120, "semi": false, "singleQuote": true, diff --git a/site/astro.config.ts b/site/astro.config.ts index 14534850423a..45142be4aaba 100644 --- a/site/astro.config.ts +++ b/site/astro.config.ts @@ -1,3 +1,5 @@ +import { fileURLToPath } from 'node:url' + import { defineConfig } from 'astro/config' import astroBrokenLinksChecker from 'astro-broken-links-checker' import bootstrapLight from 'bootstrap-vscode-theme/themes/bootstrap-light.json' @@ -9,6 +11,11 @@ import { getConfig } from './src/libs/config' import { algoliaPlugin } from './src/plugins/algolia-plugin' import { stackblitzPlugin } from './src/plugins/stackblitz-plugin' +// Resolve `@bootstrap` to the same on-disk Bootstrap bundle the docs ship, so +// every docs script imports from a single module instance (no duplicated +// component registries). Mirrors the `@bootstrap` alias in `tsconfig.json`. +const bootstrapBundlePath = fileURLToPath(new URL('../dist/js/bootstrap.bundle.js', import.meta.url)) + const isDev = process.env.NODE_ENV === 'development' const site = isDev @@ -62,6 +69,11 @@ export default defineConfig({ }, site, vite: { - plugins: [algoliaPlugin(), stackblitzPlugin()] + plugins: [algoliaPlugin(), stackblitzPlugin()], + resolve: { + alias: { + '@bootstrap': bootstrapBundlePath + } + } } }) diff --git a/site/src/assets/application.js b/site/src/assets/application.js index 2936465acc6a..2a758ca314af 100644 --- a/site/src/assets/application.js +++ b/site/src/assets/application.js @@ -1,6 +1,4 @@ -// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT -// IT'S ALL JUST JUNK FOR OUR DOCS! -// ++++++++++++++++++++++++++++++++++++++++++ +// NOTICE: Internal docs helpers — not shipped in Bootstrap; not for reuse. /*! * JavaScript for Bootstrap's docs (https://getbootstrap.com/) diff --git a/site/src/assets/partials/sidebar.js b/site/src/assets/partials/sidebar.js index ca90442da471..ce8292e3df07 100644 --- a/site/src/assets/partials/sidebar.js +++ b/site/src/assets/partials/sidebar.js @@ -1,6 +1,4 @@ -// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT -// IT'S ALL JUST JUNK FOR OUR DOCS! -// ++++++++++++++++++++++++++++++++++++++++++ +// NOTICE: Internal docs helpers — not shipped in Bootstrap; not for reuse. /* * JavaScript for Bootstrap's docs (https://getbootstrap.com/) diff --git a/site/src/assets/partials/snippets.js b/site/src/assets/partials/snippets.js index 68f965da519a..5c2550d502be 100644 --- a/site/src/assets/partials/snippets.js +++ b/site/src/assets/partials/snippets.js @@ -1,8 +1,5 @@ -// 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. -// ++++++++++++++++++++++++++++++++++++++++++ +// NOTICE: Embedded as-is into StackBlitz playgrounds via `?raw` import. +// Adapt to your needs in real projects. /* * JavaScript for Bootstrap's docs (https://getbootstrap.com/) @@ -16,7 +13,7 @@ import { Popover, Toast, Carousel -} from '../../../../dist/js/bootstrap.bundle.js' +} from '@bootstrap' export default () => { // -------- diff --git a/site/src/assets/partials/sticky.js b/site/src/assets/partials/sticky.js index 8e673895e866..4db97bfa270e 100644 --- a/site/src/assets/partials/sticky.js +++ b/site/src/assets/partials/sticky.js @@ -1,6 +1,4 @@ -// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT -// IT'S ALL JUST JUNK FOR OUR DOCS! -// ++++++++++++++++++++++++++++++++++++++++++ +// NOTICE: Internal docs helpers — not shipped in Bootstrap; not for reuse. /* * JavaScript for Bootstrap's docs (https://getbootstrap.com/) diff --git a/site/src/assets/partials/toc.js b/site/src/assets/partials/toc.js index 5198fbe13b04..1ebed1c0cdb0 100644 --- a/site/src/assets/partials/toc.js +++ b/site/src/assets/partials/toc.js @@ -1,6 +1,4 @@ -// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT -// IT'S ALL JUST JUNK FOR OUR DOCS! -// ++++++++++++++++++++++++++++++++++++++++++ +// NOTICE: Internal docs helpers — not shipped in Bootstrap; not for reuse. /* * JavaScript for Bootstrap's docs (https://getbootstrap.com/) @@ -9,7 +7,7 @@ * For details, see https://creativecommons.org/licenses/by/3.0/. */ -import { Drawer } from '../../../../dist/js/bootstrap.bundle.js' +import { Drawer } from '@bootstrap' export default () => { const tocSidebar = document.querySelector('#bdTocSidebar') diff --git a/site/src/assets/search.js b/site/src/assets/search.js index 2d8e868c85f1..4b8781deef0d 100644 --- a/site/src/assets/search.js +++ b/site/src/assets/search.js @@ -1,6 +1,4 @@ -// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT -// IT'S ALL JUST JUNK FOR OUR DOCS! -// ++++++++++++++++++++++++++++++++++++++++++ +// NOTICE: Internal docs helpers — not shipped in Bootstrap; not for reuse. /*! * JavaScript for Bootstrap's docs (https://getbootstrap.com/) diff --git a/site/src/assets/snippets.js b/site/src/assets/snippets.js deleted file mode 100644 index 3ca0bf6f3837..000000000000 --- a/site/src/assets/snippets.js +++ /dev/null @@ -1,13 +0,0 @@ -/* - * JavaScript for Bootstrap's docs (https://getbootstrap.com/) - * Copyright 2011-2026 The Bootstrap Authors - * Licensed under the Creative Commons Attribution 3.0 Unported License. - * For details, see https://creativecommons.org/licenses/by/3.0/. - */ - -// Note that this file is not published; we only include it in scripts.html -// for StackBlitz to work - -import snippets from 'js/partials/snippets.js' - -snippets() diff --git a/site/src/assets/stackblitz.js b/site/src/assets/stackblitz.js index a944ef8a0053..ddb3d32cb80f 100644 --- a/site/src/assets/stackblitz.js +++ b/site/src/assets/stackblitz.js @@ -1,8 +1,5 @@ -// 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. -// ++++++++++++++++++++++++++++++++++++++++++ +// NOTICE: Drives the "Open in StackBlitz" button on docs examples; bundles +// `partials/snippets.js` as raw text into the generated playground. /*! * JavaScript for Bootstrap's docs (https://getbootstrap.com/) diff --git a/site/src/components/Ads.astro b/site/src/components/Ads.astro index e7e87e2cffbb..1c9ebd096e7e 100644 --- a/site/src/components/Ads.astro +++ b/site/src/components/Ads.astro @@ -1,9 +1,9 @@ --- + --- + id="_carbonads_js"> diff --git a/site/src/components/DocsScripts.astro b/site/src/components/DocsScripts.astro index 320d91e5f4de..503f175df824 100644 --- a/site/src/components/DocsScripts.astro +++ b/site/src/components/DocsScripts.astro @@ -1,4 +1,7 @@ --- +// Loaded only on docs pages from `Scripts.astro`. Astro extracts/bundles +// ` - - - -{import.meta.env.PROD && ScssProd && ( - - -)} - -{!import.meta.env.PROD && Scss && ( - -)} +{ + import.meta.env.PROD && ScssProd && ( + <> + + + + ) +} + +{!import.meta.env.PROD && Scss && } diff --git a/site/src/components/head/Scss.astro b/site/src/components/head/Scss.astro index 6f01717cbd23..da90eb677912 100644 --- a/site/src/components/head/Scss.astro +++ b/site/src/components/head/Scss.astro @@ -1,4 +1,5 @@ --- + --- diff --git a/site/src/components/head/ScssProd.astro b/site/src/components/head/ScssProd.astro index 4a639403f378..bf17edaa4732 100644 --- a/site/src/components/head/ScssProd.astro +++ b/site/src/components/head/ScssProd.astro @@ -1,4 +1,5 @@ --- + --- diff --git a/site/src/components/shortcodes/Details.astro b/site/src/components/shortcodes/Details.astro index a30c3b7b5482..8db884631f06 100644 --- a/site/src/components/shortcodes/Details.astro +++ b/site/src/components/shortcodes/Details.astro @@ -8,11 +8,7 @@ interface Props { * The name of an existing details content to display located in `src/content/details`. * This will override any content passed in via the default slot. */ - name?: - | 'danger-example' - | 'info-example' - | 'warning-color-assistive-technologies' - | 'warning-example' + name?: 'danger-example' | 'info-example' | 'warning-color-assistive-technologies' | 'warning-example' /** * The summary text displayed before the details are expanded. * If not provided and `name` is set, will use the `title` from the markdown frontmatter. @@ -26,7 +22,7 @@ let { summary } = Astro.props let Content: MarkdownInstance<{}>['Content'] | undefined if (name) { - const details = await getDetailsByName(name) as any + const details = (await getDetailsByName(name)) as any if (!details) { throw new Error(`Could not find details with name '${name}'.`) @@ -37,7 +33,7 @@ if (name) { summary = details.data.title } - const namedDetails = await render(details) as any + const namedDetails = (await render(details)) as any Content = namedDetails.Content } @@ -49,8 +45,18 @@ if (!summary) {
- - + + {summary} diff --git a/site/src/components/shortcodes/Example.astro b/site/src/components/shortcodes/Example.astro index 081737924e59..b6c94eedec42 100644 --- a/site/src/components/shortcodes/Example.astro +++ b/site/src/components/shortcodes/Example.astro @@ -63,9 +63,7 @@ let markup = Array.isArray(code) ? code.join('\n') : code markup = replacePlaceholdersInHtml(markup) // Use customMarkup for source code display if provided, otherwise use the processed markup -let sourceMarkup = customMarkup - ? (Array.isArray(customMarkup) ? customMarkup.join('\n') : customMarkup) - : markup +let sourceMarkup = customMarkup ? (Array.isArray(customMarkup) ? customMarkup.join('\n') : customMarkup) : markup const simplifiedMarkup = sourceMarkup .replace( @@ -79,12 +77,16 @@ const simplifiedMarkup = sourceMarkup ---
- {showPreview && ( -
- -
- )} - {showMarkup && ( - - )} + { + showPreview && ( +
+ +
+ ) + } + { + showMarkup && ( + + ) + }
diff --git a/site/src/components/shortcodes/MenuPlacementPlayground.astro b/site/src/components/shortcodes/MenuPlacementPlayground.astro index ce4ec5f90892..ab408c7acea9 100644 --- a/site/src/components/shortcodes/MenuPlacementPlayground.astro +++ b/site/src/components/shortcodes/MenuPlacementPlayground.astro @@ -34,22 +34,11 @@ const logicalPlacements = [
@@ -69,30 +58,29 @@ const logicalPlacements = [ > bottom-start @@ -114,7 +102,7 @@ const logicalPlacements = [ /> - +