this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

⚡️ Use statically rendered pages when available in production environment

+20 -2
+1 -1
Justfile
··· 7 7 8 8 start: 9 9 just build 10 - ENV=prod ./tmp/main 10 + ENV=production ./tmp/main 11 11 12 12 build: 13 13 templ generate
+14 -1
main.go
··· 38 38 } 39 39 } 40 40 41 + if os.Getenv("ENV") == "production" { 42 + // Try to get rendered static page first 43 + content, err := GetPage(filepath.Join("dist", translations.language), path) 44 + if err != nil { 45 + color.Cyan("[%s] Could not get static page for /%s: %s, falling back to server rendering until next restart", translations.language, path, err) 46 + } else { 47 + server.Handle(fmt.Sprintf("/%s", path), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 48 + w.Write(content) 49 + })) 50 + registeredPaths = append(registeredPaths, path) 51 + return 52 + } 53 + } 54 + 41 55 translator := HttpTranslator{ 42 56 translations: translations, 43 57 ch: templ.Handler(pages.Layout(page, collections.URLsToNames(true, translations.language), sites, translations.language)), 44 58 } 45 59 46 - // fmt.Printf("[%s] Registering page /%s\n", locale, path) 47 60 server.Handle(fmt.Sprintf("/%s", path), translator) 48 61 registeredPaths = append(registeredPaths, path) 49 62 }
+5
static.go
··· 8 8 "path/filepath" 9 9 ) 10 10 11 + func GetPage(inside string, path string) ([]byte, error) { 12 + pagePath := filepath.Join(inside, path, "index.html") 13 + return os.ReadFile(pagePath) 14 + } 15 + 11 16 func StaticallyRender(inside string, origin string, path string) error { 12 17 outputPath := filepath.Join(inside, path, "index.html") 13 18 url := fmt.Sprintf("%s/%s", origin, path)