Skip to content

Commit

Permalink
fix gzip compression
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Feb 11, 2024
1 parent dd169ea commit d4c1590
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (r *statsWriter) Write(p []byte) (int, error) {
defer putZip(g)
g.Reset(b)
g.Write(p)
g.Close()
r.compressed = b.Len()
return r.ResponseWriter.Write(b.Bytes())
}
Expand Down
34 changes: 24 additions & 10 deletions tools/docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ var scriptData []byte
var style template.CSS
var script []template.JS

var domain = os.Getenv("DOMAIN")
var track = os.Getenv("TRACKER")

var page = template.Must(template.New("main").Parse(data))
var minifier *minify.M

Expand All @@ -61,6 +64,13 @@ func init() {
panic(err)
}
script = append(script, template.JS(o))

if v := os.Getenv("TRACKER"); v != "" {
track = v
}
if v := os.Getenv("DOMAIN"); v != "" {
domain = v
}
}

var serve = flag.Bool("s", false, "serves")
Expand Down Expand Up @@ -190,10 +200,12 @@ func Build(w io.Writer, dir string) error {
}
var b bytes.Buffer
m := Model{
CSS: style,
JS: script,
Logo: LOGO,
Icon: Icon,
Domain: domain,
Track: track,
CSS: style,
JS: script,
Logo: LOGO,
Icon: Icon,
}
var positions []int
seen := make(map[string]struct{})
Expand Down Expand Up @@ -318,12 +330,14 @@ type Item struct {
}

type Model struct {
CSS template.CSS
Logo template.HTMLAttr
Icon template.HTMLAttr
JS []template.JS
Menus []Menu
Pages []template.HTML
Domain string
Track string
CSS template.CSS
Logo template.HTMLAttr
Icon template.HTMLAttr
JS []template.JS
Menus []Menu
Pages []template.HTML
}

type Menu struct {
Expand Down
3 changes: 3 additions & 0 deletions tools/docs/page.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<title>vince - API first Cloud Native Web Analytics For Startups</title>
<link rel="icon" {{.Icon}}>
<style>{{.CSS}}</style>
{{if .Domain}}
<script defer data-domain="{{.Domain}}" src="{{.Track}}"></script>
{{end}}
</head>

<body>
Expand Down
3 changes: 3 additions & 0 deletions tools/serve
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go build -o bin/docs ./tools/docs/

DOMAIN=vinceanalytics.com TRACKER="http://localhost:8080/js/vince.local.js" ./bin/docs -s docs/

0 comments on commit d4c1590

Please sign in to comment.