diff --git a/main.go b/main.go
index 12377bc..21822a4 100644
--- a/main.go
+++ b/main.go
@@ -1,20 +1,21 @@
package main
import (
- "fmt"
- "html/template"
- "log"
- "net/http"
- "os"
- "strconv"
- "strings"
- "time"
+ "fmt"
+ "html/template"
+ "log"
+ "net/http"
+ "os"
+ "regexp"
+ "strconv"
+ "strings"
+ "time"
- "arimelody.me/arimelody.me/api/v1/music"
+ "arimelody.me/arimelody.me/api/v1/music"
- "github.com/gomarkdown/markdown"
- "github.com/gomarkdown/markdown/html"
- "github.com/gomarkdown/markdown/parser"
+ "github.com/gomarkdown/markdown"
+ "github.com/gomarkdown/markdown/html"
+ "github.com/gomarkdown/markdown/parser"
)
const PORT int = 8080
@@ -34,6 +35,7 @@ var base_template = template.Must(template.ParseFiles(
"views/base.html",
"views/header.html",
"views/footer.html",
+ "views/prideflag.html",
))
var htmx_template = template.Must(template.New("root").Parse(`
{{block "head" .}}{{end}}{{block "content" .}}{{end}}`))
@@ -59,11 +61,21 @@ func handle_request(writer http.ResponseWriter, req *http.Request) {
uri := req.URL.Path
start_time := time.Now()
- hx_boosted := len(req.Header["Hx-Boosted"]) > 0 && req.Header["Hx-Boosted"][0] == "true"
+ hx_request := len(req.Header["Hx-Request"]) > 0 && req.Header["Hx-Request"][0] == "true"
+
+ // don't bother fulfilling requests to a page that's already loaded on the client!
+ if hx_request && len(req.Header["Referer"]) > 0 && len(req.Header["Hx-Current-Url"]) > 0 {
+ regex := regexp.MustCompile(`https?:\/\/[^\/]+`)
+ current_location := regex.ReplaceAllString(req.Header["Hx-Current-Url"][0], "")
+ if current_location == req.URL.Path {
+ writer.WriteHeader(204);
+ return
+ }
+ }
code := func(writer http.ResponseWriter, req *http.Request) int {
var root *template.Template
- if hx_boosted {
+ if hx_request {
root = template.Must(htmx_template.Clone())
} else {
root = template.Must(base_template.Clone())
diff --git a/public/script/header.js b/public/script/header.js
index 4db08c6..4d939c9 100644
--- a/public/script/header.js
+++ b/public/script/header.js
@@ -1,4 +1,3 @@
-const header_home = document.getElementById("header-home");
const header_links = document.getElementById("header-links");
const hamburger = document.getElementById("header-links-toggle");
@@ -7,14 +6,9 @@ function toggle_header_links() {
}
document.addEventListener("click", event => {
- if (!header_links.contains(event.target) && !hamburger.contains(event.target)) {
+ if (!header_links.contains(event.target) && !hamburger.contains(event.target) && !header_links.href) {
header_links.classList.remove("open");
}
});
hamburger.addEventListener("click", event => { toggle_header_links(); });
-
-header_home.addEventListener("click", event => {
- event.preventDefault();
- location.href = "/";
-});
diff --git a/public/script/lib/htmx-head-support.js b/public/script/lib/htmx-head-support.js
new file mode 100644
index 0000000..67cfc69
--- /dev/null
+++ b/public/script/lib/htmx-head-support.js
@@ -0,0 +1,141 @@
+//==========================================================
+// head-support.js
+//
+// An extension to htmx 1.0 to add head tag merging.
+//==========================================================
+(function(){
+
+ var api = null;
+
+ function log() {
+ //console.log(arguments);
+ }
+
+ function mergeHead(newContent, defaultMergeStrategy) {
+
+ if (newContent && newContent.indexOf(' -1) {
+ const htmlDoc = document.createElement("html");
+ // remove svgs to avoid conflicts
+ var contentWithSvgsRemoved = newContent.replace(/