Home

jolheiser.com @main - refs - log - search -
https://git.jolheiser.com/jolheiser.com.git
my website
main.go - raw
 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
package main

import (
	"context"
	"io"
	"os"

	"git.jojodev.com/jolheiser/simpleicons"
	"github.com/a-h/templ"
	"gopkg.in/yaml.v3"
)

type Link struct {
	Name     string `yaml:"name"`
	URL      string `yaml:"url"`
	IconName string `yaml:"icon"`
}

func (l Link) Icon() simpleicons.Icon {
	return simpleicons.Icons[l.IconName]
}

var tailwindCSS = `
@tailwind base;
@tailwind components;
@tailwind utilities;
`

//go:generate templ generate
//go:generate go run .
//go:generate tailwind-ctp -i ./dist/styles.css -o ./dist/styles.css --minify
func main() {
	var links struct {
		Links []Link `yaml:"links"`
	}

	fi, err := os.Open("links.yaml")
	if err != nil {
		panic(err)
	}
	defer fi.Close()
	if err := yaml.NewDecoder(fi).Decode(&links); err != nil {
		panic(err)
	}

	if err := os.MkdirAll("dist", os.ModePerm); err != nil {
		panic(err)
	}

	html, err := os.Create("dist/index.html")
	if err != nil {
		panic(err)
	}
	defer html.Close()

	err = index(links.Links).Render(context.Background(), html)
	if err != nil {
		panic(err)
	}

	css, err := os.Create("dist/styles.css")
	if err != nil {
		panic(err)
	}
	defer css.Close()
	if _, err := css.WriteString(tailwindCSS); err != nil {
		panic(err)
	}
}

func SafeHTML(html string) templ.Component {
	return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) {
		_, err = io.WriteString(w, html)
		return
	})
}