diff --git a/go.mod b/go.mod index d6cba33..5e046e2 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,4 @@ module piekarnikgosi go 1.26.2 -require ( - github.com/adrium/goheif v0.0.0-20230113233934-ca402e77a786 // indirect - github.com/vegidio/avif-go v0.0.0-20260318201954-49ee16a82be7 // indirect -) +require github.com/a-h/templ v0.3.1020 diff --git a/go.sum b/go.sum index 377fdbb..0857b6f 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -github.com/adrium/goheif v0.0.0-20230113233934-ca402e77a786 h1:zvgtcRb2B5gynWjm+Fc9oJZPHXwmcgyH0xCcNm6Rmo4= -github.com/adrium/goheif v0.0.0-20230113233934-ca402e77a786/go.mod h1:aKVJoQ0cc9K5Xb058XSnnAxXLliR97qbSqWBlm5ca1E= -github.com/vegidio/avif-go v0.0.0-20260318201954-49ee16a82be7 h1:TAgtdm0s/kM05YdoV3/hqz6ApHHtozxdKl5hdJ6YxqQ= -github.com/vegidio/avif-go v0.0.0-20260318201954-49ee16a82be7/go.mod h1:/ITCFP53XCH3zFZZLLtPm3jRqsv5CMgefZl4UCuP1rs= +github.com/a-h/templ v0.3.1020 h1:ypAT/L5ySWEnZ6Zft/5yfoWXYYkhFNvEFOeeqecg4tw= +github.com/a-h/templ v0.3.1020/go.mod h1:A2DlK61v+K+NRoGnhmYbNYVmtYHcFO5/AisMvBdDxTM= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= diff --git a/main.go b/main.go index 388c366..0649da2 100644 --- a/main.go +++ b/main.go @@ -1,24 +1,15 @@ package main import ( + "context" "fmt" "html/template" + "io" "net/http" "os" + "piekarnikgosi/templates" ) -func saveFile(t *template.Template, name string, data any) { - file, err := os.Create("www/" + name + ".html") - if err != nil { - panic(err) - } - defer file.Close() - err = t.ExecuteTemplate(file, name+".gohtml", data) - if err != nil { - panic(err) - } -} - type Product struct { Name string Image string @@ -43,18 +34,31 @@ var Cakes = []Product{ {"Karpatka", "014", "120", ""}, } -func generateHTML() { - t, err := template.ParseGlob(`templates/*.gohtml`) +type ComponentRenderer interface { + Render(ctx context.Context, w io.Writer) error +} + +func saveFile(name string, comp ComponentRenderer) { + file, err := os.Create("www/" + name + ".html") if err != nil { panic(err) } - saveFile(t, `index`, nil) - saveFile(t, `kawiarnia`, nil) - saveFile(t, `portfolio`, nil) - saveFile(t, `wyroby`, Cakes) - saveFile(t, `wyroby_torty`, nil) - saveFile(t, `wyroby_slodkie_stoly`, nil) - saveFile(t, `wyroby_lody`, nil) + defer file.Close() + + err = comp.Render(context.Background(), file) + if err != nil { + panic(err) + } +} + +func generateHTML() { + saveFile(`index`, templates.IndexPage()) + // saveFile(t, `kawiarnia`, nil) + // saveFile(t, `portfolio`, nil) + // saveFile(t, `wyroby`, Cakes) + // saveFile(t, `wyroby_torty`, nil) + // saveFile(t, `wyroby_slodkie_stoly`, nil) + // saveFile(t, `wyroby_lody`, nil) } func main() { diff --git a/templates/header.gohtml b/templates/header.gohtml index 0f3c98e..a572e2b 100644 --- a/templates/header.gohtml +++ b/templates/header.gohtml @@ -24,4 +24,4 @@ Kontakt -{{end}} \ No newline at end of file +{{end}} diff --git a/templates/index.gohtml b/templates/index.gohtml deleted file mode 100644 index 00692ce..0000000 --- a/templates/index.gohtml +++ /dev/null @@ -1,141 +0,0 @@ -{{template "header" "index"}} -
-
-
-

Słodkości tworzone z pasją

-

Naturalne składniki, domowe receptury i pasja. Tworzymy torty i wypieki na Twoje najważniejsze chwile - - od codziennych radości po wielkie uroczystości

- Zobacz naszą ofertę -
-
- tort -
-
-
-
-
-
- kawiarnia -
-
- kawiarnia -
-
-
- Tradycja i serce -

O nas

-

- „Piekarnik Gosi” to marzenie, które udało mi się zrealizować dzięki wsparciu i pomocy moich - najbliższych. To pracownia cukiernicza stworzona z zamiłowania do pieczenia. Tworzę z pasją, z - najwyższej jakości składników, słodkości, które uświetnią każdą uroczystość oraz spotkanie. - Wszystkie wypieki wykonuje od podstaw własnoręcznie : od biszkoptu , frużelin owocowych, chrupek , - kremów aż po elementy dekoracyjne. W mojej ofercie znajdują się torty weselne, słodkie stoły, torty - okazjonalne, tarty i ciasta wykonywane na indywidualne zamówienia. Co wyróżnia moją pracownię? - Domowy i naturalny smak 🙂 Realizuje życzenia klientów ze starannością i pełnym zaangażowaniem. -

-
-
-
- -
-
-
-

Twój drugi dom

-

Poczuj się jak w domu. Codziennie czekają na Ciebie świeże wypieki prosto z naszej pracowni, - selekcja - najlepszych herbat i przepyszna kawa. To tutaj nasze ciasta smakują najlepiej – podane z - uśmiechem, w - miejscu stworzonym z pasji do słodkości.

-
    -
  • - - - - - - - Miła atmosfera -
  • -
  • - - - - - - - Darmowe wifi -
  • -
-
-
-
- kawiarnia -
-
- ciasto i kawa -
-
-
-
-
-{{template "footer"}} \ No newline at end of file diff --git a/templates/layout.templ b/templates/layout.templ new file mode 100644 index 0000000..59f74e1 --- /dev/null +++ b/templates/layout.templ @@ -0,0 +1,375 @@ +package templates + +import "fmt" + +templ Layout(activePage string) { + + + + + Piekarnik Gosi + + + + + + + + { children... } + + + +} + +templ Link(activePage, targetPage, title string) { + if activePage == targetPage { + { title } + } else { + { title } + } +} + +templ IndexPage() { + @Layout("index") { +
+
+
+

Słodkości tworzone z pasją

+

+ Naturalne składniki, domowe receptury i pasja. Tworzymy torty i wypieki na Twoje najważniejsze chwile + - od codziennych radości po wielkie uroczystości +

+ Zobacz naszą ofertę +
+
+ tort +
+
+
+
+
+
+ kawiarnia +
+
+ kawiarnia +
+
+
+ Tradycja i serce +

O nas

+

+ „Piekarnik Gosi” to marzenie, które udało mi się zrealizować dzięki wsparciu i pomocy moich + najbliższych. To pracownia cukiernicza stworzona z zamiłowania do pieczenia. Tworzę z pasją, z + najwyższej jakości składników, słodkości, które uświetnią każdą uroczystość oraz spotkanie. + Wszystkie wypieki wykonuje od podstaw własnoręcznie : od biszkoptu , frużelin owocowych, chrupek , + kremów aż po elementy dekoracyjne. W mojej ofercie znajdują się torty weselne, słodkie stoły, torty + okazjonalne, tarty i ciasta wykonywane na indywidualne zamówienia. Co wyróżnia moją pracownię? + Domowy i naturalny smak 🙂 Realizuje życzenia klientów ze starannością i pełnym zaangażowaniem. +

+
+
+
+ +
+
+
+

Twój drugi dom

+

+ Poczuj się jak w domu. Codziennie czekają na Ciebie świeże wypieki prosto z naszej pracowni, + selekcja + najlepszych herbat i przepyszna kawa. To tutaj nasze ciasta smakują najlepiej – podane z + uśmiechem, w + miejscu stworzonym z pasji do słodkości. +

+
    +
  • + + + + + + + Miła atmosfera +
  • +
  • + + + + + + + Darmowe wifi +
  • +
+
+
+
+ kawiarnia +
+
+ ciasto i kawa +
+
+
+
+
+ } +} diff --git a/templates/layout_templ.go b/templates/layout_templ.go new file mode 100644 index 0000000..842b918 --- /dev/null +++ b/templates/layout_templ.go @@ -0,0 +1,192 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.3.1020 +package templates + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import "fmt" + +func Layout(activePage string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "Piekarnik Gosi") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ_7745c5c3_Var1.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func Link(activePage, targetPage, title string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var2 := templ.GetChildren(ctx) + if templ_7745c5c3_Var2 == nil { + templ_7745c5c3_Var2 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + if activePage == targetPage { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(title) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/layout.templ`, Line: 178, Col: 12} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(title) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/layout.templ`, Line: 180, Col: 53} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) +} + +func IndexPage() templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var6 := templ.GetChildren(ctx) + if templ_7745c5c3_Var6 == nil { + templ_7745c5c3_Var6 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var7 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "

Słodkości tworzone z pasją

Naturalne składniki, domowe receptury i pasja. Tworzymy torty i wypieki na Twoje najważniejsze chwile - od codziennych radości po wielkie uroczystości

Zobacz naszą ofertę
\"tort\"
\"kawiarnia\"
\"kawiarnia\"
Tradycja i serce

O nas

„Piekarnik Gosi” to marzenie, które udało mi się zrealizować dzięki wsparciu i pomocy moich najbliższych. To pracownia cukiernicza stworzona z zamiłowania do pieczenia. Tworzę z pasją, z najwyższej jakości składników, słodkości, które uświetnią każdą uroczystość oraz spotkanie. Wszystkie wypieki wykonuje od podstaw własnoręcznie : od biszkoptu , frużelin owocowych, chrupek , kremów aż po elementy dekoracyjne. W mojej ofercie znajdują się torty weselne, słodkie stoły, torty okazjonalne, tarty i ciasta wykonywane na indywidualne zamówienia. Co wyróżnia moją pracownię? Domowy i naturalny smak 🙂 Realizuje życzenia klientów ze starannością i pełnym zaangażowaniem.

Nasze Wyroby

\"tort\"

Torty Okazjonalne

Weselne, urodzinowe i te bez okazji – od klasyki po nowoczesne musy.

Przeglądaj Torty
\"ciasto\"

Domowe Ciasta

Zapach tradycji: od serników po puszyste bezy

Wyberz ciasto
\"slodkosci\"

Słodkie Stoły

Kompleksowa oprawa słodkości na większe przyjęcia.

Sprawdź słodkie stoły

Twój drugi dom

Poczuj się jak w domu. Codziennie czekają na Ciebie świeże wypieki prosto z naszej pracowni, selekcja najlepszych herbat i przepyszna kawa. To tutaj nasze ciasta smakują najlepiej – podane z uśmiechem, w miejscu stworzonym z pasji do słodkości.

  • Miła atmosfera
  • Darmowe wifi
\"kawiarnia\"
\"ciasto
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = Layout("index").Render(templ.WithChildren(ctx, templ_7745c5c3_Var7), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +var _ = templruntime.GeneratedTemplate