Goldsmith-DevServer Goldsmith

golang goldsmith goldsmith-devserver mit license web

Goldsmith-DevServer is an HTTP server and a recursive file watcher rolled into one. This minimalist library can be used with Goldsmith to automatically regenerate your site when source files change, while allowing you to view the changes in your web browser.

Usage

The primary goal of Goldsmith-DevServer is to help you get up and running with Goldsmith as quickly as possible. To use it, simply invoke the exported devserver.DevServe function, passing in an object that satisfies the devserver.Builder interface, desired server port number, followed by the source and destination directories.

The library will serve your site, rebuilding it as needed when contents of the source directory (or any descendants) are modified. It is also possible to pass in additional directories to watch immediately after the destination directory (not shown). The server will keep running until you manually terminate the process.

Below is a code sample Goldsmith-DevServer usage:

package main

import (
	"log"

	"github.com/FooSoft/goldsmith"
	"github.com/FooSoft/goldsmith-devserver"
	"github.com/FooSoft/goldsmith-components/frontmatter"
	"github.com/FooSoft/goldsmith-components/layout"
	"github.com/FooSoft/goldsmith-components/markdown"
)

type builder struct{}

func (b *builder) Build(srcDir, dstDir string) {
	errs := goldsmith.Begin(srcDir).
		Chain(frontmatter.New()).
		Chain(markdown.NewCommon()).
		Chain(layout.New("layoutDir/*.html")).
		End(dstDir)

	for _, err := range errs {
		log.Print(err)
	}
}

func main() {
	devserver.DevServe(new(builder), 8080, "srcDir", "dstDir")
}

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.