diff --git a/Dockerfile b/Dockerfile index d91ca09..a062281 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,8 @@ ADD config/ config/ ADD media/ media/ +ADD templates/ templates/ + RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o agecem-org . # Alpine diff --git a/cmd/server.go b/cmd/server.go index 3abcb0a..fab4eaf 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -25,6 +25,7 @@ import ( "git.agecem.com/agecem/agecem-org/config" "git.agecem.com/agecem/agecem-org/media" "git.agecem.com/agecem/agecem-org/public" + "git.agecem.com/agecem/agecem-org/templates" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" ) @@ -35,7 +36,10 @@ type Template struct { var cfg config.Config -var embedFS embed.FS +var ( + publicFS embed.FS + templatesFS embed.FS +) // serverCmd represents the server command var serverCmd = &cobra.Command{ @@ -64,7 +68,8 @@ var serverCmd = &cobra.Command{ func init() { rootCmd.AddCommand(serverCmd) - embedFS = public.GetEmbedFS() + publicFS = public.GetPublicFS() + templatesFS = templates.GetTemplatesFS() // server.port - --server-port serverCmd.Flags().Int("server-port", 8080, "Port to run the webserver on (config: server.port)") @@ -122,7 +127,7 @@ func RunServer() { e := echo.New() t := &Template{ - templates: template.Must(template.ParseFS(embedFS, "html/*.gohtml")), + templates: template.Must(template.ParseFS(templatesFS, "html/*.gohtml")), } e.Renderer = t @@ -745,12 +750,12 @@ func handleAdminDocumentsUploadPOST(c echo.Context) error { func handleStaticCSSIndex(c echo.Context) error { // TODO Ajouter gestion d'erreurs - data, _ := embedFS.ReadFile("css/index.css") + data, _ := publicFS.ReadFile("css/index.css") return c.Blob(http.StatusOK, "text/css", data) } func handleStaticCSSGeneral(c echo.Context) error { // TODO Ajouter gestion d'erreurs - data, _ := embedFS.ReadFile("css/general.css") + data, _ := publicFS.ReadFile("css/general.css") return c.Blob(http.StatusOK, "text/css", data) } diff --git a/public/public.go b/public/public.go index 60d9fe6..a2ab158 100644 --- a/public/public.go +++ b/public/public.go @@ -2,9 +2,9 @@ package public import "embed" -//go:embed html/* css/* js/* -var embedFS embed.FS +//go:embed css/*.css js/*.js +var publicFS embed.FS -func GetEmbedFS() embed.FS { - return embedFS +func GetPublicFS() embed.FS { + return publicFS } diff --git a/public/html/a-propos.gohtml b/templates/html/a-propos.gohtml similarity index 100% rename from public/html/a-propos.gohtml rename to templates/html/a-propos.gohtml diff --git a/public/html/actualite.gohtml b/templates/html/actualite.gohtml similarity index 100% rename from public/html/actualite.gohtml rename to templates/html/actualite.gohtml diff --git a/public/html/admin-upload.gohtml b/templates/html/admin-upload.gohtml similarity index 100% rename from public/html/admin-upload.gohtml rename to templates/html/admin-upload.gohtml diff --git a/public/html/admin.gohtml b/templates/html/admin.gohtml similarity index 100% rename from public/html/admin.gohtml rename to templates/html/admin.gohtml diff --git a/public/html/documentation.gohtml b/templates/html/documentation.gohtml similarity index 100% rename from public/html/documentation.gohtml rename to templates/html/documentation.gohtml diff --git a/public/html/formulaires.gohtml b/templates/html/formulaires.gohtml similarity index 100% rename from public/html/formulaires.gohtml rename to templates/html/formulaires.gohtml diff --git a/public/html/general.gohtml b/templates/html/general.gohtml similarity index 100% rename from public/html/general.gohtml rename to templates/html/general.gohtml diff --git a/public/html/header.gohtml b/templates/html/header.gohtml similarity index 100% rename from public/html/header.gohtml rename to templates/html/header.gohtml diff --git a/public/html/index.gohtml b/templates/html/index.gohtml similarity index 100% rename from public/html/index.gohtml rename to templates/html/index.gohtml diff --git a/public/html/vie-etudiante.gohtml b/templates/html/vie-etudiante.gohtml similarity index 100% rename from public/html/vie-etudiante.gohtml rename to templates/html/vie-etudiante.gohtml diff --git a/templates/templates.go b/templates/templates.go new file mode 100644 index 0000000..d848e80 --- /dev/null +++ b/templates/templates.go @@ -0,0 +1,10 @@ +package templates + +import "embed" + +//go:embed html/*.gohtml +var templatesFS embed.FS + +func GetTemplatesFS() embed.FS { + return templatesFS +}