summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--main.go23
-rw-r--r--templates/archive.html4
-rw-r--r--templates/directory.html2
3 files changed, 16 insertions, 13 deletions
diff --git a/main.go b/main.go
index 4dbf016..42db6d2 100644
--- a/main.go
+++ b/main.go
@@ -44,8 +44,8 @@ type Page struct {
 
 type Archive struct {
 	Title   string
-	Prev    template.URL
-	Next    template.URL
+	Prev    string
+	Next    string
 	Entries []Page
 }
 
@@ -54,6 +54,10 @@ type Directory struct {
 	Entries []string
 }
 
+func escape(name string) template.URL {
+	return template.URL(strings.Replace(name, "?", "%3f", -1))
+}
+
 func find(entries []os.DirEntry, name string) int {
 	for i, entry := range entries {
 		if entry.Name() == name {
@@ -65,7 +69,9 @@ func find(entries []os.DirEntry, name string) int {
 
 func main() {
 	http.Handle("/static/", http.FileServer(http.FS(static)))
-	t, err := template.ParseFS(templates, "templates/*.html")
+	t, err := template.New("").Funcs(template.FuncMap{
+		"escape": escape,
+	}).ParseFS(templates, "templates/*.html")
 	if err != nil {
 		log.Fatal(err)
 	}
@@ -138,19 +144,16 @@ func main() {
 			}
 		}
 
-		prev := "";
+		prev := ""
 		if index > 0 {
 			prev = entries[index-1].Name()
 		}
-		next := "";
-		if index < len(entries) - 1 {
+		next := ""
+		if index < len(entries)-1 {
 			next = entries[index+1].Name()
 		}
 		t.ExecuteTemplate(w, "archive.html", Archive{
-			stat.Name(),
-			template.URL(prev),
-			template.URL(next),
-			pages,
+			stat.Name(), prev, next, pages,
 		})
 	})
 
diff --git a/templates/archive.html b/templates/archive.html
index fbd2f7a..ee5d2b3 100644
--- a/templates/archive.html
+++ b/templates/archive.html
@@ -3,10 +3,10 @@
 <title>{{.Title}}</title>
 <body>
   <nav>{{if .Prev}}
-    <a id=prev href="{{.Prev}}">PREV</a>{{else}}
+    <a id=prev href="{{.Prev | escape}}">PREV</a>{{else}}
     <a id=prev></a>{{end}}
     <a id=up href=.>UP</a>{{if .Next}}
-    <a id=next href="{{.Next}}">NEXT</a>{{else}}
+    <a id=next href="{{.Next | escape}}">NEXT</a>{{else}}
     <a id=next></a>{{end}}
   </nav>
   <main>{{range .Entries}}
diff --git a/templates/directory.html b/templates/directory.html
index 6fc35fa..a04637e 100644
--- a/templates/directory.html
+++ b/templates/directory.html
@@ -4,7 +4,7 @@
 <body>
   <main>
     <a href=../><p>../</p></a>{{range .Entries}}
-    <a href="./{{.}}"><p>{{.}}</p></a>{{end}}
+    <a href="./{{. | escape}}"><p>{{.}}</p></a>{{end}}
   </main>
 </body>
 </html>