Copy static dir into build
Anirudh Oppiliappan x@icyphox.sh
Thu, 05 Aug 2021 10:36:22 +0530
3 files changed,
40 insertions(+),
6 deletions(-)
M
atom/feed.go
→
atom/feed.go
@@ -47,6 +47,7 @@ Author *AtomAuthor `xml:"author"`
Entries []AtomEntry } +// Creates a new Atom feed. func NewAtomFeed(srcDir string, posts []markdown.Output) ([]byte, error) { entries := []AtomEntry{} config := config.Config
M
commands/build.go
→
commands/build.go
@@ -17,6 +17,7 @@ const (
BUILD = "build" PAGES = "pages" TEMPLATES = "templates" + STATIC = "static" ) type Pages struct {@@ -180,22 +181,32 @@ // Core builder function. Converts markdown to html,
// copies over non .md files, etc. func Build() error { pages := Pages{} - err := pages.initPages() - if err != nil { + if err := pages.initPages(); err != nil { + return err + } + + // Clean the build directory. + if err := util.Clean(BUILD); err != nil { return err } // Deal with files. // ex: pages/{_index,about,etc}.md - err = pages.processFiles() - if err != nil { + if err := pages.processFiles(); err != nil { return err } // Deal with dirs -- i.e. dirs of markdown files. // ex: pages/{blog,travel}/*.md - err = pages.processDirs() - if err != nil { + if err := pages.processDirs(); err != nil { + return err + } + + // Copy the static directory into build + // ex: build/static/ + buildStatic := filepath.Join(BUILD, STATIC) + os.Mkdir(buildStatic, 0755) + if err := util.CopyDir(STATIC, buildStatic); err != nil { return err }
A
util/rmall.go
@@ -0,0 +1,22 @@
+package util + +import ( + "os" + "path/filepath" +) + +// Cleans a given directory, removing all files and subdirs. +func Clean(dir string) error { + files, err := filepath.Glob(filepath.Join(dir, "*")) + if err != nil { + return err + } + + for _, file := range files { + err = os.RemoveAll(file) + if err != nil { + return err + } + } + return nil +}