all repos — homestead @ b712080aeb160e9e91952603937476309906c029

Code for my website

make goatcounter URL configurable

Alan Pearce
commit

b712080aeb160e9e91952603937476309906c029

parent

5fa45d81f0772ff202d27d9af76f5bef343c99e6

2 files changed, 6 insertions(+), 10 deletions(-)

jump to
M internal/config/config.gointernal/config/config.go
@@ -38,6 +38,7 @@ Email string
Description string DomainStartDate string `toml:"domain_start_date"` OriginalDomain string `toml:"original_domain"` + GoatCounter URL `toml:"goatcounter"` Domains []string OIDCHost URL `toml:"oidc_host"` Taxonomies []Taxonomy
M templates/page.templtemplates/page.templ
@@ -2,7 +2,6 @@ package templates
import ( "io/fs" - "net/url" "website/internal/config" )
@@ -74,7 +73,7 @@ <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>.
<a href="https://git.alanpearce.eu/website/">Site source code</a> is <a href="https://opensource.org/licenses/MIT">MIT</a> </footer> - @counter(page.Path, page.Title) + @counter(site, page.Path, page.Title) if site.InjectLiveReload { <script defer> new EventSource("/_/reload").onmessage = event => {
@@ -87,11 +86,7 @@ </body>
</html> } -func mkURL(path string, title string) string { - u, err := url.Parse("https://alanpearce-eu.goatcounter.com/count") - if err != nil { - panic(err) - } +func mkURL(u config.URL, path string, title string) string { q := u.Query() q.Add("p", path) q.Add("t", title)
@@ -100,10 +95,10 @@
return u.String() } -templ counter(path string, title string) { - <script data-goatcounter="https://alanpearce-eu.goatcounter.com/count" async src="https://gc.zgo.at/count.v4.js" crossorigin="anonymous" integrity="sha384-nRw6qfbWyJha9LhsOtSb2YJDyZdKvvCFh0fJYlkquSFjUxp9FVNugbfy8q1jdxI+"></script> +templ counter(config *config.Config, path string, title string) { + <script data-goatcounter={ config.GoatCounter.String() } async src="https://gc.zgo.at/count.v4.js" crossorigin="anonymous" integrity="sha384-nRw6qfbWyJha9LhsOtSb2YJDyZdKvvCFh0fJYlkquSFjUxp9FVNugbfy8q1jdxI+"></script> <noscript> - <img src={ string(templ.URL(mkURL(path, title))) }/> + <img src={ string(templ.URL(mkURL(config.GoatCounter, path, title))) }/> </noscript> }