From 5033e31b22f3e336e2fedf9c336036b1e04d1593 Mon Sep 17 00:00:00 2001 From: early Date: Wed, 18 Dec 2024 17:52:09 -0700 Subject: [PATCH] Fix app route registration, don't unescape in renderDocument --- app/app.go | 13 ++++++++++++- web/internal/compile/compile.go | 6 ++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/app.go b/app/app.go index eb6ab84..a73d41c 100644 --- a/app/app.go +++ b/app/app.go @@ -224,7 +224,11 @@ func (app *App) Static(rootPath, rootDir string) error { } else { servePath = strings.TrimSuffix(servePath, ".html") } - handler = page.Static(fpath) + p := page.Static(fpath) + if p.Error() != nil { + return p.Error() + } + handler = p default: handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { f, err := os.Open(fpath) @@ -257,12 +261,19 @@ func (app *App) Handle(expr string, handler http.Handler) { if todayPage, ok := handler.(*page.Page); ok { // Special handling for Today pages app.nonStaticFiles = append(app.nonStaticFiles, todayPage.FileDependencies()...) + // Track registered paths here; localization causes paths to overlap pretty frequently + // In the future, it may be better to have a custom ServeMux for this. + registered := make([]string, 0) for _, lang := range todayPage.Languages() { translatedExpr := expr translations, ok := todayPage.Translations()[lang] if ok { translatedExpr = localization.TranslatePath(todayPage.DefaultLanguage(), lang, expr, translations) } + if slices.Contains(registered, translatedExpr) { + continue + } + registered = append(registered, translatedExpr) for _, middleware := range app.preHandler { handler = middleware(handler) diff --git a/web/internal/compile/compile.go b/web/internal/compile/compile.go index 700a03e..8ae35b4 100644 --- a/web/internal/compile/compile.go +++ b/web/internal/compile/compile.go @@ -181,10 +181,12 @@ func renderDocument(document *html.Node) (string, error) { if err != nil { return "", err } - raw := html.UnescapeString(buf.String()) + // I don't remember why I removed this, but I trust my past self to have + // had a good reason + // raw := html.UnescapeString(buf.String()) // Clean boolean attributes - raw = removeEmptyAttrValues(raw) + raw := removeEmptyAttrValues(buf.String()) return raw, nil } -- 2.39.5