|
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | + |
| 4 | +const entryDirectory = './documentation'; |
| 5 | + |
| 6 | +const componentToAppend = ` |
| 7 | +
|
| 8 | + <footer class="carbon"> |
| 9 | + <dds-footer-container key="footer" disable-locale-button="true" size="micro" /> |
| 10 | + </footer> |
| 11 | +
|
| 12 | + <script |
| 13 | + key="8" |
| 14 | + type="module" |
| 15 | + src="https://1.www.s81c.com/common/carbon-for-ibm-dotcom/tag/v1/latest/footer.min.js"> |
| 16 | + </script> |
| 17 | +
|
| 18 | + <!-- Storybook override --> |
| 19 | + <script> |
| 20 | + document.title = "Carbon Components Angular"; |
| 21 | + </script> |
| 22 | +
|
| 23 | + <script |
| 24 | + src="//1.www.s81c.com/common/stats/ibm-common.js" |
| 25 | + type="text/javascript" |
| 26 | + async="async"> |
| 27 | + </script> |
| 28 | +</body>`; |
| 29 | +const styleToAppend = ` |
| 30 | + <style> |
| 31 | + footer.carbon { |
| 32 | + position: absolute; |
| 33 | + bottom: 0; |
| 34 | + width: 100%; |
| 35 | + z-index: 9999; |
| 36 | + } |
| 37 | + #root > div { |
| 38 | + /* |
| 39 | + * Subtracting the height of the footer to prevent |
| 40 | + * overlaying the footer ontop of content |
| 41 | + */ |
| 42 | + height: calc(100vh - 48px); |
| 43 | + } |
| 44 | + </style> |
| 45 | +</head>`; |
| 46 | + |
| 47 | + |
| 48 | +function rewriteHtmlFile(filePath) { |
| 49 | + fs.readFile(filePath, 'utf8', (err, data) => { |
| 50 | + if (err) { |
| 51 | + console.error('Error reading file', filePath, err); |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + let newContent = data.replace('</body>', componentToAppend); |
| 56 | + newContent = newContent.replace('</head>', styleToAppend); |
| 57 | + |
| 58 | + fs.writeFile(filePath, newContent, 'utf8', (err) => { |
| 59 | + if(err) { |
| 60 | + console.error('Error writing file', filePath, err); |
| 61 | + } else { |
| 62 | + console.log('Success writing file', filePath); |
| 63 | + } |
| 64 | + }) |
| 65 | + }) |
| 66 | +} |
| 67 | + |
| 68 | +function walkDirectory(dir) { |
| 69 | + fs.readdir(dir, { withFileTypes: true }, (err, items) => { |
| 70 | + if (err) { |
| 71 | + console.error('Error reading directory', dir, err); |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + items.forEach((item) => { |
| 76 | + const fullPath = path.join(dir, item.name); |
| 77 | + if (item.isDirectory()) { |
| 78 | + walkDirectory(fullPath); |
| 79 | + } else if (item.isFile() && path.extname(item.name) === '.html') { |
| 80 | + rewriteHtmlFile(fullPath); |
| 81 | + } |
| 82 | + }) |
| 83 | + }) |
| 84 | +} |
| 85 | + |
| 86 | +walkDirectory(entryDirectory); |
0 commit comments