--- /dev/null
+// 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
+}
-// $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 (
"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"
)
}
-// 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.
--- /dev/null
+// 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)
+}