1
0
mirror of https://github.com/thebaer/cdr.git synced 2024-11-15 01:31:01 +00:00

Add static site generation

Run `cdr burn` to create an index.html file in the current directory.
This commit is contained in:
Matt Baer 2020-02-26 00:17:28 -05:00
parent 79db8a0cd1
commit 2246bed69b
2 changed files with 31 additions and 0 deletions

View File

@ -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 {

View File

@ -16,6 +16,7 @@ func main() {
}
app.Commands = []*cli.Command{
&cmdGenerate,
&cmdServe,
&cmdClean,
}