mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 01:05:32 +00:00
Some changes, path specific data
This commit is contained in:
@@ -1,5 +1,24 @@
|
|||||||
package functions
|
package functions
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
func Arr(els ...any) []any {
|
func Arr(els ...any) []any {
|
||||||
return els
|
return els
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Dict(values ...interface{}) (map[string]interface{}, error) {
|
||||||
|
// Must have even number of args: key, value, key, value, ...
|
||||||
|
if len(values)%2 != 0 {
|
||||||
|
return nil, fmt.Errorf("invalid dict call: must have even number of args")
|
||||||
|
}
|
||||||
|
|
||||||
|
m := make(map[string]interface{}, len(values)/2)
|
||||||
|
for i := 0; i < len(values); i += 2 {
|
||||||
|
key, ok := values[i].(string)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("dict keys must be strings")
|
||||||
|
}
|
||||||
|
m[key] = values[i+1]
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package pagemodels
|
package pagemodels
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||||
"github.com/pocketbase/pocketbase/core"
|
"github.com/pocketbase/pocketbase/core"
|
||||||
"github.com/pocketbase/pocketbase/tools/router"
|
"github.com/pocketbase/pocketbase/tools/router"
|
||||||
@@ -74,12 +71,7 @@ func (p *DefaultPage) Setup(router *router.Router[*core.RequestEvent], app core.
|
|||||||
data["keywords"] = p.Keywords()
|
data["keywords"] = p.Keywords()
|
||||||
data["text"] = p.Text()
|
data["text"] = p.Text()
|
||||||
|
|
||||||
var builder strings.Builder
|
return engine.Response200(e, p.Template, data, p.Layout)
|
||||||
err := engine.Render(&builder, p.Template, data, p.Layout)
|
|
||||||
if err != nil {
|
|
||||||
return e.HTML(http.StatusInternalServerError, err.Error())
|
|
||||||
}
|
|
||||||
return e.HTML(http.StatusOK, builder.String())
|
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package pagemodels
|
package pagemodels
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||||
"github.com/pocketbase/pocketbase/core"
|
"github.com/pocketbase/pocketbase/core"
|
||||||
"github.com/pocketbase/pocketbase/tools/router"
|
"github.com/pocketbase/pocketbase/tools/router"
|
||||||
@@ -33,12 +30,7 @@ func (p *Page) Down(app core.App) error {
|
|||||||
|
|
||||||
func (p *Page) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *Page) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||||
router.GET(p.Name, func(e *core.RequestEvent) error {
|
router.GET(p.Name, func(e *core.RequestEvent) error {
|
||||||
var builder strings.Builder
|
return engine.Response200(e, p.Template, nil, p.Layout)
|
||||||
err := engine.Render(&builder, p.Template, nil, p.Layout)
|
|
||||||
if err != nil {
|
|
||||||
return e.HTML(http.StatusInternalServerError, err.Error())
|
|
||||||
}
|
|
||||||
return e.HTML(http.StatusOK, builder.String())
|
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
29
pages/404.go
29
pages/404.go
@@ -1,9 +1,6 @@
|
|||||||
package pages
|
package pages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||||
@@ -12,9 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const URL_ERROR_404 = "/errors/404/"
|
const URL_ERROR_404 = "/errors/404/"
|
||||||
|
const URL_ERROR_500 = "/errors/500/"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rp := &Error404Page{
|
rp := &ErrorPage{
|
||||||
Page: pagemodels.Page{
|
Page: pagemodels.Page{
|
||||||
Name: URL_ERROR_404,
|
Name: URL_ERROR_404,
|
||||||
},
|
},
|
||||||
@@ -22,27 +20,20 @@ func init() {
|
|||||||
app.Register(rp)
|
app.Register(rp)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Error404Page struct {
|
type ErrorPage struct {
|
||||||
pagemodels.Page
|
pagemodels.Page
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Error404Page) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *ErrorPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||||
router.GET(URL_ERROR_404, func(e *core.RequestEvent) error {
|
router.GET(URL_ERROR_404, func(e *core.RequestEvent) error {
|
||||||
return Error404(e, engine, nil)
|
return engine.Response404(e, nil, nil)
|
||||||
|
})
|
||||||
|
router.GET(URL_ERROR_500, func(e *core.RequestEvent) error {
|
||||||
|
return engine.Response500(e, nil, nil)
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Error404(e *core.RequestEvent, engine *templating.Engine, err error) error {
|
func Error404(e *core.RequestEvent, engine *templating.Engine, err error, data map[string]interface{}) error {
|
||||||
data := make(map[string]interface{})
|
return engine.Response404(e, err, data)
|
||||||
var sb strings.Builder
|
|
||||||
if err != nil {
|
|
||||||
e.App.Logger().Error("404 error fetching URL!", "error", err, "request", e.Request.URL)
|
|
||||||
data["Error"] = err.Error()
|
|
||||||
}
|
|
||||||
err = engine.Render(&sb, URL_ERROR_404, data, "default")
|
|
||||||
if err != nil {
|
|
||||||
return e.String(http.StatusInternalServerError, err.Error())
|
|
||||||
}
|
|
||||||
return e.HTML(http.StatusNotFound, sb.String())
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package pages
|
package pages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
||||||
@@ -36,13 +33,13 @@ func (p *AlmanachPage) Setup(router *router.Router[*core.RequestEvent], app core
|
|||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
entry, err := dbmodels.EntryForMusenalmID(app, id)
|
entry, err := dbmodels.EntryForMusenalmID(app, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["entry"] = entry
|
data["entry"] = entry
|
||||||
|
|
||||||
series, srelations, _, err := dbmodels.SeriesForEntries(app, []*dbmodels.Entry{entry})
|
series, srelations, _, err := dbmodels.SeriesForEntries(app, []*dbmodels.Entry{entry})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := map[string]*dbmodels.Series{}
|
s := map[string]*dbmodels.Series{}
|
||||||
@@ -55,26 +52,26 @@ func (p *AlmanachPage) Setup(router *router.Router[*core.RequestEvent], app core
|
|||||||
|
|
||||||
places, err := dbmodels.PlacesForEntry(app, entry)
|
places, err := dbmodels.PlacesForEntry(app, entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["places"] = places
|
data["places"] = places
|
||||||
|
|
||||||
contents, err := dbmodels.ContentsForEntry(app, entry)
|
contents, err := dbmodels.ContentsForEntry(app, entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["contents"] = contents
|
data["contents"] = contents
|
||||||
|
|
||||||
agents, arelations, err := dbmodels.AgentsForEntries(app, []*dbmodels.Entry{entry})
|
agents, arelations, err := dbmodels.AgentsForEntries(app, []*dbmodels.Entry{entry})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["arelations"] = arelations
|
data["arelations"] = arelations
|
||||||
|
|
||||||
if len(contents) > 0 {
|
if len(contents) > 0 {
|
||||||
cagents, crelations, err := dbmodels.AgentsForContents(app, contents)
|
cagents, crelations, err := dbmodels.AgentsForContents(app, contents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["crelations"] = crelations
|
data["crelations"] = crelations
|
||||||
for k, v := range cagents {
|
for k, v := range cagents {
|
||||||
@@ -90,10 +87,5 @@ func (p *AlmanachPage) Setup(router *router.Router[*core.RequestEvent], app core
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *AlmanachPage) Get(request *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
func (p *AlmanachPage) Get(request *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
||||||
var builder strings.Builder
|
return engine.Response200(request, TEMPLATE_ALMANACH, data)
|
||||||
err := engine.Render(&builder, TEMPLATE_ALMANACH, data)
|
|
||||||
if err != nil {
|
|
||||||
return Error404(request, engine, err)
|
|
||||||
}
|
|
||||||
return request.HTML(http.StatusOK, builder.String())
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package pages
|
package pages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
||||||
@@ -37,13 +35,13 @@ func (p *PersonPage) Setup(router *router.Router[*core.RequestEvent], app core.A
|
|||||||
|
|
||||||
agent, err := dbmodels.AgentForId(app, person)
|
agent, err := dbmodels.AgentForId(app, person)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["a"] = agent
|
data["a"] = agent
|
||||||
|
|
||||||
series, relations, entries, err := dbmodels.SeriesForAgent(app, person)
|
series, relations, entries, err := dbmodels.SeriesForAgent(app, person)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbmodels.SortSeriessesByTitle(series)
|
dbmodels.SortSeriessesByTitle(series)
|
||||||
@@ -53,19 +51,19 @@ func (p *PersonPage) Setup(router *router.Router[*core.RequestEvent], app core.A
|
|||||||
|
|
||||||
contents, err := dbmodels.ContentsForAgent(app, person)
|
contents, err := dbmodels.ContentsForAgent(app, person)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
agents, crelations, err := dbmodels.AgentsForContents(app, contents)
|
agents, crelations, err := dbmodels.AgentsForContents(app, contents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["agents"] = agents
|
data["agents"] = agents
|
||||||
data["crelations"] = crelations
|
data["crelations"] = crelations
|
||||||
|
|
||||||
centries, err := dbmodels.EntriesForContents(app, contents)
|
centries, err := dbmodels.EntriesForContents(app, contents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["centries"] = centries
|
data["centries"] = centries
|
||||||
|
|
||||||
@@ -79,13 +77,5 @@ func (p *PersonPage) Setup(router *router.Router[*core.RequestEvent], app core.A
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PersonPage) Get(request *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
func (p *PersonPage) Get(request *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
||||||
var builder strings.Builder
|
return engine.Response200(request, TEMPLATE_PERSON, data)
|
||||||
err := engine.Render(&builder, TEMPLATE_PERSON, data)
|
|
||||||
if err != nil {
|
|
||||||
return Error404(request, engine, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
request.Response.Header().Set("Content-Type", "text/html")
|
|
||||||
request.Response.Write([]byte(builder.String()))
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package pages
|
package pages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
||||||
@@ -90,7 +87,7 @@ func (p *PersonenPage) FilterRequest(app core.App, engine *templating.Engine, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
dbmodels.SortAgentsByName(agents)
|
dbmodels.SortAgentsByName(agents)
|
||||||
data["agents"] = agents
|
data["agents"] = agents
|
||||||
@@ -106,7 +103,7 @@ func (p *PersonenPage) SearchRequest(app core.App, engine *templating.Engine, e
|
|||||||
|
|
||||||
agents, altagents, err := dbmodels.BasicSearchAgents(app, search)
|
agents, altagents, err := dbmodels.BasicSearchAgents(app, search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbmodels.SortAgentsByName(agents)
|
dbmodels.SortAgentsByName(agents)
|
||||||
@@ -129,7 +126,7 @@ func (p *PersonenPage) LetterRequest(app core.App, engine *templating.Engine, e
|
|||||||
|
|
||||||
agents, err := dbmodels.AgentsForLetter(app, letter)
|
agents, err := dbmodels.AgentsForLetter(app, letter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
dbmodels.SortAgentsByName(agents)
|
dbmodels.SortAgentsByName(agents)
|
||||||
data["agents"] = agents
|
data["agents"] = agents
|
||||||
@@ -140,13 +137,8 @@ func (p *PersonenPage) LetterRequest(app core.App, engine *templating.Engine, e
|
|||||||
func (p *PersonenPage) Get(request *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
func (p *PersonenPage) Get(request *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
||||||
err := p.CommonData(request.App, data)
|
err := p.CommonData(request.App, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(request, engine, err)
|
return Error404(request, engine, err, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder strings.Builder
|
return engine.Response200(request, URL_PERSONEN, data)
|
||||||
err = engine.Render(&builder, URL_PERSONEN, data)
|
|
||||||
if err != nil {
|
|
||||||
return Error404(request, engine, err)
|
|
||||||
}
|
|
||||||
return request.HTML(http.StatusOK, builder.String())
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package pages
|
package pages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
||||||
@@ -36,13 +33,13 @@ func (p *ReihePage) Setup(router *router.Router[*core.RequestEvent], app core.Ap
|
|||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
reihe, err := dbmodels.SeriesForId(app, id)
|
reihe, err := dbmodels.SeriesForId(app, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["series"] = reihe
|
data["series"] = reihe
|
||||||
|
|
||||||
rmap, emap, err := dbmodels.EntriesForSeriesses(app, []*dbmodels.Series{reihe})
|
rmap, emap, err := dbmodels.EntriesForSeriesses(app, []*dbmodels.Series{reihe})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
data["relations"] = rmap
|
data["relations"] = rmap
|
||||||
@@ -55,10 +52,5 @@ func (p *ReihePage) Setup(router *router.Router[*core.RequestEvent], app core.Ap
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReihePage) Get(request *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
func (p *ReihePage) Get(request *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
||||||
var builder strings.Builder
|
return engine.Response200(request, TEMPLATE_REIHE, data)
|
||||||
err := engine.Render(&builder, TEMPLATE_REIHE, data)
|
|
||||||
if err != nil {
|
|
||||||
return Error404(request, engine, err)
|
|
||||||
}
|
|
||||||
return request.HTML(http.StatusOK, builder.String())
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package pages
|
package pages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||||
@@ -67,12 +65,12 @@ func (p *ReihenPage) YearRequest(app core.App, engine *templating.Engine, e *cor
|
|||||||
|
|
||||||
y, err := strconv.Atoi(year)
|
y, err := strconv.Atoi(year)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
series, relations, entries, err := dbmodels.SeriesForYear(app, y)
|
series, relations, entries, err := dbmodels.SeriesForYear(app, y)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["entries"] = entries
|
data["entries"] = entries
|
||||||
data["relations"] = relations
|
data["relations"] = relations
|
||||||
@@ -91,7 +89,7 @@ func (p *ReihenPage) LetterRequest(app core.App, engine *templating.Engine, e *c
|
|||||||
|
|
||||||
series, err := dbmodels.SeriesForLetter(app, letter)
|
series, err := dbmodels.SeriesForLetter(app, letter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
// INFO: We sort again since the query can't sort german umlauts correctly
|
// INFO: We sort again since the query can't sort german umlauts correctly
|
||||||
dbmodels.SortSeriessesByTitle(series)
|
dbmodels.SortSeriessesByTitle(series)
|
||||||
@@ -99,7 +97,7 @@ func (p *ReihenPage) LetterRequest(app core.App, engine *templating.Engine, e *c
|
|||||||
|
|
||||||
rmap, bmap, err := dbmodels.EntriesForSeriesses(app, series)
|
rmap, bmap, err := dbmodels.EntriesForSeriesses(app, series)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["entries"] = bmap
|
data["entries"] = bmap
|
||||||
data["relations"] = rmap
|
data["relations"] = rmap
|
||||||
@@ -114,13 +112,13 @@ func (p *ReihenPage) PersonRequest(app core.App, engine *templating.Engine, e *c
|
|||||||
|
|
||||||
agent, err := dbmodels.AgentForId(app, person)
|
agent, err := dbmodels.AgentForId(app, person)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["a"] = agent
|
data["a"] = agent
|
||||||
|
|
||||||
series, relations, entries, err := dbmodels.SeriesForAgent(app, person)
|
series, relations, entries, err := dbmodels.SeriesForAgent(app, person)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
dbmodels.SortSeriessesByTitle(series)
|
dbmodels.SortSeriessesByTitle(series)
|
||||||
data["series"] = series
|
data["series"] = series
|
||||||
@@ -137,13 +135,13 @@ func (p *ReihenPage) PlaceRequest(app core.App, engine *templating.Engine, e *co
|
|||||||
|
|
||||||
pl, err := dbmodels.PlaceForId(app, place)
|
pl, err := dbmodels.PlaceForId(app, place)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["p"] = pl
|
data["p"] = pl
|
||||||
|
|
||||||
series, relations, entries, err := dbmodels.SeriesForPlace(app, place)
|
series, relations, entries, err := dbmodels.SeriesForPlace(app, place)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["series"] = series
|
data["series"] = series
|
||||||
data["relations"] = relations
|
data["relations"] = relations
|
||||||
@@ -158,7 +156,7 @@ func (p *ReihenPage) SearchRequest(app core.App, engine *templating.Engine, e *c
|
|||||||
data[PARAM_SEARCH] = search
|
data[PARAM_SEARCH] = search
|
||||||
series, altseries, err := dbmodels.BasicSearchSeries(app, search)
|
series, altseries, err := dbmodels.BasicSearchSeries(app, search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
dbmodels.SortSeriessesByTitle(series)
|
dbmodels.SortSeriessesByTitle(series)
|
||||||
dbmodels.SortSeriessesByTitle(altseries)
|
dbmodels.SortSeriessesByTitle(altseries)
|
||||||
@@ -167,7 +165,7 @@ func (p *ReihenPage) SearchRequest(app core.App, engine *templating.Engine, e *c
|
|||||||
|
|
||||||
rmap, bmap, err := dbmodels.EntriesForSeriesses(app, series)
|
rmap, bmap, err := dbmodels.EntriesForSeriesses(app, series)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(e, engine, err)
|
return Error404(e, engine, err, data)
|
||||||
}
|
}
|
||||||
data["entries"] = bmap
|
data["entries"] = bmap
|
||||||
data["relations"] = rmap
|
data["relations"] = rmap
|
||||||
@@ -207,13 +205,8 @@ func (p *ReihenPage) CommonData(app core.App, data map[string]interface{}) error
|
|||||||
func (p *ReihenPage) Get(request *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
func (p *ReihenPage) Get(request *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
||||||
err := p.CommonData(request.App, data)
|
err := p.CommonData(request.App, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Error404(request, engine, err)
|
return Error404(request, engine, err, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder strings.Builder
|
return engine.Response200(request, URL_REIHEN, data)
|
||||||
err = engine.Render(&builder, URL_REIHEN, data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return request.HTML(http.StatusOK, builder.String())
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
package templating
|
package templating
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/helpers/functions"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/helpers/functions"
|
||||||
|
"github.com/pocketbase/pocketbase/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -45,6 +49,8 @@ func (e *Engine) funcs() error {
|
|||||||
e.mu.Unlock()
|
e.mu.Unlock()
|
||||||
e.AddFunc("Safe", functions.Safe)
|
e.AddFunc("Safe", functions.Safe)
|
||||||
e.AddFunc("Arr", functions.Arr)
|
e.AddFunc("Arr", functions.Arr)
|
||||||
|
e.AddFunc("HasPrefix", strings.HasPrefix)
|
||||||
|
e.AddFunc("Dict", functions.Dict)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,3 +156,70 @@ func (e *Engine) Render(out io.Writer, path string, ld map[string]interface{}, l
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Engine) Response404(request *core.RequestEvent, err error, data map[string]interface{}) error {
|
||||||
|
if data == nil {
|
||||||
|
data = make(map[string]interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb strings.Builder
|
||||||
|
if err != nil {
|
||||||
|
request.App.Logger().Error("404 error fetching URL!", "error", err, "request", request.Request.URL)
|
||||||
|
data["Error"] = err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
data["page"] = requestData(request)
|
||||||
|
|
||||||
|
err2 := e.Render(&sb, "/errors/404/", data)
|
||||||
|
if err != nil {
|
||||||
|
return e.Response500(request, errors.Join(err, err2), data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return request.HTML(http.StatusNotFound, sb.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Engine) Response500(request *core.RequestEvent, err error, data map[string]interface{}) error {
|
||||||
|
if data == nil {
|
||||||
|
data = make(map[string]interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb strings.Builder
|
||||||
|
if err != nil {
|
||||||
|
request.App.Logger().Error("500 error fetching URL!", "error", err, "request", request.Request.URL)
|
||||||
|
data["Error"] = err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
data["page"] = requestData(request)
|
||||||
|
|
||||||
|
err2 := e.Render(&sb, "/errors/500/", data)
|
||||||
|
if err != nil {
|
||||||
|
return request.String(http.StatusInternalServerError, errors.Join(err, err2).Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return request.HTML(http.StatusInternalServerError, sb.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Engine) Response200(request *core.RequestEvent, path string, ld map[string]interface{}, layout ...string) error {
|
||||||
|
if ld == nil {
|
||||||
|
ld = make(map[string]interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
ld["page"] = requestData(request)
|
||||||
|
|
||||||
|
var builder strings.Builder
|
||||||
|
err := e.Render(&builder, path, ld, layout...)
|
||||||
|
if err != nil {
|
||||||
|
return e.Response500(request, err, ld)
|
||||||
|
}
|
||||||
|
|
||||||
|
return request.HTML(http.StatusOK, builder.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func requestData(request *core.RequestEvent) map[string]interface{} {
|
||||||
|
data := make(map[string]interface{})
|
||||||
|
data["Path"] = request.Request.URL.Path
|
||||||
|
data["Query"] = request.Request.URL.Query()
|
||||||
|
data["Method"] = request.Request.Method
|
||||||
|
data["Host"] = request.Request.Host
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
|||||||
<div class="mt-12">Datenschutz, Impressum.</div>
|
<div class="mt-12 pt-3 border-t">Datenschutz, Impressum.</div>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
{{ $model := . }}
|
||||||
<div
|
<div
|
||||||
class="pb-1.5 border-b border-zinc-300"
|
class="pb-1.5 border-b border-zinc-300"
|
||||||
x-data="{ openeditionmenu: window.location.pathname.startsWith('/edition/')}">
|
x-data="{ openeditionmenu: window.location.pathname.startsWith('/edition/')}">
|
||||||
@@ -8,15 +9,37 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav
|
<nav
|
||||||
class="self-end font-serif font-bold flex flex-row gap-x-6 [&>a]:no-underline
|
class="self-end font-serif font-bold flex flex-row gap-x-4 [&>a]:no-underline
|
||||||
[&>*]:px-1.5 [&>*]:pt-1 [&>*]:-mb-1.5">
|
[&>*]:px-1.5 [&>*]:pt-1 [&>*]:-mb-1.5">
|
||||||
<a href="/reihen/">Reihen</a>
|
<a
|
||||||
<a href="/personen/">Personen</a>
|
href="/reihen/"
|
||||||
<a href="/suche/">Suche</a>
|
{{ if and $model.page (HasPrefix $model.page.Path "/reihe") -}}
|
||||||
|
aria-current="page"
|
||||||
|
{{- end -}}
|
||||||
|
>Reihen</a
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href="/personen/"
|
||||||
|
{{ if and $model.page (HasPrefix $model.page.Path "/person") -}}
|
||||||
|
aria-current="page"
|
||||||
|
{{- end -}}
|
||||||
|
>Personen</a
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href="/suche/"
|
||||||
|
{{ if and $model.page (HasPrefix $model.page.Path "/suche") -}}
|
||||||
|
aria-current="page"
|
||||||
|
{{- end -}}
|
||||||
|
>Suche</a
|
||||||
|
>
|
||||||
<button
|
<button
|
||||||
|
{{ if and $model.page (HasPrefix $model.page.Path "/edition") -}}
|
||||||
|
aria-current="true"
|
||||||
|
{{- end -}}
|
||||||
data-url="/edition/"
|
data-url="/edition/"
|
||||||
class="text-slate-600 hover:text-slate-900 hover:cursor-pointer"
|
class="text-slate-600 hover:text-slate-900 hover:cursor-pointer hover:bg-slate-100
|
||||||
:class="openeditionmenu? 'bg-slate-200' : 'closed'"
|
!pr-2.5"
|
||||||
|
:class="openeditionmenu? 'bg-slate-100' : 'closed'"
|
||||||
@click="openeditionmenu = !openeditionmenu">
|
@click="openeditionmenu = !openeditionmenu">
|
||||||
<i x-show="!openeditionmenu" class="ri-arrow-right-s-fill"></i>
|
<i x-show="!openeditionmenu" class="ri-arrow-right-s-fill"></i>
|
||||||
<i x-show="openeditionmenu" class="ri-arrow-down-s-fill"></i>
|
<i x-show="openeditionmenu" class="ri-arrow-down-s-fill"></i>
|
||||||
@@ -27,17 +50,46 @@
|
|||||||
<nav
|
<nav
|
||||||
:class="openeditionmenu? 'open' : 'closed'"
|
:class="openeditionmenu? 'open' : 'closed'"
|
||||||
x-show="openeditionmenu"
|
x-show="openeditionmenu"
|
||||||
class="submenu w-full flex flex-row justify-end pt-3 gap-x-6 font-bold font-serif
|
class="submenu flex flex-row justify-end pt-3.5 gap-x-4 font-bold font-serif
|
||||||
[&>a]:no-underline [&>*]:-mb-1.5">
|
[&>a]:no-underline [&>*]:-mb-1.5 w-full pr-2.5 [&>*]:px-1.5">
|
||||||
<a href="/edition/einfuehrung/">Einführung</a>
|
<a
|
||||||
<a href="/edition/dokumentation/">Dokumentation</a>
|
href="/edition/einfuehrung/"
|
||||||
<a href="/edition/literatur/">Literatur</a>
|
{{ if and $model.page (HasPrefix $model.page.Path "/edition/einfuehrung") -}}
|
||||||
<a href="/edition/danksagungen/">Danksagungen</a>
|
aria-current="page"
|
||||||
<a href="/edition/kontakt/">Kontakt</a>
|
{{- end -}}
|
||||||
|
>Einführung</a
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href="/edition/dokumentation/"
|
||||||
|
{{ if and $model.page (HasPrefix $model.page.Path "/edition/dokumentation") -}}
|
||||||
|
aria-current="page"
|
||||||
|
{{- end -}}
|
||||||
|
>Dokumentation</a
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href="/edition/literatur/"
|
||||||
|
{{ if and $model.page (HasPrefix $model.page.Path "/edition/literatur") -}}
|
||||||
|
aria-current="page"
|
||||||
|
{{- end -}}
|
||||||
|
>Literatur</a
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href="/edition/danksagungen/"
|
||||||
|
{{ if and $model.page (HasPrefix $model.page.Path "/edition/danksagungen") -}}
|
||||||
|
aria-current="page"
|
||||||
|
{{- end -}}
|
||||||
|
>Danksagungen</a
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href="/edition/kontakt/"
|
||||||
|
{{ if and $model.page (HasPrefix $model.page.Path "/edition/kontakt") -}}
|
||||||
|
aria-current="page"
|
||||||
|
{{- end -}}
|
||||||
|
>Kontakt</a
|
||||||
|
>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { setMenuActive } from "/assets/scripts.js";
|
import { setMenuActive } from "/assets/scripts.js";
|
||||||
setMenuActive();
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -30,8 +30,8 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="w-full" hx-ext="response-targets" hx-boost="true">
|
<body class="w-full" hx-ext="response-targets" hx-boost="true">
|
||||||
<div class="container flex flex-col min-h-screen max-w-(--breakpoint-xl) mx-auto">
|
<div class="container flex flex-col min-h-screen max-w-(--breakpoint-xl) mx-auto px-3 py-3.5">
|
||||||
<header class="px-3 py-2.5" id="header">
|
<header class="" id="header">
|
||||||
{{ block "_menu" . }}
|
{{ block "_menu" . }}
|
||||||
<!-- Default app menu... -->
|
<!-- Default app menu... -->
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
||||||
<main class="">
|
<main class="text-lg">
|
||||||
{{ block "body" . }}
|
{{ block "body" . }}
|
||||||
<!-- Default app body... -->
|
<!-- Default app body... -->
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
13
views/routes/components/_alphabet.gohtml
Normal file
13
views/routes/components/_alphabet.gohtml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{{ $model := . }}
|
||||||
|
|
||||||
|
{{ if $model.letters }}
|
||||||
|
<div class="alphabet">
|
||||||
|
{{ range $id, $r := .letters }}
|
||||||
|
<a
|
||||||
|
href="?letter={{ $r }}"
|
||||||
|
{{ if eq $model.active $r }}aria-current="page"{{ end }}
|
||||||
|
>{{ $r }}</a
|
||||||
|
>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
4
views/routes/errors/500/body.gohtml
Normal file
4
views/routes/errors/500/body.gohtml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<h1>Die Seite konnte nicht gefunden werden!</h1>
|
||||||
|
{{ if .Error }}
|
||||||
|
<p>{{ .Error }}</p>
|
||||||
|
{{ end }}
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
{{ $model := . }}
|
{{ $model := . }}
|
||||||
|
|
||||||
{{ range $count, $letter := $model.letters }}
|
{{ template "_alphabet" Dict "active" .letter "letters" .letters }}
|
||||||
<a href="/personen?letter={{ $letter }}{{ if $model.filter }}&filter={{ $model.filter }}{{ end }}"
|
|
||||||
>{{ $letter }}</a
|
|
||||||
>
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
|
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
{{ $model := . }}
|
{{ $model := . }}
|
||||||
|
|
||||||
{{ if .letters }}
|
{{ template "_alphabet" Dict "active" .letter "letters" .letters }}
|
||||||
<div>
|
|
||||||
{{ range $id, $r := .letters }}
|
|
||||||
<a href="/reihen?letter={{ $r }}">{{ $r }}</a>
|
|
||||||
{{ end }}
|
|
||||||
</div>
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
|
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -27,12 +27,9 @@
|
|||||||
font-variant-caps: small-caps;
|
font-variant-caps: small-caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer base {
|
|
||||||
}
|
|
||||||
|
|
||||||
@layer components {
|
@layer components {
|
||||||
html {
|
html {
|
||||||
font-size: 15.5px;
|
font-size: 16.5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@@ -58,8 +55,16 @@
|
|||||||
@apply ml-14 list-disc;
|
@apply ml-14 list-disc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nav > a {
|
||||||
|
@apply hover:!border-zinc-200;
|
||||||
|
}
|
||||||
|
|
||||||
nav > * {
|
nav > * {
|
||||||
@apply border-b-4 border-transparent hover:!border-zinc-200;
|
@apply border-b-4 border-transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav > button[aria-current="true"] {
|
||||||
|
@apply !bg-slate-200;
|
||||||
}
|
}
|
||||||
|
|
||||||
nav a[aria-current="page"] {
|
nav a[aria-current="page"] {
|
||||||
|
|||||||
Reference in New Issue
Block a user