]> git.earlybird.gay Git - today/commitdiff
Fix app route registration, don't unescape in renderDocument
authorearly <me@earlybird.gay>
Thu, 19 Dec 2024 00:52:09 +0000 (17:52 -0700)
committerearly <me@earlybird.gay>
Thu, 19 Dec 2024 00:52:09 +0000 (17:52 -0700)
app/app.go
web/internal/compile/compile.go

index eb6ab84d4bfa774d36193f33ded5e5170fb87f97..a73d41ccacc59c22c4dc32c38f75d884736c6839 100644 (file)
@@ -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)
index 700a03e8f51c561fa29454798710d8a7e2ec16c7..8ae35b4355145bd47d925e7669a6eb023dcbd64d 100644 (file)
@@ -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
 }