summaryrefslogtreecommitdiff
path: root/cmd/generate/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/generate/main.go')
-rw-r--r--cmd/generate/main.go84
1 files changed, 84 insertions, 0 deletions
diff --git a/cmd/generate/main.go b/cmd/generate/main.go
new file mode 100644
index 0000000..ce5ce0d
--- /dev/null
+++ b/cmd/generate/main.go
@@ -0,0 +1,84 @@
+package main
+
+import (
+ "bytes"
+ _ "embed"
+ "fmt"
+ "os"
+ "strings"
+
+ "html/template"
+
+ "github.com/yuin/goldmark"
+)
+
+func MarkdownToHTML(md string) (template.HTML, error) {
+ var html strings.Builder
+ if err := goldmark.Convert([]byte(md), &html); err != nil {
+ return template.HTML(""), err
+ }
+ return template.HTML(html.String()), nil
+}
+
+var githubProjects = map[string]string{
+ "flori/json": "ruby-json",
+}
+
+func main() {
+ if err := mainWithError(); err != nil {
+ fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
+ os.Exit(1)
+ }
+}
+
+//go:embed imworkingon.html.tmpl
+var htmlTmplStr string
+
+func mainWithError() error {
+ contribs, err := ReadContribs("contribs.yml")
+ if err != nil {
+ return err
+ }
+ tags, err := ReadUpstreams("tags.yml")
+ if err != nil {
+ return err
+ }
+ upstreams, err := ReadUpstreams("upstreams.yml")
+ if err != nil {
+ return err
+ }
+ tmpl := template.Must(template.New("imworkingon.html").
+ Funcs(template.FuncMap{
+ "md2html": MarkdownToHTML,
+ "getUpstream": func(c Contribution) Upstream {
+ // First try any of the documented upstreams.
+ for _, cURL := range c.URLs {
+ for _, upstream := range upstreams {
+ for _, uURL := range upstream.URLs {
+ prefix := uURL
+ if !strings.HasSuffix(prefix, "/") {
+ prefix += "/"
+ }
+ if cURL == uURL || strings.HasPrefix(cURL, prefix) {
+ return upstream
+ }
+ }
+ }
+ }
+ return Upstream{URLs: []string{c.URLs[0]}, Name: "???"}
+ },
+ }).
+ Parse(htmlTmplStr))
+ var out bytes.Buffer
+ if err := tmpl.Execute(&out, map[string]any{
+ "Contribs": contribs,
+ "Tags": tags,
+ "upstreams": upstreams,
+ }); err != nil {
+ return err
+ }
+ if err := os.WriteFile("plan.html", out.Bytes(), 0666); err != nil {
+ return err
+ }
+ return nil
+}