Added static pages

This commit is contained in:
Simon Martens
2024-12-03 20:15:39 +01:00
parent 71927afebd
commit 5f6886a144
17 changed files with 72 additions and 30 deletions

View File

@@ -6,8 +6,8 @@ tmp_dir = "tmp"
args_bin = [] args_bin = []
bin = "./tmp/main" bin = "./tmp/main"
cmd = "go build -tags=\"dev\" -o ./tmp/main ." cmd = "go build -tags=\"dev\" -o ./tmp/main ."
delay = 1000 delay = 400
exclude_dir = ["assets", "views", "tmp", "vendor", "testdata", "data_git", "cache_gnd"] exclude_dir = ["views/assets", "views/routes", "views/node_modules", "tmp", "vendor", "testdata", "data_git", "cache_gnd", "cache_geonames"]
exclude_file = [] exclude_file = []
exclude_regex = ["_test.go"] exclude_regex = ["_test.go"]
exclude_unchanged = false exclude_unchanged = false

9
controllers/static.go Normal file
View File

@@ -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)
}
}

View File

@@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
@@ -80,21 +79,21 @@ func Start(k *app.KGPZ, s *server.Server) {
}() }()
// Interactive listening for input // Interactive listening for input
if k.IsDebug() { // if k.IsDebug() {
go func() { // go func() {
for { // for {
var input string // var input string
fmt.Scanln(&input) // fmt.Scanln(&input)
if input == "r" { // if input == "r" {
s.Restart() // s.Restart()
} else if input == "p" { // } else if input == "p" {
k.Pull() // k.Pull()
} else if input == "q" { // } else if input == "q" {
sigs <- os.Signal(syscall.SIGTERM) // sigs <- os.Signal(syscall.SIGTERM)
} // }
} // }
}() // }()
} // }
//
<-done <-done
} }

View File

@@ -101,13 +101,11 @@ func (s *Server) Watcher() error {
func (s *Server) Start() { func (s *Server) Start() {
s.engine.Reload() s.engine.Reload()
if s.cache != nil { if s.cache == nil {
s.cache.Close()
}
s.cache = memory.New(memory.Config{ s.cache = memory.New(memory.Config{
GCInterval: 30 * time.Second, GCInterval: 30 * time.Second,
}) })
}
srv := fiber.New(fiber.Config{ srv := fiber.New(fiber.Config{
AppName: s.Config.Address, AppName: s.Config.Address,
@@ -165,6 +163,11 @@ func (s *Server) Start() {
srv.Get("/:year/:issue/:page?", controllers.GetIssue(s.kgpz)) srv.Get("/:year/:issue/:page?", controllers.GetIssue(s.kgpz))
srv.Get("/:year/:issue/beilage/: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) s.runner(srv)
if s.Config.Debug { 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.") logging.Error(err, "Error closing server cleanly. Shutting server down by force.")
clean = false clean = false
} }
s.cache.Close() s.cache.Reset()
} }
if !clean { if !clean {

7
viewmodels/page.go Normal file
View File

@@ -0,0 +1,7 @@
package viewmodels
type PageViewModel struct {
Title string
Description string
Keywords string
}

View File

@@ -45,11 +45,16 @@ func YearView(year string, lib *xmlprovider.Library) (*YearViewModel, error) {
return nil, errors.New("No issues found for year " + year) return nil, errors.New("No issues found for year " + year)
} }
res.SortAvailableYears() res.Sort()
return &res, nil return &res, nil
} }
func (y *YearViewModel) Sort() {
y.SortAvailableYears()
y.Issues.Sort()
}
func (y *YearViewModel) PushIssue(i xmlprovider.Issue) { func (y *YearViewModel) PushIssue(i xmlprovider.Issue) {
iv, err := FromIssue(i) iv, err := FromIssue(i)
if err != nil { if err != nil {
@@ -59,6 +64,12 @@ func (y *YearViewModel) PushIssue(i xmlprovider.Issue) {
list, ok := y.Issues[iv.Month] list, ok := y.Issues[iv.Month]
if !ok { if !ok {
list = []IssueViewModel{} list = []IssueViewModel{}
} else {
for _, issue := range list {
if issue.Number.No == iv.Number.No {
return
}
}
} }
y.Issues[iv.Month] = append(list, *iv) y.Issues[iv.Month] = append(list, *iv)
@@ -84,3 +95,11 @@ func (y *YearViewModel) SortAvailableYears() {
return iint < jint 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
})
}
}

1
views/head.gohtml Normal file
View File

@@ -0,0 +1 @@
<title>KGPZ - Ausgaben {{ .model.year }}</title>

View File

View File

@@ -0,0 +1 @@
<title>KGPZ - Impressum &amp; Datenschutz</title>

View File

View File

@@ -0,0 +1 @@
<title>KGPZ - Geschichte &amp; Edition</title>

View File

@@ -1,11 +1,10 @@
{{ $model := .model }} {{ $model := .model }}
<div> <div>
<a href="/{{- $model.Year -}}" aria-current="page"> <a href="/{{- $model.Year -}}">
Zurück zum Jahr Zurück zum Jahr
{{ $model.Year }} {{ $model.Year }}
</a> </a>
</div> </div>
Issue found!
{{ $page := 0 }} {{ $page := 0 }}
{{ range $piece := .model.Pieces.IssuePieces }} {{ range $piece := .model.Pieces.IssuePieces }}
<div> <div>
@@ -14,7 +13,7 @@ Issue found!
<div>S. {{ $page }}</div> <div>S. {{ $page }}</div>
{{ end }} {{ end }}
Piece! Eintrag!
{{ if gt (len $piece.IssueRefs) 1 }} {{ if gt (len $piece.IssueRefs) 1 }}
{{ len $piece.IssueRefs }} Teile {{ len $piece.IssueRefs }} Teile
<ol> <ol>

View File

@@ -0,0 +1 @@
<title>KGPZ - Ausgabe {{ .model.Year }}&verythinsp;/&verythinsp;{{ .model.No }}</title>

View File

View File

@@ -0,0 +1 @@
<title>KGPZ - Kontakt</title>

View File

View File

@@ -0,0 +1 @@
<title>KGPZ - Zitation</title>