Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinDFuller committed Aug 13, 2023
1 parent 365b10f commit 50e6273
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ deploy:

format:
@go fmt ./...;
@npx prettier -w **/*;
@npx prettier -w **/*.js **/*.css **/*.html **/*.webmanifest;

build:
@rm -rf ./.build;
@mkdir ./.build;
@curl "http://localhost:9000/" > ./.build/index.html;
@curl "http://localhost:9000/site.webmanifest" > ./.build/site.webmanifest;
@curl "http://localhost:9000/make" > ./.build/make.html;
@curl "http://localhost:9000/grass" > ./.build/grass.html;
@curl "http://localhost:9000/grass/worker.js" > ./.build/grass-service-worker.js;
Expand Down
54 changes: 36 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"
"strings"
"sync"
"text/template"

"github.com/justindfuller/justindfuller.com/aphorism"
Expand Down Expand Up @@ -63,40 +64,55 @@ func main() {

suffixes := []string{".js", ".css", ".html"}

var wg sync.WaitGroup

for i := 0; i < len(files); i++ {
file := files[i]

if file.Dir {
log.Printf("Sub-directory: %s", file.Path)
dir, err := os.ReadDir("." + file.Path)
if err != nil {
log.Fatalf("Error reading dir: %s", file.Path)
}
wg.Add(1)

for _, entry := range dir {
files = append(files, File{
Path: file.Path + "/" + entry.Name(),
Dir: entry.IsDir(),
})
}
go func() {
log.Printf("Sub-directory: %s", file.Path)
dir, err := os.ReadDir("." + file.Path)
if err != nil {
log.Fatalf("Error reading dir: %s", file.Path)
}

for _, entry := range dir {
files = append(files, File{
Path: file.Path + "/" + entry.Name(),
Dir: entry.IsDir(),
})
}
wg.Done()
}()

continue
}

wg.Wait()

var found bool

for _, suffix := range suffixes {
if strings.HasSuffix(file.Path, suffix) {
found = true

b, err := os.ReadFile("." + file.Path)
if err != nil {
log.Fatalf("File read error=%s file=%s", err, file.Path)
}
wg.Add(1)

if _, err := templates.New(file.Path).Parse(string(b)); err != nil {
log.Fatalf("Template parse error=%s path=%s", err, file.Path)
}
go func() {
b, err := os.ReadFile("." + file.Path)
if err != nil {
log.Fatalf("File read error=%s file=%s", err, file.Path)
}

if _, err := templates.New(file.Path).Parse(string(b)); err != nil {
log.Fatalf("Template parse error=%s path=%s", err, file.Path)
}

wg.Done()
}()

break
}
Expand All @@ -107,6 +123,8 @@ func main() {
}
}

wg.Wait()

log.Printf("Templates: %s", templates.DefinedTemplates())

http.HandleFunc("/aphorism", func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 50e6273

Please sign in to comment.