This commit is contained in:
Alex Yatskov 2024-03-03 21:39:08 -08:00
parent 889397b9c5
commit cd2e515141
4 changed files with 47 additions and 41 deletions

View File

@ -29,7 +29,9 @@ type Builder interface {
// website until it is terminated. // website until it is terminated.
func DevServe(builder Builder, port int, sourceDir, targetDir, cacheDir string, watchDirs ...string) { func DevServe(builder Builder, port int, sourceDir, targetDir, cacheDir string, watchDirs ...string) {
dirs := append(watchDirs, sourceDir) dirs := append(watchDirs, sourceDir)
build(dirs, func() { builder.Build(sourceDir, targetDir, cacheDir) }) build(dirs, func() {
builder.Build(sourceDir, targetDir, cacheDir)
})
httpAddr := fmt.Sprintf(":%d", port) httpAddr := fmt.Sprintf(":%d", port)
httpHandler := http.FileServer(http.Dir(targetDir)) httpHandler := http.FileServer(http.Dir(targetDir))

View File

@ -2,29 +2,31 @@ package goldsmith
// Plugin contains the minimum set of methods required on plugins. Plugins can // Plugin contains the minimum set of methods required on plugins. Plugins can
// also optionally implement Initializer, Processor, and Finalizer interfaces. // also optionally implement Initializer, Processor, and Finalizer interfaces.
type Plugin interface { type (
Plugin interface {
Name() string Name() string
} }
// Initializer is used to optionally initialize a plugin and to specify a // Initializer is used to optionally initialize a plugin and to specify a
// filter to be used for determining which files will be processed. // filter to be used for determining which files will be processed.
type Initializer interface { Initializer interface {
Initialize(context *Context) error Initialize(context *Context) error
} }
// Processor allows for optional processing of files passing through a plugin. // Processor allows for optional processing of files passing through a plugin.
type Processor interface { Processor interface {
Process(context *Context, file *File) error Process(context *Context, file *File) error
} }
// Finalizer allows for optional finalization of a plugin after all files // Finalizer allows for optional finalization of a plugin after all files
// queued in the chain have passed through it. // queued in the chain have passed through it.
type Finalizer interface { Finalizer interface {
Finalize(context *Context) error Finalize(context *Context) error
} }
// Filter is used to determine which files should continue in the chain. // Filter is used to determine which files should continue in the chain.
type Filter interface { Filter interface {
Name() string Name() string
Accept(file *File) bool Accept(file *File) bool
} }
)

View File

@ -12,10 +12,9 @@ import (
type ( type (
FileProp any FileProp any
FileProps map[string]FileProp FileProps map[string]FileProp
)
// File represents in-memory or on-disk files in a chain. // File represents in-memory or on-disk files in a chain.
type File struct { File struct {
relPath string relPath string
props FileProps props FileProps
modTime time.Time modTime time.Time
@ -26,6 +25,7 @@ type File struct {
index int index int
} }
)
// Rename modifies the file path relative to the source directory. // Rename modifies the file path relative to the source directory.
func (self *File) Rename(path string) error { func (self *File) Rename(path string) error {

View File

@ -1,11 +1,13 @@
package goldsmith package goldsmith
type filterEntry struct { type (
filterEntry struct {
filter Filter filter Filter
index int index int
} }
type filterStack []filterEntry filterStack []filterEntry
)
func (self *filterStack) accept(file *File) bool { func (self *filterStack) accept(file *File) bool {
for _, entry := range *self { for _, entry := range *self {