From 96e7bdf5c98ad7f1735ad6951c43e47b218efcf9 Mon Sep 17 00:00:00 2001 From: mya Date: Sun, 28 Jan 2024 10:09:37 -0600 Subject: [PATCH] port from myago --- internal/index.html.gotmpl | 11 +++++ internal/lib.html.gotmpl | 11 +++++ main.go | 83 +++++++++++++++++++++++++++++++++ site/em/index.html | 11 +++++ site/gorm/crud/index.html | 11 +++++ site/gorm/encryption/index.html | 11 +++++ site/index.html | 15 ++++++ site/lib/index.html | 11 +++++ site/okit/index.html | 11 +++++ site/spdx-fmt/index.html | 11 +++++ site/units/index.html | 11 +++++ 11 files changed, 197 insertions(+) create mode 100644 internal/index.html.gotmpl create mode 100644 internal/lib.html.gotmpl create mode 100644 main.go create mode 100644 site/em/index.html create mode 100644 site/gorm/crud/index.html create mode 100644 site/gorm/encryption/index.html create mode 100644 site/index.html create mode 100644 site/lib/index.html create mode 100644 site/okit/index.html create mode 100644 site/spdx-fmt/index.html create mode 100644 site/units/index.html diff --git a/internal/index.html.gotmpl b/internal/index.html.gotmpl new file mode 100644 index 0000000..df5e7b7 --- /dev/null +++ b/internal/index.html.gotmpl @@ -0,0 +1,11 @@ + + + + Go Libraries + + +{{- range $generate := .Generates }} +
{{ $generate.Package }}
+{{- end }} + + diff --git a/internal/lib.html.gotmpl b/internal/lib.html.gotmpl new file mode 100644 index 0000000..7905f94 --- /dev/null +++ b/internal/lib.html.gotmpl @@ -0,0 +1,11 @@ + + + + + + {{ .Package }} + + +Redirecting you to the project page... + + diff --git a/main.go b/main.go new file mode 100644 index 0000000..91d931a --- /dev/null +++ b/main.go @@ -0,0 +1,83 @@ +package main + +import ( + _ "embed" + "flag" + "log" + "os" + "path/filepath" + "text/template" +) + +//go:embed internal/lib.html.gotmpl +var libContentTemplate string + +//go:embed internal/index.html.gotmpl +var indexContentTemplate string + +type Generate struct { + Path string + Package string + Repository string + VCS string +} + +func renderFile(filename string, template *template.Template, data any) error { + dir := filepath.Dir(filename) + _ = os.MkdirAll(dir, 0755) + + file, err := os.Create(filename) + if err != nil { + return err + } + + defer file.Close() + + return template.Execute(file, data) +} + +func must[T any](val T, err error) T { + if err != nil { + panic(err) + } + + return val +} + +func main() { + libTemplate := must(template.New("lib").Parse(libContentTemplate)) + indexTemplate := must(template.New("index").Parse(indexContentTemplate)) + wd := must(os.Getwd()) + + cli := flag.NewFlagSet("go-repo", flag.ExitOnError) + + baseDir := cli.String("base_dir", filepath.Join(wd, "site"), "configure the directory where this script outputs data") + + // ignore due to ExitOnError + _ = cli.Parse(os.Args[1:]) + + generates := []Generate{ + {"em", "go.pitz.tech/em", "https://github.com/mjpitz/em", "git"}, + {"lib", "go.pitz.tech/lib", "https://github.com/mjpitz/myago", "git"}, + {"okit", "go.pitz.tech/okit", "https://code.pitz.tech/mya/okit", "git"}, + {"units", "go.pitz.tech/units", "https://github.com/mjpitz/units", "git"}, + {filepath.Join("gorm", "encryption"), "go.pitz.tech/gorm/encryption", "https://github.com/mjpitz/gorm-encryption", "git"}, + {filepath.Join("gorm", "crud"), "go.pitz.tech/gorm/crud", "https://code.pitz.tech/mya/gorm-crud", "git"}, + {"spdx-fmt", "go.pitz.tech/spdx-fmt", "https://github.com/mjpitz/spdx-fmt", "git"}, + } + + for _, generate := range generates { + log.Println("rendering", generate.Path) + + err := renderFile(filepath.Join(*baseDir, generate.Path, "index.html"), libTemplate, generate) + if err != nil { + log.Fatalln(err.Error()) + } + } + + log.Println("rendering", "index.html") + err := renderFile(filepath.Join(*baseDir, "index.html"), indexTemplate, map[string]any{"Generates": generates}) + if err != nil { + log.Fatalln(err.Error()) + } +} diff --git a/site/em/index.html b/site/em/index.html new file mode 100644 index 0000000..908dfe0 --- /dev/null +++ b/site/em/index.html @@ -0,0 +1,11 @@ + + + + + + go.pitz.tech/em + + +Redirecting you to the project page... + + diff --git a/site/gorm/crud/index.html b/site/gorm/crud/index.html new file mode 100644 index 0000000..48d5d93 --- /dev/null +++ b/site/gorm/crud/index.html @@ -0,0 +1,11 @@ + + + + + + go.pitz.tech/gorm/crud + + +Redirecting you to the project page... + + diff --git a/site/gorm/encryption/index.html b/site/gorm/encryption/index.html new file mode 100644 index 0000000..27d4948 --- /dev/null +++ b/site/gorm/encryption/index.html @@ -0,0 +1,11 @@ + + + + + + go.pitz.tech/gorm/encryption + + +Redirecting you to the project page... + + diff --git a/site/index.html b/site/index.html new file mode 100644 index 0000000..12ef461 --- /dev/null +++ b/site/index.html @@ -0,0 +1,15 @@ + + + + Go Libraries + + +
go.pitz.tech/em
+
go.pitz.tech/lib
+
go.pitz.tech/okit
+
go.pitz.tech/units
+
go.pitz.tech/gorm/encryption
+
go.pitz.tech/gorm/crud
+
go.pitz.tech/spdx-fmt
+ + diff --git a/site/lib/index.html b/site/lib/index.html new file mode 100644 index 0000000..01c38d6 --- /dev/null +++ b/site/lib/index.html @@ -0,0 +1,11 @@ + + + + + + go.pitz.tech/lib + + +Redirecting you to the project page... + + diff --git a/site/okit/index.html b/site/okit/index.html new file mode 100644 index 0000000..3780c03 --- /dev/null +++ b/site/okit/index.html @@ -0,0 +1,11 @@ + + + + + + go.pitz.tech/okit + + +Redirecting you to the project page... + + diff --git a/site/spdx-fmt/index.html b/site/spdx-fmt/index.html new file mode 100644 index 0000000..fbc6080 --- /dev/null +++ b/site/spdx-fmt/index.html @@ -0,0 +1,11 @@ + + + + + + go.pitz.tech/spdx-fmt + + +Redirecting you to the project page... + + diff --git a/site/units/index.html b/site/units/index.html new file mode 100644 index 0000000..9a3a68a --- /dev/null +++ b/site/units/index.html @@ -0,0 +1,11 @@ + + + + + + go.pitz.tech/units + + +Redirecting you to the project page... + +