Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
louismaximepiton committed Jul 11, 2023
1 parent d3e5824 commit d41146f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion site/assets/js/snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
(() => {
'use strict'

// Boosted mod: Try not using `const` at the first layer in this file, otherwise Storybook will fail render some examples.

// --------
// Tooltips
// --------
Expand Down Expand Up @@ -140,7 +142,7 @@
// -------------------------------
// Links
// -------------------------------
// Disable empty links in docs examples only,
// Disable empty links in docs examples only
document.querySelectorAll('.bd-content [href="#"]')
.forEach(link => {
link.addEventListener('click', event => {
Expand Down
11 changes: 6 additions & 5 deletions stories/create-stories-from-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const toPascalCase = str => {
return (str.match(/[\dA-Za-z]+/g) || []).map(w => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join('')
}

// Get all stories that might be displayed
const files = fs.readdirSync(path.resolve(__dirname, `../site/content/docs/${version}/components/`)).map(fileName => [toPascalCase(fileName.replace('.md', '')), 'components'])
.concat(fs.readdirSync(path.resolve(__dirname, `../site/content/docs/${version}/forms/`)).map(fileName => [toPascalCase(fileName.replace('.md', '')), 'forms']))
.concat([['Tables', 'content']]) // Manual adding
Expand All @@ -70,6 +71,7 @@ createDirectoryIfNeeded(outputDirectory);
page.waitForNavigation()
])

// Getting examples content and classes
const e = await page.evaluate(() =>
Array.from(document.querySelectorAll('.bd-example'), e => [e.innerHTML, e.classList]) // eslint-disable-line no-undef
)
Expand All @@ -89,12 +91,11 @@ createDirectoryIfNeeded(outputDirectory);
example[0] = example[0].replace(/<!--[\S\s]*?-->/gm, '')

// Insert some specific JavaScript
// example += '<script src="https://cdn.jsdelivr.net/npm/boosted/dist/js/boosted.bundle.min.js" crossorigin="anonymous"></script>'
example[0] += '\n<script type="text/javascript" defer>\n /* global boosted: false */\n document.querySelectorAll(\'[href]\').forEach(link => {link.addEventListener(\'click\', event => {event.preventDefault()})})\n</script>'
example[0] += `\n<script type="text/javascript">\n document.getElementById("root").className = "${Object.values(example[1]).join(' ')}"\n</script>`
example[0] += '\n<script type="text/javascript">\n /* global boosted: false */\n document.querySelectorAll(\'[href]\').forEach(link => {link.addEventListener(\'click\', event => {event.preventDefault()})})\n</script>' // Remove links behavior
example[0] += `\n<script type="text/javascript">\n document.getElementById("root").className = "${Object.values(example[1]).join(' ')} m-0 p-0 border-0"\n</script>` // Add example classes and remove the previous ones
if (new RegExp(`// storybook-start ${file[0]}\n`, 's').test(snippets)) {
const re = new RegExp(`// storybook-start ${file[0]}\n.*// storybook-end ${file[0]}\n`, 'gs')
example[0] += `\n<script type="text/javascript" defer>\n ${snippets.match(re)[0].replaceAll('`', '\\`').replaceAll('${', '\\${').replaceAll(/\.bd-.* /g, '')}</script>`
const re = new RegExp(`// storybook-start ${file[0]}\n.*// storybook-end ${file[0]}\n`, 'gs') // RegExp to get all used code in `snippets.js`
example[0] += `\n<script type="text/javascript">\n ${snippets.match(re)[0].replaceAll('`', '\\`').replaceAll('${', '\\${')}</script>` // Replace backticks and variables in js snippets
}

createDirectoryIfNeeded(outputFileDirectory)
Expand Down

0 comments on commit d41146f

Please sign in to comment.