master
1#!/usr/bin/env node
2
3import allBadges from '#badges'
4import { fileURLToPath } from 'node:url'
5import * as path from 'node:path'
6import fs from 'node:fs'
7
8const badgesHtml = []
9
10for (const { default: b } of allBadges) {
11 const url = fileURLToPath(b.url)
12 const dirname = path.basename(path.dirname(url))
13 const filename = path.basename(url).replace('.js', '.ts')
14 for (const id of b.badges) {
15 badgesHtml.push(
16 `<a href="https://github.com/my-badges/my-badges/tree/master/badges/${dirname}/${filename}"><img src="https://my-badges.github.io/my-badges/${id}.png" alt="${b.desc}" title="${b.desc}" width="128"></a>`,
17 )
18 }
19}
20
21const html = `
22<!doctype html>
23<html lang="en">
24 <head>
25 <title>My Badges</title>
26 <meta charset="utf-8">
27 <meta name="viewport" content="width=device-width, initial-scale=1">
28 <link rel="preconnect" href="https://fonts.googleapis.com">
29 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
30 <link href="https://fonts.googleapis.com/css2?family=Anton&display=swap" rel="stylesheet">
31 <style>
32 body {
33 background-color: #f6f8fa;
34 font-family: "Anton", sans-serif;
35 font-weight: 400;
36 font-style: normal;
37 font-size: 16px;
38 margin: 0;
39 padding: 40px;
40 }
41 h1 {
42 font-size: 5rem;
43 margin: 2.5rem 0 3rem;
44 text-align: center;
45 color: #0366d6;
46 }
47 main {
48 display: flex;
49 flex-wrap: wrap;
50 justify-content: center;
51 }
52 a {
53 text-decoration: none;
54 }
55 </style>
56 </head>
57 <body>
58 <h1>My Badges</h1>
59 <main>
60 ${badgesHtml.join('\n')}
61 </main>
62 </body>
63</html>
64`
65
66fs.mkdirSync('.pages', { recursive: true })
67fs.writeFileSync('.pages/index.html', html)