|
| 1 | +import { desktopIcons, libraries, plugins, templates, frameworks, sponsorware, apps, packages } from './data.ts'; |
| 2 | + |
| 3 | +// Read the homepage.stx template |
| 4 | +const template = await Bun.file('./homepage.stx').text(); |
| 5 | + |
| 6 | +// Find and replace the @foreach loop for desktop icons |
| 7 | +const desktopIconsHTML = desktopIcons.map(icon => ` |
| 8 | + <button |
| 9 | + class="desktop-icon" |
| 10 | + data-icon-id="${icon.id}" |
| 11 | + data-icon-type="${icon.type}" |
| 12 | + data-icon-section="${icon.section || ''}" |
| 13 | + data-icon-url="${icon.url || ''}" |
| 14 | + > |
| 15 | + <div class="desktop-icon-image">${icon.icon}</div> |
| 16 | + <div class="desktop-icon-label">${icon.title}</div> |
| 17 | + </button>`).join('\n'); |
| 18 | + |
| 19 | +// Replace desktop icons @foreach loop |
| 20 | +let html = template.replace( |
| 21 | + /@foreach\(desktopIcons as icon\)[\s\S]*?@endforeach/, |
| 22 | + desktopIconsHTML |
| 23 | +); |
| 24 | + |
| 25 | +// Generate and replace libraries @foreach loop |
| 26 | +const librariesHTML = libraries.map(library => ` |
| 27 | + <a href="${library.url}" target="_blank" class="folder-item"> |
| 28 | + <div class="folder-item-icon">📦</div> |
| 29 | + <div class="folder-item-content"> |
| 30 | + <div class="folder-item-name">${library.name}</div> |
| 31 | + <div class="folder-item-desc">${library.desc}</div> |
| 32 | + </div> |
| 33 | + </a>`).join('\n'); |
| 34 | + |
| 35 | +html = html.replace( |
| 36 | + /@foreach\(libraries as library\)[\s\S]*?@endforeach/, |
| 37 | + librariesHTML |
| 38 | +); |
| 39 | + |
| 40 | +// Generate and replace plugins @foreach loop |
| 41 | +const pluginsHTML = plugins.map(plugin => ` |
| 42 | + <a href="${plugin.url}" target="_blank" class="folder-item"> |
| 43 | + <div class="folder-item-icon">🔌</div> |
| 44 | + <div class="folder-item-content"> |
| 45 | + <div class="folder-item-name">${plugin.name}</div> |
| 46 | + <div class="folder-item-desc">${plugin.desc}</div> |
| 47 | + </div> |
| 48 | + </a>`).join('\n'); |
| 49 | + |
| 50 | +html = html.replace( |
| 51 | + /@foreach\(plugins as plugin\)[\s\S]*?@endforeach/, |
| 52 | + pluginsHTML |
| 53 | +); |
| 54 | + |
| 55 | +// Generate and replace templates @foreach loop |
| 56 | +const templatesHTML = templates.map(template => ` |
| 57 | + <a href="${template.url}" target="_blank" class="folder-item"> |
| 58 | + <div class="folder-item-icon">📋</div> |
| 59 | + <div class="folder-item-content"> |
| 60 | + <div class="folder-item-name">${template.name}</div> |
| 61 | + <div class="folder-item-desc">${template.desc}</div> |
| 62 | + </div> |
| 63 | + </a>`).join('\n'); |
| 64 | + |
| 65 | +html = html.replace( |
| 66 | + /@foreach\(templates as template\)[\s\S]*?@endforeach/, |
| 67 | + templatesHTML |
| 68 | +); |
| 69 | + |
| 70 | +// Generate and replace frameworks @foreach loop |
| 71 | +const frameworksHTML = frameworks.map(framework => ` |
| 72 | + <a href="${framework.url}" target="_blank" class="folder-item"> |
| 73 | + <div class="folder-item-icon">🏗️</div> |
| 74 | + <div class="folder-item-content"> |
| 75 | + <div class="folder-item-name">${framework.name}</div> |
| 76 | + <div class="folder-item-desc">${framework.desc}</div> |
| 77 | + </div> |
| 78 | + </a>`).join('\n'); |
| 79 | + |
| 80 | +html = html.replace( |
| 81 | + /@foreach\(frameworks as framework\)[\s\S]*?@endforeach/, |
| 82 | + frameworksHTML |
| 83 | +); |
| 84 | + |
| 85 | +// Generate and replace sponsorware @foreach loop |
| 86 | +const sponsorwareHTML = sponsorware.map(item => ` |
| 87 | + <a href="${item.url}" target="_blank" class="folder-item"> |
| 88 | + <div class="folder-item-icon">💎</div> |
| 89 | + <div class="folder-item-content"> |
| 90 | + <div class="folder-item-name">${item.name}</div> |
| 91 | + <div class="folder-item-desc">${item.desc}</div> |
| 92 | + </div> |
| 93 | + </a>`).join('\n'); |
| 94 | + |
| 95 | +html = html.replace( |
| 96 | + /@foreach\(sponsorware as item\)[\s\S]*?@endforeach/, |
| 97 | + sponsorwareHTML |
| 98 | +); |
| 99 | + |
| 100 | +// Generate and replace apps @foreach loop |
| 101 | +const appsHTML = apps.map(app => ` |
| 102 | + <a href="${app.url}" target="_blank" class="folder-item"> |
| 103 | + <div class="folder-item-icon">📱</div> |
| 104 | + <div class="folder-item-content"> |
| 105 | + <div class="folder-item-name">${app.name}</div> |
| 106 | + <div class="folder-item-desc">${app.desc}</div> |
| 107 | + </div> |
| 108 | + </a>`).join('\n'); |
| 109 | + |
| 110 | +html = html.replace( |
| 111 | + /@foreach\(apps as app\)[\s\S]*?@endforeach/, |
| 112 | + appsHTML |
| 113 | +); |
| 114 | + |
| 115 | +// Generate and replace PackageGrid component |
| 116 | +const packagesHTML = packages.map(pkg => ` |
| 117 | + <div class="package-item"> |
| 118 | + <div class="package-emoji">${pkg.emoji}</div> |
| 119 | + <div class="package-title">${pkg.title}</div> |
| 120 | + <div class="package-desc">${pkg.desc}</div> |
| 121 | + </div>`).join('\n'); |
| 122 | + |
| 123 | +const packageGridHTML = `<div class="package-grid">\n${packagesHTML}\n </div>`; |
| 124 | + |
| 125 | +html = html.replace( |
| 126 | + /<PackageGrid items="{{ packages }}" \/>/, |
| 127 | + packageGridHTML |
| 128 | +); |
| 129 | + |
| 130 | +// Remove the module.exports script block since data is now in data.js |
| 131 | +html = html.replace( |
| 132 | + /<script>[\s\S]*?module\.exports = \{[\s\S]*?\};[\s\S]*?<\/script>/, |
| 133 | + '' |
| 134 | +); |
| 135 | + |
| 136 | +// Write the output |
| 137 | +await Bun.write('./homepage.stx', html); |
| 138 | + |
| 139 | +console.log('✓ Built homepage.stx'); |
| 140 | +console.log(` Desktop icons rendered: ${desktopIcons.length}`); |
| 141 | +console.log(` Libraries rendered: ${libraries.length}`); |
| 142 | +console.log(` Plugins rendered: ${plugins.length}`); |
| 143 | +console.log(` Templates rendered: ${templates.length}`); |
| 144 | +console.log(` Frameworks rendered: ${frameworks.length}`); |
| 145 | +console.log(` Sponsorware rendered: ${sponsorware.length}`); |
| 146 | +console.log(` Apps rendered: ${apps.length}`); |
| 147 | +console.log(` File size: ${html.length} bytes`); |
0 commit comments