From 5f6886a1444fcf4853b27ed2d8036676d5418b9a Mon Sep 17 00:00:00 2001 From: Simon Martens Date: Tue, 3 Dec 2024 20:15:39 +0100 Subject: [PATCH] Added static pages --- .air.toml | 4 ++-- controllers/static.go | 9 ++++++++ kgpz_web.go | 33 ++++++++++++++-------------- server/server.go | 17 ++++++++------ viewmodels/page.go | 7 ++++++ viewmodels/yearvm.go | 21 +++++++++++++++++- views/head.gohtml | 1 + views/routes/datenschutz/body.gohtml | 0 views/routes/datenschutz/head.gohtml | 1 + views/routes/edition/body.gohtml | 0 views/routes/edition/head.gohtml | 1 + views/routes/issue/body.gohtml | 5 ++--- views/routes/issue/head.gohtml | 1 + views/routes/kontakt/body.gotmpl | 0 views/routes/kontakt/head.gohtml | 1 + views/routes/zitation/body.gohtml | 0 views/routes/zitation/head.gohtml | 1 + 17 files changed, 72 insertions(+), 30 deletions(-) create mode 100644 controllers/static.go create mode 100644 viewmodels/page.go create mode 100644 views/head.gohtml create mode 100644 views/routes/datenschutz/body.gohtml create mode 100644 views/routes/datenschutz/head.gohtml create mode 100644 views/routes/edition/body.gohtml create mode 100644 views/routes/edition/head.gohtml create mode 100644 views/routes/issue/head.gohtml create mode 100644 views/routes/kontakt/body.gotmpl create mode 100644 views/routes/kontakt/head.gohtml create mode 100644 views/routes/zitation/body.gohtml create mode 100644 views/routes/zitation/head.gohtml diff --git a/.air.toml b/.air.toml index 5139b3e..21d1da9 100644 --- a/.air.toml +++ b/.air.toml @@ -6,8 +6,8 @@ tmp_dir = "tmp" args_bin = [] bin = "./tmp/main" cmd = "go build -tags=\"dev\" -o ./tmp/main ." - delay = 1000 - exclude_dir = ["assets", "views", "tmp", "vendor", "testdata", "data_git", "cache_gnd"] + delay = 400 + exclude_dir = ["views/assets", "views/routes", "views/node_modules", "tmp", "vendor", "testdata", "data_git", "cache_gnd", "cache_geonames"] exclude_file = [] exclude_regex = ["_test.go"] exclude_unchanged = false diff --git a/controllers/static.go b/controllers/static.go new file mode 100644 index 0000000..e32a8d0 --- /dev/null +++ b/controllers/static.go @@ -0,0 +1,9 @@ +package controllers + +import "github.com/gofiber/fiber/v2" + +func Get(path string) fiber.Handler { + return func(c *fiber.Ctx) error { + return c.Render(path, nil) + } +} diff --git a/kgpz_web.go b/kgpz_web.go index 590a7a1..224ab9f 100644 --- a/kgpz_web.go +++ b/kgpz_web.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "os" "os/signal" "syscall" @@ -80,21 +79,21 @@ func Start(k *app.KGPZ, s *server.Server) { }() // Interactive listening for input - if k.IsDebug() { - go func() { - for { - var input string - fmt.Scanln(&input) - if input == "r" { - s.Restart() - } else if input == "p" { - k.Pull() - } else if input == "q" { - sigs <- os.Signal(syscall.SIGTERM) - } - } - }() - } - + // if k.IsDebug() { + // go func() { + // for { + // var input string + // fmt.Scanln(&input) + // if input == "r" { + // s.Restart() + // } else if input == "p" { + // k.Pull() + // } else if input == "q" { + // sigs <- os.Signal(syscall.SIGTERM) + // } + // } + // }() + // } + // <-done } diff --git a/server/server.go b/server/server.go index 438b1df..05067d2 100644 --- a/server/server.go +++ b/server/server.go @@ -101,14 +101,12 @@ func (s *Server) Watcher() error { func (s *Server) Start() { s.engine.Reload() - if s.cache != nil { - s.cache.Close() + if s.cache == nil { + s.cache = memory.New(memory.Config{ + GCInterval: 30 * time.Second, + }) } - s.cache = memory.New(memory.Config{ - GCInterval: 30 * time.Second, - }) - srv := fiber.New(fiber.Config{ AppName: s.Config.Address, CaseSensitive: false, @@ -165,6 +163,11 @@ func (s *Server) Start() { srv.Get("/:year/:issue/:page?", controllers.GetIssue(s.kgpz)) srv.Get("/:year/:issue/beilage/:page?", controllers.GetIssue(s.kgpz)) + srv.Get("/edition/", controllers.Get("/edition/")) + srv.Get("/datenschutz/", controllers.Get("/datenschutz/")) + srv.Get("/kontakt/", controllers.Get("/kontakt/")) + srv.Get("/zitation/", controllers.Get("/zitation/")) + s.runner(srv) if s.Config.Debug { @@ -228,7 +231,7 @@ func (s *Server) runner(srv *fiber.App) { logging.Error(err, "Error closing server cleanly. Shutting server down by force.") clean = false } - s.cache.Close() + s.cache.Reset() } if !clean { diff --git a/viewmodels/page.go b/viewmodels/page.go new file mode 100644 index 0000000..ee2874c --- /dev/null +++ b/viewmodels/page.go @@ -0,0 +1,7 @@ +package viewmodels + +type PageViewModel struct { + Title string + Description string + Keywords string +} diff --git a/viewmodels/yearvm.go b/viewmodels/yearvm.go index d8dc35b..7ec0f95 100644 --- a/viewmodels/yearvm.go +++ b/viewmodels/yearvm.go @@ -45,11 +45,16 @@ func YearView(year string, lib *xmlprovider.Library) (*YearViewModel, error) { return nil, errors.New("No issues found for year " + year) } - res.SortAvailableYears() + res.Sort() return &res, nil } +func (y *YearViewModel) Sort() { + y.SortAvailableYears() + y.Issues.Sort() +} + func (y *YearViewModel) PushIssue(i xmlprovider.Issue) { iv, err := FromIssue(i) if err != nil { @@ -59,6 +64,12 @@ func (y *YearViewModel) PushIssue(i xmlprovider.Issue) { list, ok := y.Issues[iv.Month] if !ok { list = []IssueViewModel{} + } else { + for _, issue := range list { + if issue.Number.No == iv.Number.No { + return + } + } } y.Issues[iv.Month] = append(list, *iv) @@ -84,3 +95,11 @@ func (y *YearViewModel) SortAvailableYears() { return iint < jint }) } + +func (ibm *IssuesByMonth) Sort() { + for _, issues := range *ibm { + sort.Slice(issues, func(i, j int) bool { + return issues[i].Number.No < issues[j].Number.No + }) + } +} diff --git a/views/head.gohtml b/views/head.gohtml new file mode 100644 index 0000000..c86ac95 --- /dev/null +++ b/views/head.gohtml @@ -0,0 +1 @@ +KGPZ - Ausgaben {{ .model.year }} diff --git a/views/routes/datenschutz/body.gohtml b/views/routes/datenschutz/body.gohtml new file mode 100644 index 0000000..e69de29 diff --git a/views/routes/datenschutz/head.gohtml b/views/routes/datenschutz/head.gohtml new file mode 100644 index 0000000..2273665 --- /dev/null +++ b/views/routes/datenschutz/head.gohtml @@ -0,0 +1 @@ +KGPZ - Impressum & Datenschutz diff --git a/views/routes/edition/body.gohtml b/views/routes/edition/body.gohtml new file mode 100644 index 0000000..e69de29 diff --git a/views/routes/edition/head.gohtml b/views/routes/edition/head.gohtml new file mode 100644 index 0000000..909488c --- /dev/null +++ b/views/routes/edition/head.gohtml @@ -0,0 +1 @@ +KGPZ - Geschichte & Edition diff --git a/views/routes/issue/body.gohtml b/views/routes/issue/body.gohtml index 95cea5a..4b85fcb 100644 --- a/views/routes/issue/body.gohtml +++ b/views/routes/issue/body.gohtml @@ -1,11 +1,10 @@ {{ $model := .model }}
- + Zurück zum Jahr {{ $model.Year }}
-Issue found! {{ $page := 0 }} {{ range $piece := .model.Pieces.IssuePieces }}
@@ -14,7 +13,7 @@ Issue found!
S. {{ $page }}
{{ end }} - Piece! + Eintrag! {{ if gt (len $piece.IssueRefs) 1 }} {{ len $piece.IssueRefs }} Teile
    diff --git a/views/routes/issue/head.gohtml b/views/routes/issue/head.gohtml new file mode 100644 index 0000000..e27fe36 --- /dev/null +++ b/views/routes/issue/head.gohtml @@ -0,0 +1 @@ +KGPZ - Ausgabe {{ .model.Year }}&verythinsp;/&verythinsp;{{ .model.No }} diff --git a/views/routes/kontakt/body.gotmpl b/views/routes/kontakt/body.gotmpl new file mode 100644 index 0000000..e69de29 diff --git a/views/routes/kontakt/head.gohtml b/views/routes/kontakt/head.gohtml new file mode 100644 index 0000000..262b171 --- /dev/null +++ b/views/routes/kontakt/head.gohtml @@ -0,0 +1 @@ +KGPZ - Kontakt diff --git a/views/routes/zitation/body.gohtml b/views/routes/zitation/body.gohtml new file mode 100644 index 0000000..e69de29 diff --git a/views/routes/zitation/head.gohtml b/views/routes/zitation/head.gohtml new file mode 100644 index 0000000..d6062e0 --- /dev/null +++ b/views/routes/zitation/head.gohtml @@ -0,0 +1 @@ +KGPZ - Zitation