mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-28 16:45:32 +00:00
Basic Bilder Integration
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@ bin/
|
||||
data_git/
|
||||
cache_geo/
|
||||
cache_gnd/
|
||||
data_bilder/
|
||||
config.json
|
||||
out.log
|
||||
kgpz_web
|
||||
|
||||
20
app/kgpz.go
20
app/kgpz.go
@@ -1,6 +1,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/controllers"
|
||||
@@ -11,15 +12,14 @@ import (
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/xmlmodels"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/etag"
|
||||
)
|
||||
|
||||
// INFO: this holds all the stuff specific to the KGPZ application
|
||||
// It implements Map(*fiber.App) error, so it can be used as a MuxProvider
|
||||
// It also implements Funcs() map[string]interface{} to map funcs to a template engine
|
||||
// It is meant to be constructed once and then used as a singleton.
|
||||
|
||||
const (
|
||||
ASSETS_URL_PREFIX = "/assets"
|
||||
IMG_PREFIX = "/img/"
|
||||
|
||||
EDITION_URL = "/edition/"
|
||||
PRIVACY_URL = "/datenschutz/"
|
||||
@@ -66,6 +66,20 @@ func NewKGPZ(config *providers.ConfigProvider) (*KGPZ, error) {
|
||||
return kgpz, nil
|
||||
}
|
||||
|
||||
func (k *KGPZ) Pre(srv *fiber.App) error {
|
||||
|
||||
// Check if folder exists and if yes, serve image files from i
|
||||
if _, err := os.Stat(k.Config.Config.ImgPath); err == nil {
|
||||
fs := os.DirFS(k.Config.Config.ImgPath)
|
||||
srv.Use(IMG_PREFIX, etag.New())
|
||||
srv.Use(IMG_PREFIX, helpers.StaticHandler(&fs))
|
||||
} else {
|
||||
logging.Info("Image folder not found. Skipping image serving.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *KGPZ) Init() error {
|
||||
if gp, err := providers.NewGitProvider(
|
||||
k.Config.Config.GitURL,
|
||||
|
||||
@@ -56,6 +56,7 @@ func Init(cfg *providers.ConfigProvider) (*App, error) {
|
||||
server := server.Create(cfg, engine)
|
||||
|
||||
server.AddPre(engine)
|
||||
server.AddPre(kgpz)
|
||||
server.AddMux(kgpz)
|
||||
|
||||
return &App{KGPZ: kgpz, Server: server, Config: cfg, Engine: engine}, nil
|
||||
|
||||
@@ -17,6 +17,7 @@ const (
|
||||
DEFAULT_GIT_DIR = "data_git"
|
||||
DEFAULT_GND_DIR = "cache_gnd"
|
||||
DEFAULT_GEO_DIR = "cache_geo"
|
||||
DEFAULT_IMG_DIR = "data_bilder"
|
||||
|
||||
DEFAULT_PORT = "8080"
|
||||
DEFAULT_ADDR = "localhost"
|
||||
@@ -37,6 +38,7 @@ type Config struct {
|
||||
FolderPath string `json:"folder_path" envconfig:"FOLDER_PATH"`
|
||||
GNDPath string `json:"gnd_path" envconfig:"GND_PATH"`
|
||||
GeoPath string `json:"geo_path" envconfig:"GEO_PATH"`
|
||||
ImgPath string `json:"img_path" envconfig:"IMG_PATH"`
|
||||
WebHookEndpoint string `json:"webhook_endpoint" envconfig:"WEBHOOK_ENDPOINT"`
|
||||
WebHookSecret string `json:"webhook_secret" envconfig:"WEBHOOK_SECRET"`
|
||||
Debug bool `json:"debug" envconfig:"DEBUG"`
|
||||
@@ -110,6 +112,10 @@ func readDefaults(cfg *Config) *Config {
|
||||
cfg.Port = DEFAULT_PORT
|
||||
}
|
||||
|
||||
if strings.TrimSpace(cfg.ImgPath) == "" {
|
||||
cfg.ImgPath = DEFAULT_IMG_DIR
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# Inh. Verz.
|
||||
- 1765/28,113 Klopstock ist doppelt verlinkt, als Anzeige und als Auszug, außerdem ist nochmals die Kategorie Gedichte und litererische Kurztexte vergeben
|
||||
|
||||
34
scripts/normalizefns.py
Normal file
34
scripts/normalizefns.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
# Path to the directory containing the files
|
||||
directory = "data_bilder/"
|
||||
|
||||
# Regex pattern to match filenames with segments separated by '-'
|
||||
pattern = re.compile(r"([0-9]+[a-zA-Z]*|[a-zA-Z]*[0-9]*)-([0-9]+[a-zA-Z]*|[a-zA-Z]*[0-9]*)-([0-9]+[a-zA-Z]*|[a-zA-Z]*[0-9]*)\.jpg")
|
||||
|
||||
def normalize_segment(segment):
|
||||
# Remove leading zeros from the numeric part of the segment
|
||||
return re.sub(r'^0+(\d+)', r'\1', segment)
|
||||
|
||||
def normalize_filename(filename):
|
||||
match = pattern.match(filename)
|
||||
if not match:
|
||||
return filename # Skip files that don't match the pattern
|
||||
|
||||
# Normalize each segment
|
||||
normalized_segments = [normalize_segment(segment) for segment in match.groups()]
|
||||
return "-".join(normalized_segments) + ".jpg"
|
||||
|
||||
def normalize_filenames_in_directory(directory):
|
||||
for filename in os.listdir(directory):
|
||||
if filename.endswith(".jpg"):
|
||||
old_path = os.path.join(directory, filename)
|
||||
normalized_name = normalize_filename(filename)
|
||||
new_path = os.path.join(directory, normalized_name)
|
||||
if old_path != new_path:
|
||||
print(f"Renaming: {old_path} -> {new_path}")
|
||||
os.rename(old_path, new_path)
|
||||
|
||||
# Normalize the filenames
|
||||
normalize_filenames_in_directory(directory)
|
||||
@@ -30,18 +30,45 @@
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{- if $piece.Title -}}
|
||||
<div class="">{{- index $piece.Title 0 -}}</div>
|
||||
{{- else if $piece.Incipit -}}
|
||||
<div class="">{{- index $piece.Incipit 0 -}}</div>
|
||||
{{- end -}}
|
||||
|
||||
{{- if $piece.PlaceRefs -}}
|
||||
{{ $place := GetPlace (index $piece.PlaceRefs 0).Ref }}
|
||||
{{- if gt (len $place.Names) 0 -}}
|
||||
<div class="">{{- index $place.Names 0 -}}</div>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Kategorie Werk -->
|
||||
{{ if $piece.WorkRefs }}
|
||||
{{ range $workref := $piece.WorkRefs }}
|
||||
{{ $work := GetWork $workref.Ref }}
|
||||
<!-- What we do depends on the category -->
|
||||
{{- $kat := $workref.Category }}
|
||||
{{- if not $kat }}
|
||||
{{- $kat = "rezension" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $category := GetCategory $kat -}}
|
||||
{{- if gt (len $category.Names) 0 -}}
|
||||
<div class="category inline-block">{{- index $category.Names 0 -}}</div>
|
||||
{{- end -}}
|
||||
|
||||
{{- if $work.PreferredTitle -}}
|
||||
<div class="category inline-block">{{- index $work.PreferredTitle -}}</div>
|
||||
<div class="">{{- $work.PreferredTitle -}}</div>
|
||||
{{- else if $work.Citation.Title -}}
|
||||
<div class="category inline-block">{{- index $work.Citation.Title -}}</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
<div class="">{{- $work.Citation.Title -}}</div>
|
||||
{{- else -}}
|
||||
<div class="">{{- $work.Citation.Chardata -}}</div>
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
</div>
|
||||
|
||||
<!-- Notizen -->
|
||||
|
||||
Reference in New Issue
Block a user