diff --git a/.github/workflows/go-linux.yml b/.github/workflows/go-linux.yml new file mode 100644 index 0000000..1ea3356 --- /dev/null +++ b/.github/workflows/go-linux.yml @@ -0,0 +1,38 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go Linux + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Install dependencies + run: go get . + + - name: Build + run: go build -v + + - name: Test + run: go test -v + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.1.2 + with: + name: tweego-linux + path: ./tweego + # The desired behavior if no files are found using the provided path. diff --git a/.github/workflows/go-mac.yml b/.github/workflows/go-mac.yml new file mode 100644 index 0000000..c29daa4 --- /dev/null +++ b/.github/workflows/go-mac.yml @@ -0,0 +1,38 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go Linux + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + workflow_dispatch: + +jobs: + build: + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Install dependencies + run: go get . + + - name: Build + run: go build -v + + - name: Test + run: go test -v + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.1.2 + with: + name: tweego-macos + path: ./tweego + # The desired behavior if no files are found using the provided path. diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..46fae1f --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,38 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go Windows + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + workflow_dispatch: + +jobs: + build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Install dependencies + run: go get . + + - name: Build + run: go build -v + + - name: Test + run: go test -v + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.1.2 + with: + name: tweego-windows + path: ./tweego.exe + # The desired behavior if no files are found using the provided path. diff --git a/filesystem.go b/filesystem.go index 1535e26..949df5e 100644 --- a/filesystem.go +++ b/filesystem.go @@ -203,6 +203,7 @@ func knownFileType(filename string) bool { "htm", "html", "css", "js", + "yaml", "njk", "json", "otf", "ttf", "woff", "woff2", "gif", "jpeg", "jpg", "png", "svg", "tif", "tiff", "webp", "aac", "flac", "m4a", "mp3", "oga", "ogg", "opus", "wav", "wave", "weba", diff --git a/storyload.go b/storyload.go index 7f8a378..f133931 100644 --- a/storyload.go +++ b/storyload.go @@ -9,14 +9,18 @@ package main import ( // standard packages "bytes" + "compress/zlib" + b64 "encoding/base64" "fmt" "log" "path/filepath" "strconv" "strings" + // internal packages twee2 "github.com/tmedwards/tweego/internal/twee2compat" twlex "github.com/tmedwards/tweego/internal/tweelexer" + // external packages "golang.org/x/net/html" ) @@ -50,6 +54,18 @@ func (s *story) load(filenames []string, c *config) { if err := s.loadTagged("script", filename, c.encoding); err != nil { log.Fatalf("error: load %s: %s", filename, err.Error()) } + case "yaml", "json": + if err := s.loadTagged("data", filename, c.encoding); err != nil { + log.Fatalf("error: load %s: %s", filename, err.Error()) + } + // case "json": + // if err := s.loadJson("data", filename, c.encoding); err != nil { + // log.Fatalf("error: load %s: %s", filename, err.Error()) + // } + case "njk": + if err := s.loadTagged("template", filename, c.encoding); err != nil { + log.Fatalf("error: load %s: %s", filename, err.Error()) + } case "otf", "ttf", "woff", "woff2": if err := s.loadFont(filename); err != nil { log.Fatalf("error: load %s: %s", filename, err.Error()) @@ -379,10 +395,26 @@ func (s *story) loadTagged(tag, filename, encoding string) error { return err } + var str string + + if tag == "data" || tag == "template" { + // Add Compression + var b bytes.Buffer + w := zlib.NewWriter(&b) + w.Write(source) + w.Close() + + // str = b64.StdEncoding.EncodeToString(source) + str = b64.StdEncoding.EncodeToString(b.Bytes()) + // fmt.Println(filename, len(b.Bytes()), len(str)) + } else { + str = string(source) + } + s.add(newPassage( filepath.Base(filename), []string{tag}, - string(source), + str, )) return nil