Changes
34 changed files (+48/-19)
-
-
@@ -30,7 +30,7 @@ dirs:# # If you omit this, legit will use its default templates directory # ("templates" directory next to this file) embedded in the binary. templates: ./templates templates: ./embed/templates # [optional] # Path to a directory containing custom static assets.
-
@@ -38,7 +38,7 @@ dirs:# ("static" directory next to this file) embedded in the binary. # # Visitors can access files in this directory by accessing "/static/*". static: ./static static: ./embed/static meta: # Website's name.
-
-
embed/embed.go (new)
-
@@ -0,0 +1,42 @@// This package exposes embedded resources across modules. // A dedicated module is necessary due to Go's restriction on "embed" package // cannot embed resources on parent directories (and Go not allowing circular // dependencies.) // // Copyright 2025 Shota FUJI <pockawoooh@gmail.com> // SPDX-License-Identifier: MIT package embed import ( "embed" "io/fs" ) //go:embed static/* var defaultStaticDir embed.FS //go:embed templates/* var defaultTemplatesDir embed.FS // StaticDir returns embedded default static contents directory. func StaticDir() fs.FS { // Go cannot embed directory as-is. Stripping the subdirectory. f, err := fs.Sub(defaultStaticDir, "static") if err != nil { panic("static/ directory not embedded correctly") } return f } // TemplatesDir returns embedded default templates directory. func TemplatesDir() fs.FS { // Go cannot embed directory as-is. Stripping the subdirectory. f, err := fs.Sub(defaultTemplatesDir, "templates") if err != nil { panic("templates/ directory not embedded correctly") } return f }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
templates/repo-blob-ref-html-preview.html.tmpl > embed/templates/repo-blob-ref-html-preview.html.tmpl
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -43,8 +43,7 @@fileset = unions [ ./go.mod ./go.sum ./static ./templates ./embed (fileFilter (file: file.hasExt "go") ./.) ]; };
-
-
-
@@ -1,7 +1,6 @@package main import ( "embed" "flag" "fmt" "io/fs"
-
@@ -11,15 +10,10 @@ import ("os" "github.com/pocka/legit/config" "github.com/pocka/legit/embed" "github.com/pocka/legit/routes" ) //go:embed static/* var defaultStaticDir embed.FS //go:embed templates/* var defaultTemplatesDir embed.FS func main() { var cfg string var host string
-
@@ -65,20 +59,14 @@ func main() {staticDir = root.FS() } else { staticDir, err = fs.Sub(defaultStaticDir, "static") if err != nil { log.Fatalf("Unable to open default static dir: %s", err) } staticDir = embed.StaticDir() } var templatesDir fs.FS if c.Dirs.Templates != "" { templatesDir = os.DirFS(c.Dirs.Templates) } else { templatesDir, err = fs.Sub(defaultTemplatesDir, "templates") if err != nil { log.Fatalf("Unable to open default templates dir: %s", err) } templatesDir = embed.TemplatesDir() } mux := routes.Handlers(c, staticDir, templatesDir)
-