Static files handling

This commit is contained in:
Simon Martens
2025-02-11 21:35:40 +01:00
parent 0c8cd35577
commit 71dcf9bf5e
9 changed files with 50 additions and 107 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/mattn/go-sqlite3" "github.com/mattn/go-sqlite3"
"github.com/pocketbase/dbx" "github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase" "github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core" "github.com/pocketbase/pocketbase/core"
) )
@@ -120,6 +121,8 @@ func (app *App) Serve() error {
}) })
app.PB.OnServe().BindFunc(func(e *core.ServeEvent) error { app.PB.OnServe().BindFunc(func(e *core.ServeEvent) error {
e.Router.GET("/assets/{path...}", apis.Static(views.StaticFS, true))
for _, page := range app.Pages { for _, page := range app.Pages {
page.Setup(e.Router, e.App, engine) page.Setup(e.Router, e.App, engine)
} }

View File

@@ -40,6 +40,8 @@ func init() {
panic(err) panic(err)
} }
placesmap := datatypes.MakeMap(places, func(record *dbmodels.Place) string { return record.Name() })
series, err := seed.RecordsFromReihentitel(app, adb.Reihen) series, err := seed.RecordsFromReihentitel(app, adb.Reihen)
if err == nil { if err == nil {
for _, record := range series { for _, record := range series {
@@ -51,7 +53,7 @@ func init() {
panic(err) panic(err)
} }
entries, err := seed.RecordsFromBände(app, *adb) entries, err := seed.RecordsFromBände(app, *adb, placesmap)
if err == nil { if err == nil {
for _, record := range entries { for _, record := range entries {
if err = app.Save(record); err != nil { if err = app.Save(record); err != nil {
@@ -62,7 +64,9 @@ func init() {
panic(err) panic(err)
} }
if records, err := seed.ItemsFromBändeAndBIBLIO(app, adb.Bände, adb.BIBLIO); err == nil { entriesmap := datatypes.MakeMap(entries, func(record *dbmodels.Entry) string { return record.MusenalmID() })
if records, err := seed.ItemsFromBändeAndBIBLIO(app, adb.Bände, adb.BIBLIO, entriesmap); err == nil {
for _, record := range records { for _, record := range records {
if err = app.Save(record); err != nil { if err = app.Save(record); err != nil {
app.Logger().Error("Error saving record", "error", err, "record", record) app.Logger().Error("Error saving record", "error", err, "record", record)
@@ -72,8 +76,6 @@ func init() {
panic(err) panic(err)
} }
entriesmap := datatypes.MakeMap(entries, func(record *dbmodels.Entry) string { return record.MusenalmID() })
contents, err := seed.RecordsFromInhalte(app, adb.Inhalte, entriesmap) contents, err := seed.RecordsFromInhalte(app, adb.Inhalte, entriesmap)
if err == nil { if err == nil {
for _, record := range contents { for _, record := range contents {

View File

@@ -15,6 +15,7 @@ import (
func RecordsFromBände( func RecordsFromBände(
app core.App, app core.App,
adb xmlmodels.AccessDB, adb xmlmodels.AccessDB,
places map[string]*dbmodels.Place,
) ([]*dbmodels.Entry, error) { ) ([]*dbmodels.Entry, error) {
collection, err := app.FindCollectionByNameOrId(dbmodels.ENTRIES_TABLE) collection, err := app.FindCollectionByNameOrId(dbmodels.ENTRIES_TABLE)
records := make([]*dbmodels.Entry, 0, len(adb.Bände.Bände)) records := make([]*dbmodels.Entry, 0, len(adb.Bände.Bände))
@@ -74,7 +75,7 @@ func RecordsFromBände(
handlePreferredTitleEntry(record, band, rmap, relmap) handlePreferredTitleEntry(record, band, rmap, relmap)
handleDeprecated(record, band) handleDeprecated(record, band)
handleOrte(record, band, omap, app, ocoll) handleOrte(record, band, omap, app, ocoll, places)
records = append(records, record) records = append(records, record)
} }
@@ -122,6 +123,7 @@ func handleOrte(
orte map[string]xmlmodels.Ort, orte map[string]xmlmodels.Ort,
app core.App, app core.App,
ocollection *core.Collection, ocollection *core.Collection,
places map[string]*dbmodels.Place,
) { ) {
for _, v := range band.Orte { for _, v := range band.Orte {
o, ok := orte[v.Value] o, ok := orte[v.Value]
@@ -133,8 +135,8 @@ func handleOrte(
e = true e = true
} }
ort, err := app.FindFirstRecordByData(dbmodels.PLACES_TABLE, dbmodels.PLACES_NAME_FIELD, n) ort, ok := places[n]
if err == nil { if ok {
before := record.Places() before := record.Places()
record.SetPlaces(append(before, ort.Id)) record.SetPlaces(append(before, ort.Id))
} else { } else {

View File

@@ -16,6 +16,7 @@ func ItemsFromBändeAndBIBLIO(
app core.App, app core.App,
entries xmlmodels.Bände, entries xmlmodels.Bände,
biblio map[int]xmlmodels.BIBLIOEintrag, biblio map[int]xmlmodels.BIBLIOEintrag,
entriesmap map[string]*dbmodels.Entry,
) ([]*dbmodels.Item, error) { ) ([]*dbmodels.Item, error) {
collection, err := app.FindCollectionByNameOrId(dbmodels.ITEMS_TABLE) collection, err := app.FindCollectionByNameOrId(dbmodels.ITEMS_TABLE)
records := make([]*dbmodels.Item, 0, len(entries.Bände)) records := make([]*dbmodels.Item, 0, len(entries.Bände))
@@ -27,9 +28,9 @@ func ItemsFromBändeAndBIBLIO(
for i := 0; i < len(entries.Bände); i++ { for i := 0; i < len(entries.Bände); i++ {
band := entries.Bände[i] band := entries.Bände[i]
banddb, err := app.FindFirstRecordByData(dbmodels.ENTRIES_TABLE, dbmodels.MUSENALMID_FIELD, band.ID) banddb, ok := entriesmap[band.ID]
if err != nil { if !ok {
app.Logger().Error("Error finding record", "error", err, "collection", dbmodels.ENTRIES_TABLE, "field", dbmodels.MUSENALMID_FIELD, "value", band.ID) app.Logger().Error("Error finding entry", "error", err, "entry", band.ID)
continue continue
} }

View File

@@ -2,6 +2,7 @@ package pages
import ( import (
"net/http" "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"
@@ -33,7 +34,12 @@ func (p *IndexPage) Down(app core.App) error {
func (p *IndexPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error { func (p *IndexPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
router.GET("/{$}", func(e *core.RequestEvent) error { router.GET("/{$}", func(e *core.RequestEvent) error {
return e.String(http.StatusOK, "Hello, World!") var builder strings.Builder
err := engine.Render(&builder, "/", nil)
if err != nil {
return err
}
return e.HTML(http.StatusOK, builder.String())
}) })
return nil return nil
} }

23
scratchpad.md Normal file
View File

@@ -0,0 +1,23 @@
Vorteile PocketBase
- Log-Datenbank
- User-Management
- Kurze Übernahme neuer Features
- Backup
- Email
- Hooks
Nachteile PocketBase
- Alles muss über Hooks gemacht werden
- Eigener HTTP-Server
- Eigene Cache-Implemtation
- Eigene Cookies on Auth
- Eine weitere Abhängigkeit
Für einen Umzug:
Alle PB-Abfragen die Record benutzen, nach sql-Abfragen umwandeln.
Eigene DB-Connection
Modelle umwandeln (zzt RecordProxy)

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +1 @@
<div class="mt-8"> MALM
<h1 class="text-2xl">Königsberger gelehrte und politische Zeitungen</h1>
</div>

View File

@@ -1,92 +0,0 @@
{{ $a := . }}
{{ if and $a (ne (len $a.Names) 0) }}
<div class="pb-4">
{{ index $a.Names 0 }}
<div>
{{ $gnd := GetGND $a.GND }}
{{ if (ne $gnd nil) }}
{{- if ne (len $gnd.DateOfBirth) 0 -}}
<i class="ri-asterisk text-xs relative bottom-0.5"></i>&nbsp;
{{- HRDateShort (index $gnd.DateOfBirth 0) -}}
{{- end -}}
{{- if ne (len $gnd.DateOfDeath) 0 }}
&emsp;<i class="ri-cross-fill text-xs relative bottom-0.5"></i
>&nbsp;{{ HRDateShort (index $gnd.DateOfDeath 0) }}
{{ end }}
{{- if ne (len $gnd.ProfessionOrOccupation) 0 -}}
<div>
{{- (index $gnd.ProfessionOrOccupation 0).Label -}}
{{- if gt (len $gnd.ProfessionOrOccupation) 1 -}}
,
{{ (index $gnd.ProfessionOrOccupation 1).Label -}}
{{ end -}}
{{- if gt (len $gnd.ProfessionOrOccupation) 2 -}}
,
{{ (index $gnd.ProfessionOrOccupation 2).Label -}}
{{ end -}}
</div>
{{ end }}
{{ end }}
<div class="flex gap-x-2 flex-row">
<a href="/akteure/{{ $a.ID }}" class="no-underline!"><i class="ri-links-line"></i></a>
{{- if ne $gnd nil -}}
<a href="{{ $a.GND }}" target="_blank">GND &rarr;</a>
{{- if ne (len $gnd.Wikipedia) 0 -}}
<a href="{{ (index $gnd.Wikipedia 0).Label }}" target="_blank">WIKI &rarr;</a>
{{ end -}}
{{ end }}
</div>
</div>
{{ $works := LookupWorks $a }}
{{- if ne (len $works) 0 -}}
<div>
{{ range $_, $w := $works }}
{{- if ne (len $w.Item.Citation.InnerXML ) 0 -}}
<script type="application/xml" xslt-template="transform-citation" xslt-onload>
<xml>
{{- Safe $w.Item.Citation.InnerXML -}}
</xml>
</script>
{{- end -}}
{{ range $_, $url := $w.Item.URLs }}
<div>
<a href="{{ $url.Address }}" target="_blank">{{ $url.Chardata }}</a>
</div>
{{ end }}
{{ $pieces := LookupPieces $w.Item }}
{{ if len $pieces }}
<div>
{{ range $_, $p := $pieces }}
{{- range $_, $i := $p.Item.IssueRefs -}}
<div>
<a href="/{{ $i.When }}/{{ $i.Nr }}">{{ $i.Nr }}/{{ $i.When }}</a>
</div>
{{- end -}}
{{ end }}
</div>
{{ end }}
{{ end }}
</div>
{{ end }}
{{ $pieces := LookupPieces $a }}
{{- if ne (len $pieces) 0 -}}
<div>
{{ range $_, $p := $pieces }}
{{- range $_, $i := $p.Item.IssueRefs -}}
<div>
<a href="/{{ $i.When }}/{{ $i.Nr }}">{{ $i.Nr }}/{{ $i.When }}</a>
</div>
{{- end -}}
{{ end }}
</div>
{{ end }}
</div>
{{ end }}