Basic Briefansicht + parsing

This commit is contained in:
Simon Martens
2025-04-01 18:07:57 +02:00
parent 0e2c6360bf
commit 31d40c1ce1
13 changed files with 107 additions and 55 deletions

View File

@@ -24,5 +24,5 @@ func GetLetter(c *fiber.Ctx) error {
text := lib.Letters.Item(letter)
tradition := lib.Traditions.Item(letter)
return c.Render("/brief/", map[string]any{"meta": meta, "text": text, "tradition": tradition, "next": np.Next, "prev": np.Prev})
return c.Render("/brief/", fiber.Map{"meta": meta, "text": text, "tradition": tradition, "next": np.Next, "prev": np.Prev})
}

View File

@@ -1,27 +1,12 @@
package controllers
import (
"strconv"
"github.com/Theodor-Springmann-Stiftung/lenz-web/xmlmodels"
"github.com/gofiber/fiber/v2"
"strconv"
)
const DEFAULT_YEAR = 1765
func GetIndex(c *fiber.Ctx) error {
return c.Redirect(JAHRGAENGE_URL + "/" + strconv.Itoa(DEFAULT_YEAR))
}
func GetIndexYear(c *fiber.Ctx) error {
lib := xmlmodels.Get()
years, yearmap := lib.Years()
y := c.Params(YEAR_PARAM)
year, err := strconv.Atoi(y)
if _, ok := yearmap[year]; (err != nil || !ok) && y != "all" {
return c.SendStatus(fiber.StatusNotFound)
}
return c.Render(JAHRGAENGE_URL+"/", map[string]any{"years": years, "yearmap": yearmap, "year": year, "all": y == "all"})
return c.Redirect(LETTERS_URL + "?year=" + strconv.Itoa(DEFAULT_YEAR))
}

View File

@@ -6,30 +6,37 @@ import (
"github.com/Theodor-Springmann-Stiftung/lenz-web/server"
"github.com/Theodor-Springmann-Stiftung/lenz-web/views"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/compress"
)
const INDEX_URL = "/"
const ASSETS_URL = "/assets"
const DATENSCHUTZ_URL = "/datenschutz"
const JAHRGAENGE_URL = "/jahrgang"
const ZITATION_URL = "/ausgabe/zitation"
const EDITION_URL = "/ausgabe/edition"
const KONTAKT_URL = "/kontakt"
var INDEX_YEAR_URL = JAHRGAENGE_URL + "/:" + YEAR_PARAM
var LETTER_URL = "/brief/:" + LETTER_PARAM
const YEAR_PARAM = "year"
const LETTER_PARAM = "letter"
const (
INDEX_URL = "/"
ASSETS_URL = "/assets"
DATENSCHUTZ_URL = "/datenschutz"
LETTERS_URL = "/briefe"
ZITATION_URL = "/ausgabe/zitation"
EDITION_URL = "/ausgabe/edition"
KONTAKT_URL = "/kontakt"
LETTER_URL = "/brief/:" + LETTER_PARAM
YEAR_PARAM = "year"
LETTER_PARAM = "letter"
)
func Register(server server.Server, cfg config.Config) {
server.Server.Use(ASSETS_URL, compress.New(compress.Config{
Level: compress.LevelBestSpeed,
}))
server.Server.Use(ASSETS_URL, middleware.StaticHandler(&views.StaticFS))
server.Server.Use(func(ctx *fiber.Ctx) error {
ctx.Locals("cfg", cfg)
ctx.Locals("path", ctx.Path())
return ctx.Next()
})
server.Server.Get(INDEX_URL, GetIndex)
server.Server.Get(INDEX_YEAR_URL, GetIndexYear)
server.Server.Get(LETTERS_URL, GetLetters)
server.Server.Get(LETTER_URL, GetLetter)
server.Server.Get(DATENSCHUTZ_URL, Static(DATENSCHUTZ_URL+"/"))

View File

@@ -11,6 +11,6 @@ func Static(url string) fiber.Handler {
url += "/"
}
return func(c *fiber.Ctx) error {
return c.Render(url, map[string]any{})
return c.Render(url, fiber.Map{"Was": "Static"})
}
}

23
controllers/uebersicht.go Normal file
View File

@@ -0,0 +1,23 @@
package controllers
import (
"strconv"
"github.com/Theodor-Springmann-Stiftung/lenz-web/xmlmodels"
"github.com/gofiber/fiber/v2"
)
func GetLetters(c *fiber.Ctx) error {
lib := xmlmodels.Get()
years, yearmap := lib.Years()
y := c.Query(YEAR_PARAM, strconv.Itoa(DEFAULT_YEAR))
// TODO: does not work ATM
c.Locals("path", c.Path())
year, err := strconv.Atoi(y)
if _, ok := yearmap[year]; (err != nil || !ok) && y != "all" {
return c.SendStatus(fiber.StatusNotFound)
}
return c.Render(LETTERS_URL+"/", fiber.Map{"years": years, "yearmap": yearmap, "year": year, "all": y == "all"})
}