diff --git a/cmd/build.go b/cmd/build.go index 86d5a2c..f938ff8 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -12,7 +12,7 @@ import ( "syscall" "github.com/spf13/cobra" - "twos.dev/winter" + "twos.dev/winter/document" ) const ( @@ -34,7 +34,7 @@ var ( // Builder is a function that builds a source file src into a destination // directory dst. -type Builder func(src, dst string, cfg winter.Config) error +type Builder func(src, dst string, cfg document.Config) error func newBuildCmd() *cobra.Command { buildCmd := &cobra.Command{ @@ -43,13 +43,13 @@ func newBuildCmd() *cobra.Command { Long: `Build the website into dist/.`, RunE: func(cmd *cobra.Command, args []string) error { log.Println("Reading config.") - cfg, err := winter.NewConfig() + cfg, err := document.NewConfig() if err != nil { return err } log.Println("Building substructure.") - s, err := winter.NewSubstructure(cfg) + s, err := document.NewSubstructure(cfg) if err != nil { return err } diff --git a/cmd/clean.go b/cmd/clean.go index faf32e3..96aa8f1 100644 --- a/cmd/clean.go +++ b/cmd/clean.go @@ -6,7 +6,7 @@ import ( "github.com/adrg/xdg" "github.com/spf13/cobra" - "twos.dev/winter" + "twos.dev/winter/document" ) func newCleanCmd() *cobra.Command { @@ -21,7 +21,7 @@ func newCleanCmd() *cobra.Command { `), Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - cache, err := xdg.CacheFile(winter.AppName) + cache, err := xdg.CacheFile(document.AppName) if err != nil { return fmt.Errorf("cannot find cache: %w", err) } diff --git a/cmd/config.go b/cmd/config.go index 8225395..0bd8826 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -7,7 +7,7 @@ import ( "github.com/mitchellh/mapstructure" "github.com/spf13/cobra" "gopkg.in/yaml.v3" - "twos.dev/winter" + "twos.dev/winter/document" ) func newConfigCmd() *cobra.Command { @@ -32,7 +32,7 @@ func newConfigCmd() *cobra.Command { `), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - if err := winter.InteractiveConfig(); err != nil { + if err := document.InteractiveConfig(); err != nil { return err } return nil @@ -55,7 +55,7 @@ func newConfigGetCmd() *cobra.Command { `), Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { - c, err := winter.NewConfig() + c, err := document.NewConfig() if err != nil { return err } @@ -92,7 +92,7 @@ func newConfigClearCmd() *cobra.Command { `), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - p, err := winter.ConfigPath() + p, err := document.ConfigPath() if err != nil { return err } diff --git a/cmd/freeze.go b/cmd/freeze.go index d35e0fc..986b70b 100644 --- a/cmd/freeze.go +++ b/cmd/freeze.go @@ -8,7 +8,7 @@ import ( "gg-scm.io/pkg/git" "github.com/spf13/cobra" - "twos.dev/winter" + "twos.dev/winter/document" ) const ( @@ -50,11 +50,11 @@ func newFreezeCmd() *cobra.Command { and adds it to the list of frozen URLs. `), RunE: func(cmd *cobra.Command, args []string) error { - cfg, err := winter.NewConfig() + cfg, err := document.NewConfig() if err != nil { return err } - s, err := winter.NewSubstructure(cfg) + s, err := document.NewSubstructure(cfg) if err != nil { return err } diff --git a/cmd/livereload.go b/cmd/livereload.go index 6c7de7c..a9216a9 100644 --- a/cmd/livereload.go +++ b/cmd/livereload.go @@ -12,7 +12,7 @@ import ( "github.com/fsnotify/fsnotify" "golang.org/x/net/websocket" - "twos.dev/winter" + "twos.dev/winter/document" ) // Reloader watches the filesystem for changes to relevant files so it can @@ -22,7 +22,7 @@ type Reloader struct { // paths that match those patterns. Deprecated: Use Substructure instead. Builders map[string]Builder Ignore map[string]struct{} - Substructure *winter.Substructure + Substructure *document.Substructure closeSockets chan struct{} // listeners is a mapping of WebSocket connections browsers have open with us diff --git a/config.go b/document/config.go similarity index 99% rename from config.go rename to document/config.go index 9ce570c..349e809 100644 --- a/config.go +++ b/document/config.go @@ -1,4 +1,4 @@ -package winter +package document import ( "errors" diff --git a/document.go b/document/document.go similarity index 99% rename from document.go rename to document/document.go index ba57363..632cc03 100644 --- a/document.go +++ b/document/document.go @@ -1,4 +1,4 @@ -package winter +package document import ( "fmt" diff --git a/feed.go b/document/feed.go similarity index 99% rename from feed.go rename to document/feed.go index 0abab15..49d04d8 100644 --- a/feed.go +++ b/document/feed.go @@ -1,4 +1,4 @@ -package winter +package document import ( "bytes" diff --git a/html.go b/document/html.go similarity index 99% rename from html.go rename to document/html.go index 98e015a..e56c0c7 100644 --- a/html.go +++ b/document/html.go @@ -1,4 +1,4 @@ -package winter +package document import ( "bytes" diff --git a/template_test.go b/document/html_test.go similarity index 52% rename from template_test.go rename to document/html_test.go index 2ba73f1..18ec75a 100644 --- a/template_test.go +++ b/document/html_test.go @@ -1,4 +1,4 @@ -package winter +package document import ( "bytes" @@ -10,44 +10,46 @@ import ( "gotest.tools/v3/assert" ) -func TestTemplate(t *testing.T) { +func surround(html string) string { + return fmt.Sprintf("%s", html) +} + +func TestHTML(t *testing.T) { for _, test := range []testCase{ { - name: "NoOp", - input: "abc123", - expected: "abc123\n", + name: "Heading", + input: "

Heading 1

Heading 2

", + expected: surround("

Heading 2

"), }, { name: "SimpleTemplate", - input: "{{ add 1 2 }}", - expected: "3\n", + input: `{{ add 1 2 }}`, + expected: surround("{{ add 1 2 }}"), }, { name: "Template", - input: `{{ template "hello_world.tmpl" }}`, - expected: "Hello, world!\n\n", + input: `{{ template "_writing.html.tmpl" }}`, + expected: surround("{{ template \"_writing.html.tmpl\" }}"), }, { name: "Image", input: `Alt text`, - expected: "\"Alt\n", + expected: surround("\"Alt"), }, } { t.Run(test.name, func(t *testing.T) { src := fmt.Sprintf("src/test/%s", test.name) - doc := NewTemplateDocument( + doc := NewHTMLDocument( src, NewMetadata(src, filepath.Join("testdata", "templates")), nil, - nil, - nil, ) if err := doc.Load(strings.NewReader(test.input)); err != nil { - t.Errorf("load failed: %s", err) + assert.NilError(t, err) } var actual bytes.Buffer if err := doc.Render(&actual); err != nil { - t.Errorf("render failed: %s", err) + assert.NilError(t, err) } assert.Equal(t, test.expected, actual.String()) }) diff --git a/img.go b/document/img.go similarity index 99% rename from img.go rename to document/img.go index ea583af..47bd8a1 100644 --- a/img.go +++ b/document/img.go @@ -1,4 +1,4 @@ -package winter +package document import ( "errors" diff --git a/layout.go b/document/layout.go similarity index 99% rename from layout.go rename to document/layout.go index 322c204..01f9300 100644 --- a/layout.go +++ b/document/layout.go @@ -1,4 +1,4 @@ -package winter +package document import ( "bytes" diff --git a/markdown.go b/document/markdown.go similarity index 99% rename from markdown.go rename to document/markdown.go index 11cc68d..f2fb964 100644 --- a/markdown.go +++ b/document/markdown.go @@ -1,4 +1,4 @@ -package winter +package document import ( "bytes" diff --git a/markdown_test.go b/document/markdown_test.go similarity index 98% rename from markdown_test.go rename to document/markdown_test.go index 3277ab5..c0803b4 100644 --- a/markdown_test.go +++ b/document/markdown_test.go @@ -1,4 +1,4 @@ -package winter +package document import ( "bytes" diff --git a/metadata.go b/document/metadata.go similarity index 99% rename from metadata.go rename to document/metadata.go index 7cc6b59..afe9ec4 100644 --- a/metadata.go +++ b/document/metadata.go @@ -1,4 +1,4 @@ -package winter +package document import ( "fmt" diff --git a/org.go b/document/org.go similarity index 99% rename from org.go rename to document/org.go index a0e9763..f362cc3 100644 --- a/org.go +++ b/document/org.go @@ -1,4 +1,4 @@ -package winter +package document import ( "io" diff --git a/static.go b/document/static.go similarity index 98% rename from static.go rename to document/static.go index 4b1b618..3e00124 100644 --- a/static.go +++ b/document/static.go @@ -1,4 +1,4 @@ -package winter +package document import ( "fmt" diff --git a/template.go b/document/template.go similarity index 99% rename from template.go rename to document/template.go index 6235d12..7bb8d90 100644 --- a/template.go +++ b/document/template.go @@ -1,4 +1,4 @@ -package winter +package document import ( "bytes" diff --git a/html_test.go b/document/template_test.go similarity index 52% rename from html_test.go rename to document/template_test.go index d9511a4..23e7a65 100644 --- a/html_test.go +++ b/document/template_test.go @@ -1,4 +1,4 @@ -package winter +package document import ( "bytes" @@ -10,46 +10,44 @@ import ( "gotest.tools/v3/assert" ) -func surround(html string) string { - return fmt.Sprintf("%s", html) -} - -func TestHTML(t *testing.T) { +func TestTemplate(t *testing.T) { for _, test := range []testCase{ { - name: "Heading", - input: "

Heading 1

Heading 2

", - expected: surround("

Heading 2

"), + name: "NoOp", + input: "abc123", + expected: "abc123\n", }, { name: "SimpleTemplate", - input: `{{ add 1 2 }}`, - expected: surround("{{ add 1 2 }}"), + input: "{{ add 1 2 }}", + expected: "3\n", }, { name: "Template", - input: `{{ template "_writing.html.tmpl" }}`, - expected: surround("{{ template \"_writing.html.tmpl\" }}"), + input: `{{ template "hello_world.tmpl" }}`, + expected: "Hello, world!\n\n", }, { name: "Image", input: `Alt text`, - expected: surround("\"Alt"), + expected: "\"Alt\n", }, } { t.Run(test.name, func(t *testing.T) { src := fmt.Sprintf("src/test/%s", test.name) - doc := NewHTMLDocument( + doc := NewTemplateDocument( src, NewMetadata(src, filepath.Join("testdata", "templates")), nil, + nil, + nil, ) if err := doc.Load(strings.NewReader(test.input)); err != nil { - assert.NilError(t, err) + t.Errorf("load failed: %s", err) } var actual bytes.Buffer if err := doc.Render(&actual); err != nil { - assert.NilError(t, err) + t.Errorf("render failed: %s", err) } assert.Equal(t, test.expected, actual.String()) }) diff --git a/uris.go b/document/uris.go similarity index 99% rename from uris.go rename to document/uris.go index 92138e2..53180e7 100644 --- a/uris.go +++ b/document/uris.go @@ -1,4 +1,4 @@ -package winter +package document import ( "bytes" diff --git a/utils.go b/document/utils.go similarity index 97% rename from utils.go rename to document/utils.go index a5e28a0..d75cba4 100644 --- a/utils.go +++ b/document/utils.go @@ -1,4 +1,4 @@ -package winter +package document import "strings" diff --git a/winter.go b/document/winter.go similarity index 99% rename from winter.go rename to document/winter.go index 9a8d932..c0a3ed8 100644 --- a/winter.go +++ b/document/winter.go @@ -1,4 +1,4 @@ -// Package winter supplies a static website generator. +// Package document supplies a static website generator. // It has these goals: // // 1. New content must be easy to edit. Old content must be hard to break. @@ -133,7 +133,7 @@ // [Cool URIs don't change.]: https://www.w3.org/Provider/Style/URI // [KaTeX]: https://katex.org // [TadiWeb]: https://www.tadiweb.com -package winter +package document import ( "fmt" diff --git a/main.go b/main.go new file mode 100644 index 0000000..9e46f62 --- /dev/null +++ b/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "twos.dev/winter/cmd" +) + +func main() { + cmd.Execute() +} diff --git a/tools.go b/tools.go index 6a65b3c..577f670 100644 --- a/tools.go +++ b/tools.go @@ -1,5 +1,5 @@ //go:build tools -package winter +package main import _ "github.com/mitranim/gow"