Skip to content

Commit 1eccc81

Browse files
Docs: unminify package example HTML files (#41637)
1 parent b850fcb commit 1eccc81

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

build/zip-examples.mjs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import fs from 'node:fs/promises'
1111
import path from 'node:path'
1212
import { fileURLToPath } from 'node:url'
1313
import sh from 'shelljs'
14+
import { format } from 'prettier'
1415

1516
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1617

@@ -83,16 +84,34 @@ for (const file of staticJsFiles) {
8384
sh.rm(`${distFolder}/index.html`)
8485

8586
// get all examples' HTML files
86-
for (const file of sh.find(`${distFolder}/**/*.html`)) {
87+
const htmlFiles = sh.find(`${distFolder}/**/*.html`)
88+
89+
const formatPromises = htmlFiles.map(async file => {
8790
const fileContents = sh.cat(file)
8891
.toString()
8992
.replace(new RegExp(`"/docs/${versionShort}/`, 'g'), '"../')
9093
.replace(/"..\/dist\//g, '"../assets/dist/')
9194
.replace(/(<link href="\.\.\/[^"]*"[^>]*) integrity="[^"]*"/g, '$1')
9295
.replace(/<link[^>]*href="\.\.\/assets\/img\/favicons\/[^"]*"[^>]*>/g, '')
9396
.replace(/(<script src="\.\.\/[^"]*"[^>]*) integrity="[^"]*"/g, '$1')
94-
new sh.ShellString(fileContents).to(file)
95-
}
97+
98+
let formattedHTML
99+
try {
100+
formattedHTML = await format(fileContents, {
101+
parser: 'html',
102+
filepath: file
103+
})
104+
} catch (error) {
105+
console.error(`\nError formatting ${file}:`)
106+
console.error(`Message: ${error.message}`)
107+
console.error('\nSkipping formatting for this file...\n')
108+
formattedHTML = fileContents
109+
}
110+
111+
new sh.ShellString(formattedHTML).to(file)
112+
})
113+
114+
await Promise.all(formatPromises)
96115

97116
// create the zip file
98117
sh.exec(`zip -qr9 "${distFolder}.zip" "${distFolder}"`)

site/src/assets/examples/cheatsheet-rtl/index.astro

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,7 @@ import Placeholder from "@shortcodes/Placeholder.astro"
12091209
<nav class="navbar navbar-expand-lg bg-body-tertiary">
12101210
<div class="container-fluid">
12111211
<a class="navbar-brand" href="#">
1212-
<img src=${getVersionedDocsPath('/assets/brand/bootstrap-logo-white.svg')} width="38" height="30" class="d-inline-block align-top" alt="Bootstrap" loading="lazy"
1213-
style="filter: invert(1) grayscale(100%) brightness(200%);">
1212+
<img src="${getVersionedDocsPath('/assets/brand/bootstrap-logo-white.svg')}" width="38" height="30" class="d-inline-block align-top" alt="Bootstrap" loading="lazy" style="filter: invert(1) grayscale(100%) brightness(200%);">
12141213
</a>
12151214
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="تبديل التنقل">
12161215
<span class="navbar-toggler-icon"></span>
@@ -1249,7 +1248,7 @@ import Placeholder from "@shortcodes/Placeholder.astro"
12491248
<nav class="navbar navbar-expand-lg navbar-dark bg-primary mt-5">
12501249
<div class="container-fluid">
12511250
<a class="navbar-brand" href="#">
1252-
<img src=${getVersionedDocsPath('/assets/brand/bootstrap-logo-white.svg')} width="38" height="30" class="d-inline-block align-top" alt="Bootstrap" loading="lazy">
1251+
<img src="${getVersionedDocsPath('/assets/brand/bootstrap-logo-white.svg')}" width="38" height="30" class="d-inline-block align-top" alt="Bootstrap" loading="lazy">
12531252
</a>
12541253
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent2" aria-controls="navbarSupportedContent2" aria-expanded="false" aria-label="تبديل التنقل">
12551254
<span class="navbar-toggler-icon"></span>

site/src/assets/examples/cheatsheet/index.astro

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,7 @@ export const body_class = 'bg-body-tertiary'
11871187
<nav class="navbar navbar-expand-lg bg-body-tertiary">
11881188
<div class="container-fluid">
11891189
<a class="navbar-brand" href="#">
1190-
<img src=${getVersionedDocsPath('/assets/brand/bootstrap-logo-white.svg')} width="38" height="30" class="d-inline-block align-top" alt="Bootstrap" loading="lazy"
1191-
style="filter: invert(1) grayscale(100%) brightness(200%);">
1190+
<img src="${getVersionedDocsPath('/assets/brand/bootstrap-logo-white.svg')}" width="38" height="30" class="d-inline-block align-top" alt="Bootstrap" loading="lazy" style="filter: invert(1) grayscale(100%) brightness(200%);">
11921191
</a>
11931192
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
11941193
<span class="navbar-toggler-icon"></span>
@@ -1227,7 +1226,7 @@ export const body_class = 'bg-body-tertiary'
12271226
<nav class="navbar navbar-expand-lg navbar-dark bg-primary mt-5">
12281227
<div class="container-fluid">
12291228
<a class="navbar-brand" href="#">
1230-
<img src=${getVersionedDocsPath('/assets/brand/bootstrap-logo-white.svg')} width="38" height="30" class="d-inline-block align-top" alt="Bootstrap" loading="lazy">
1229+
<img src="${getVersionedDocsPath('/assets/brand/bootstrap-logo-white.svg')}" width="38" height="30" class="d-inline-block align-top" alt="Bootstrap" loading="lazy">
12311230
</a>
12321231
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent2" aria-controls="navbarSupportedContent2" aria-expanded="false" aria-label="Toggle navigation">
12331232
<span class="navbar-toggler-icon"></span>

0 commit comments

Comments
 (0)