all repos — vite @ cf68ef9a7f922eb4b2dc23e4bb0c2a64060414a0

a fast (this time, actually) and minimal static site generator

Copy static dir into build
Anirudh Oppiliappan x@icyphox.sh
Thu, 05 Aug 2021 10:36:22 +0530
commit

cf68ef9a7f922eb4b2dc23e4bb0c2a64060414a0

parent

b13fa0dea805a51cac161eb5ff2a37ea8fb51b9b

3 files changed, 40 insertions(+), 6 deletions(-)

jump to
M atom/feed.goatom/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.gocommands/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 +}