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 = []
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

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

View File

@@ -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 {

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

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