Skip to content

Commit c38cb22

Browse files
committed
feat: add html index
1 parent 656a47d commit c38cb22

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

.github/workflows/generate-index.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
run: |
4242
./plugin-data-extractor
4343
mkdir dist
44+
mv index.html dist/index.html
4445
mv shopware_extensions.json dist/shopware_extensions_v1.json
4546
env:
4647
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

main.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
"html/template"
78
"log"
89
"net/http"
910
"os"
@@ -240,6 +241,64 @@ func collectResults(results chan Result, wg *sync.WaitGroup) {
240241
}
241242

242243
// Write the map to a JSON file
244+
writeShopwareExtensionJson(packageData)
245+
writeShopwareExtensionListingHtml(packageData)
246+
}
247+
248+
func writeShopwareExtensionListingHtml(packageData map[string]*ShopwareExtensionMetadata) {
249+
file, err := os.Create("index.html")
250+
if err != nil {
251+
log.Fatalf("Unable to create index.html file: %v", err)
252+
}
253+
defer file.Close()
254+
255+
tmpl, err := template.New("index_html").Parse(`
256+
<!DOCTYPE html>
257+
<html lang="en">
258+
<head>
259+
<meta charset="UTF-8">
260+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
261+
<title>Shopware Extensions</title>
262+
</head>
263+
<body>
264+
<h1>Shopware Extensions</h1>
265+
<p>Generated at: {{ .GeneratedAt }}</p>
266+
<table>
267+
<thead>
268+
<tr>
269+
<th>Package</th>
270+
<th>Repository URL</th>
271+
<th>Latest Commit Time</th>
272+
</tr>
273+
</thead>
274+
<tbody>
275+
{{ range $packageName, $metadata := .Extensions }}
276+
<tr>
277+
<td>{{ $packageName }}</td>
278+
<td><a href="{{ $metadata.RepositoryUrl }}">{{ $metadata.RepositoryUrl }}</a></td>
279+
<td>{{ $metadata.LatestCommitTime }}</td>
280+
</tr>
281+
{{ end }}
282+
</tbody>
283+
</table>
284+
</body>
285+
`)
286+
287+
if tmpl == nil {
288+
log.Fatalf("Failed to parse HTML template: %v", err)
289+
}
290+
291+
if err = tmpl.Execute(file, ShopwareExtensionIndex{
292+
Extensions: packageData,
293+
GeneratedAt: int(time.Now().Unix()),
294+
}); err != nil {
295+
log.Fatalf("Failed to write HTML to file: %v", err)
296+
}
297+
298+
log.Println("Shopware extensions data written to index.html")
299+
}
300+
301+
func writeShopwareExtensionJson(packageData map[string]*ShopwareExtensionMetadata) {
243302
file, err := os.Create("shopware_extensions.json")
244303
if err != nil {
245304
log.Fatalf("Unable to create JSON file: %v", err)

0 commit comments

Comments
 (0)