]> Nishi Git Mirror - aya.git/commitdiff
Separate the build<FORMAT> functions into their own source files
authorIzuru Yakumo <yakumo.izuru@chaotic.ninja>
Mon, 11 Dec 2023 17:23:49 +0000 (14:23 -0300)
committerIzuru Yakumo <yakumo.izuru@chaotic.ninja>
Mon, 11 Dec 2023 17:23:49 +0000 (14:23 -0300)
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>
cmd/aya/amber.go [new file with mode: 0644]
cmd/aya/gcss.go [new file with mode: 0644]
cmd/aya/html.go [new file with mode: 0644]
cmd/aya/main.go
cmd/aya/markdown.go [new file with mode: 0644]
cmd/aya/raw.go [new file with mode: 0644]
version.go

diff --git a/cmd/aya/amber.go b/cmd/aya/amber.go
new file mode 100644 (file)
index 0000000..05f9fe1
--- /dev/null
@@ -0,0 +1,47 @@
+// Render .amber files into .html
+package main
+
+import (
+       "bytes"
+       "fmt"
+       "io"
+       "os"
+       "path/filepath"
+       "github.com/eknkc/amber"
+)
+
+func buildAmber(path string, w io.Writer, vars Vars) error {
+        v, body, err := getVars(path, vars)
+        if err != nil {
+                return err
+        }
+        a := amber.New()
+        if err := a.Parse(body); err != nil {
+                fmt.Println(body)
+                return err
+        }
+
+        t, err := a.Compile()
+        if err != nil {
+                return err
+        }
+
+        htmlBuf := &bytes.Buffer{}
+        if err := t.Execute(htmlBuf, v); err != nil {
+                return err
+        }
+
+        if body, err = render(string(htmlBuf.Bytes()), v); err != nil {
+                return err
+        }
+        if w == nil {
+                f, err := os.Create(filepath.Join(PUBDIR, renameExt(path, ".amber", ".html")))
+                if err != nil {
+                        return err
+                }
+                defer f.Close()
+                w = f
+        }
+        _, err = io.WriteString(w, body)
+        return err
+}
diff --git a/cmd/aya/gcss.go b/cmd/aya/gcss.go
new file mode 100644 (file)
index 0000000..2cb449b
--- /dev/null
@@ -0,0 +1,30 @@
+// Render .gcss files into .css
+package main
+
+import (
+       "io"
+       "os"
+       "path/filepath"
+       "strings"
+       "github.com/yosssi/gcss"
+)
+
+func buildGCSS(path string, w io.Writer) error {
+        f, err := os.Open(path)
+        if err != nil {
+                return err
+        }
+        defer f.Close()
+
+        if w == nil {
+                s := strings.TrimSuffix(path, ".gcss") + ".css"
+                css, err := os.Create(filepath.Join(PUBDIR, s))
+                if err != nil {
+                        return err
+                }
+                defer css.Close()
+                w = css
+        }
+        _, err = gcss.Compile(w, f)
+        return err
+}
diff --git a/cmd/aya/html.go b/cmd/aya/html.go
new file mode 100644 (file)
index 0000000..7d6b5d3
--- /dev/null
@@ -0,0 +1,32 @@
+// Renders hypertext files expanding all variable macros inside it
+package main
+
+import (
+       "io"
+       "os"
+       "path/filepath"
+       "text/template"
+)
+
+func buildHTML(path string, w io.Writer, vars Vars) error {
+        v, body, err := getVars(path, vars)
+        if err != nil {
+                return err
+        }
+        if body, err = render(body, v); err != nil {
+                return err
+        }
+        tmpl, err := template.New("").Delims("<%", "%>").Parse(body)
+        if err != nil {
+                return err
+        }
+        if w == nil {
+                f, err := os.Create(filepath.Join(PUBDIR, path))
+                if err != nil {
+                        return err
+                }
+                defer f.Close()
+                w = f
+        }
+        return tmpl.Execute(w, vars)
+}
index ac22395dc8a9b021a185d9c685abc51de08ef2cd..71009cf4b1eb053a62d7eea8cc505c7e8af69948 100644 (file)
@@ -1,4 +1,4 @@
-// $TheSupernovaDuo: marisa.chaotic.ninja/aya/cmd/aya, v0.6.9 2023-12-09 23:30:07+0000, yakumo_izuru Exp $
+// $TheSupernovaDuo: marisa.chaotic.ninja/aya/cmd/aya, v0.7.0 2023-12-11 17:22:51+0000, yakumo_izuru Exp $
 package main
 
 import (
@@ -9,12 +9,8 @@ import (
        "os/exec"
        "path/filepath"
        "strings"
-       "text/template"
        "time"
 
-       "github.com/eknkc/amber"
-       "github.com/russross/blackfriday/v2"
-       "github.com/yosssi/gcss"
        "gopkg.in/yaml.v3"
        "marisa.chaotic.ninja/aya"
 )
@@ -174,133 +170,6 @@ func render(s string, vars Vars) (string, error) {
 
 }
 
-// Renders markdown with the given layout into html expanding all the macros
-func buildMarkdown(path string, w io.Writer, vars Vars) error {
-       v, body, err := getVars(path, vars)
-       extensions := blackfriday.CommonExtensions|blackfriday.AutoHeadingIDs|blackfriday.Strikethrough|blackfriday.Footnotes
-       if err != nil {
-               return err
-       }
-       content, err := render(body, v)
-       if err != nil {
-               return err
-       }
-       v["content"] = string(blackfriday.Run([]byte(content),
-               blackfriday.WithExtensions(extensions),
-       ))
-       if w == nil {
-               out, err := os.Create(filepath.Join(PUBDIR, renameExt(path, "", ".html")))
-               if err != nil {
-                       return err
-               }
-               defer out.Close()
-               w = out
-       }
-       return buildHTML(filepath.Join(AYADIR, v["layout"]), w, v)
-}
-
-// Renders hypertext file expanding all variable macros inside it
-func buildHTML(path string, w io.Writer, vars Vars) error {
-       v, body, err := getVars(path, vars)
-       if err != nil {
-               return err
-       }
-       if body, err = render(body, v); err != nil {
-               return err
-       }
-       tmpl, err := template.New("").Delims("<%", "%>").Parse(body)
-       if err != nil {
-               return err
-       }
-       if w == nil {
-               f, err := os.Create(filepath.Join(PUBDIR, path))
-               if err != nil {
-                       return err
-               }
-               defer f.Close()
-               w = f
-       }
-       return tmpl.Execute(w, vars)
-}
-
-// Renders .amber file into .html
-func buildAmber(path string, w io.Writer, vars Vars) error {
-       v, body, err := getVars(path, vars)
-       if err != nil {
-               return err
-       }
-       a := amber.New()
-       if err := a.Parse(body); err != nil {
-               fmt.Println(body)
-               return err
-       }
-
-       t, err := a.Compile()
-       if err != nil {
-               return err
-       }
-
-       htmlBuf := &bytes.Buffer{}
-       if err := t.Execute(htmlBuf, v); err != nil {
-               return err
-       }
-
-       if body, err = render(string(htmlBuf.Bytes()), v); err != nil {
-               return err
-       }
-
-       if w == nil {
-               f, err := os.Create(filepath.Join(PUBDIR, renameExt(path, ".amber", ".html")))
-               if err != nil {
-                       return err
-               }
-               defer f.Close()
-               w = f
-       }
-       _, err = io.WriteString(w, body)
-       return err
-}
-
-// Compiles .gcss into .css
-func buildGCSS(path string, w io.Writer) error {
-       f, err := os.Open(path)
-       if err != nil {
-               return err
-       }
-       defer f.Close()
-
-       if w == nil {
-               s := strings.TrimSuffix(path, ".gcss") + ".css"
-               css, err := os.Create(filepath.Join(PUBDIR, s))
-               if err != nil {
-                       return err
-               }
-               defer css.Close()
-               w = css
-       }
-       _, err = gcss.Compile(w, f)
-       return err
-}
-
-// Copies file as is from path to writer
-func buildRaw(path string, w io.Writer) error {
-       in, err := os.Open(path)
-       if err != nil {
-               return err
-       }
-       defer in.Close()
-       if w == nil {
-               if out, err := os.Create(filepath.Join(PUBDIR, path)); err != nil {
-                       return err
-               } else {
-                       defer out.Close()
-                       w = out
-               }
-       }
-       _, err = io.Copy(w, in)
-       return err
-}
-
 // This function passes the files to build to their corresponding functions
 // As far as I'm aware, Markdown has three possible filename extensions,
 // but .md is the most common one known.
diff --git a/cmd/aya/markdown.go b/cmd/aya/markdown.go
new file mode 100644 (file)
index 0000000..23c7f9a
--- /dev/null
@@ -0,0 +1,33 @@
+// Renders markdown with the given layout into html expanding all the macros
+package main
+
+import (
+       "io"
+       "os"
+       "path/filepath"
+       "github.com/russross/blackfriday/v2"
+)
+
+func buildMarkdown(path string, w io.Writer, vars Vars) error {
+        v, body, err := getVars(path, vars)
+        extensions := blackfriday.CommonExtensions|blackfriday.AutoHeadingIDs|blackfriday.Strikethrough|blackfriday.Footnotes
+        if err != nil {
+                return err
+        }
+        content, err := render(body, v)
+        if err != nil {
+                return err
+        }
+        v["content"] = string(blackfriday.Run([]byte(content),
+                blackfriday.WithExtensions(extensions),
+        ))
+        if w == nil {
+                out, err := os.Create(filepath.Join(PUBDIR, renameExt(path, "", ".html")))
+                if err != nil {
+                        return err
+                }
+                defer out.Close()
+                w = out
+        }
+        return buildHTML(filepath.Join(AYADIR, v["layout"]), w, v)
+}
diff --git a/cmd/aya/raw.go b/cmd/aya/raw.go
new file mode 100644 (file)
index 0000000..83e12f3
--- /dev/null
@@ -0,0 +1,26 @@
+// Copy files as-is from source to destination
+package main
+
+import (
+       "io"
+       "os"
+       "path/filepath"
+)
+
+func buildRaw(path string, w io.Writer) error {
+        in, err := os.Open(path)
+        if err != nil {
+                return err
+        }
+        defer in.Close()
+        if w == nil {
+                if out, err := os.Create(filepath.Join(PUBDIR, path)); err != nil {
+                        return err
+                } else {
+                        defer out.Close()
+                        w = out
+                }
+        }
+        _, err = io.Copy(w, in)
+        return err
+}
index 30d567861659f4d78ef007a0c621b64f6e4048c7..0210513e5a2361cac524895c7ccd62bd6a53881e 100644 (file)
@@ -8,7 +8,7 @@ import (
 
 var (
        // Set to current tag
-       Version = "v0.6.9"
+       Version = "v0.7.0"
        Time = time.Now()
 )