-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.go
More file actions
99 lines (80 loc) · 1.72 KB
/
helpers.go
File metadata and controls
99 lines (80 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"sync"
)
type StringQueue struct {
container []string
}
func (self *StringQueue) push(item string) bool {
if self.contains(item) {
fmt.Println("importing fragment: ", item, " will cause circular dependency")
return false
}
self.container = append(self.container, item)
return true
}
func (self *StringQueue) pop() string {
length := len(self.container)
if length == 0 {
return ""
}
lastIndex := length - 1
item := self.container[lastIndex]
self.container = self.container[:lastIndex]
return item
}
func (self *StringQueue) contains(item string) bool {
for _, internalItem := range self.container {
if internalItem == item {
return true
}
}
return false
}
func getFiles(input string) ([]string, error){
info, err := os.Stat(input)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return nil, err
}
if !info.IsDir() {
path, err := filepath.Abs(input)
return []string{path}, err
}
files, err := os.ReadDir(input)
if err != nil {
return nil, err
}
var paths []string
for _, f := range files {
if !f.IsDir() &&
strings.HasSuffix(f.Name(), ".html") &&
!strings.HasSuffix(f.Name(), ".compiled.html") {
fullPath := filepath.Join(input, f.Name())
paths = append(paths, fullPath)
}
}
return paths, nil
}
func templateFiles(files []string, outDir string) {
var wg sync.WaitGroup
defer func() {
wg.Wait()
fmt.Println("done templating all the files")
fmt.Println("------------------------------")
}()
for _, file := range files {
templater := Templater {
fileName: file,
outdir: outDir,
wg: &wg,
}
wg.Add(1)
fmt.Println("starting templating: ", file)
go templater.templateFile()
}
}