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