From 2246bed69b9cac5aae0367ebf3be1a6c41c80c71 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Wed, 26 Feb 2020 00:17:28 -0500 Subject: [PATCH] Add static site generation Run `cdr burn` to create an index.html file in the current directory. --- cmd/cdr/generate.go | 30 ++++++++++++++++++++++++++++++ cmd/cdr/main.go | 1 + 2 files changed, 31 insertions(+) diff --git a/cmd/cdr/generate.go b/cmd/cdr/generate.go index 3919932..f59d668 100644 --- a/cmd/cdr/generate.go +++ b/cmd/cdr/generate.go @@ -17,6 +17,11 @@ var ( Usage: "serve the mixtape site", Action: serveAction, } + cmdGenerate = cli.Command{ + Name: "burn", + Usage: "generate the static mixtape site", + Action: generateAction, + } ) func newMixtape(wd string) (*cdr.Mixtape, error) { @@ -38,6 +43,31 @@ func newMixtape(wd string) (*cdr.Mixtape, error) { return m, nil } +func generateAction(c *cli.Context) error { + f, err := os.Create("index.html") + if err != nil { + return err + } + defer f.Close() + + wd, err := os.Getwd() + if err != nil { + return err + } + + m, err := newMixtape(wd) + if err != nil { + return err + } + + err = cdr.Render(m, f) + if err != nil { + return err + } + + return nil +} + func serveAction(c *cli.Context) error { wd, err := os.Getwd() if err != nil { diff --git a/cmd/cdr/main.go b/cmd/cdr/main.go index 6bd543a..57f38c8 100644 --- a/cmd/cdr/main.go +++ b/cmd/cdr/main.go @@ -16,6 +16,7 @@ func main() { } app.Commands = []*cli.Command{ + &cmdGenerate, &cmdServe, &cmdClean, }