about summary refs log tree commit diff stats
path: root/templates
diff options
context:
space:
mode:
authorAlan Pearce2024-06-28 16:03:38 +0200
committerAlan Pearce2024-06-28 16:03:38 +0200
commit82baf3c72e8aeec606b2c3fcd34b7ad8b4e1bc40 (patch)
tree34fbbdc966f8d2c3863e03147fb149a72ee01367 /templates
parent32a2145ee44cc301551ce2e4d24ed34361ebd4b2 (diff)
downloadwebsite-82baf3c72e8aeec606b2c3fcd34b7ad8b4e1bc40.tar.lz
website-82baf3c72e8aeec606b2c3fcd34b7ad8b4e1bc40.tar.zst
website-82baf3c72e8aeec606b2c3fcd34b7ad8b4e1bc40.zip
make goatcounter URL configurable
Diffstat (limited to 'templates')
-rw-r--r--templates/page.templ15
1 files changed, 5 insertions, 10 deletions
diff --git a/templates/page.templ b/templates/page.templ
index 1dbd345..7a43485 100644
--- a/templates/page.templ
+++ b/templates/page.templ
@@ -2,7 +2,6 @@ package templates
 
 import (
 	"io/fs"
-	"net/url"
 
 	"website/internal/config"
 )
@@ -74,7 +73,7 @@ templ Page(site *config.Config, page PageSettings) {
 				<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 @@ templ Page(site *config.Config, page PageSettings) {
 	</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 @@ func mkURL(path string, title string) string {
 	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>
 }