Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1310b7b243 |
@@ -3,7 +3,6 @@ package resthome
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/layouts"
|
|
||||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/pages"
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/pages"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@ func (h *Handler) home(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
layouts.Render(r.Context(), w, r, pages.Home(pageHeaders))
|
h.r.Render(r.Context(), w, r, pages.Home(pageHeaders))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) page(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) page(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -26,5 +25,5 @@ func (h *Handler) page(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
layouts.Render(r.Context(), w, r, pages.ContentPage(page))
|
h.r.Render(r.Context(), w, r, pages.ContentPage(page))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,22 @@ package resthome
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/page"
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/page"
|
||||||
|
"github.com/a-h/templ"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
src pageService
|
src pageService
|
||||||
|
r renderer
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(mux *http.ServeMux, srv pageService) *Handler {
|
func New(mux *http.ServeMux, renderer renderer, srv pageService) *Handler {
|
||||||
h := &Handler{
|
h := &Handler{
|
||||||
src: srv,
|
src: srv,
|
||||||
|
r: renderer,
|
||||||
}
|
}
|
||||||
|
|
||||||
mux.HandleFunc("GET /{$}", h.home)
|
mux.HandleFunc("GET /{$}", h.home)
|
||||||
@@ -25,3 +29,6 @@ type pageService interface {
|
|||||||
GetPages(ctx context.Context) ([]page.PageHeader, error)
|
GetPages(ctx context.Context) ([]page.PageHeader, error)
|
||||||
GetPage(ctx context.Context, uid string) (page.Page, error)
|
GetPage(ctx context.Context, uid string) (page.Page, error)
|
||||||
}
|
}
|
||||||
|
type renderer interface {
|
||||||
|
Render(ctx context.Context, w io.Writer, r *http.Request, component templ.Component)
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,5 +6,9 @@ func Default() Cfg {
|
|||||||
Concurency: 10,
|
Concurency: 10,
|
||||||
Quality: 80,
|
Quality: 80,
|
||||||
},
|
},
|
||||||
|
Tracking: &UmamiConfig{
|
||||||
|
ScriptSrc: "https://umami.schreifuchs.ch/script.js",
|
||||||
|
WebsiteID: "54d8a379-77d5-4c20-b46d-5c9a6c9e39bd",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ type Cfg struct {
|
|||||||
FileSystem *WebdavConfig `env:", prefix=FILESYSTEM_"`
|
FileSystem *WebdavConfig `env:", prefix=FILESYSTEM_"`
|
||||||
Cache *ValkeyConfig `env:", prefix=CACHE_"`
|
Cache *ValkeyConfig `env:", prefix=CACHE_"`
|
||||||
Image *ImageConfig `env:", prefix=IMAGE_"`
|
Image *ImageConfig `env:", prefix=IMAGE_"`
|
||||||
|
Tracking *UmamiConfig `env:", prefix=TRACKING_"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebdavConfig struct {
|
type WebdavConfig struct {
|
||||||
@@ -36,6 +37,11 @@ type ImageConfig struct {
|
|||||||
Quality int `env:"QUALITY"`
|
Quality int `env:"QUALITY"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UmamiConfig struct {
|
||||||
|
ScriptSrc string `env:"SCRIPT_SRC"`
|
||||||
|
WebsiteID string `env:"WEBSITE_ID"`
|
||||||
|
}
|
||||||
|
|
||||||
func Read(ctx context.Context) (cfg Cfg, err error) {
|
func Read(ctx context.Context) (cfg Cfg, err error) {
|
||||||
cfg = Default()
|
cfg = Default()
|
||||||
err = envconfig.ProcessWith(ctx, &envconfig.Config{
|
err = envconfig.ProcessWith(ctx, &envconfig.Config{
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/filesystem"
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/filesystem"
|
||||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
|
||||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web"
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web"
|
||||||
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/layouts"
|
||||||
"github.com/studio-b12/gowebdav"
|
"github.com/studio-b12/gowebdav"
|
||||||
"github.com/valkey-io/valkey-go"
|
"github.com/valkey-io/valkey-go"
|
||||||
)
|
)
|
||||||
@@ -31,7 +32,6 @@ func (s *Server) RegisterRoutes() (h http.Handler) {
|
|||||||
|
|
||||||
func (s *Server) registerOther() (h http.Handler) {
|
func (s *Server) registerOther() (h http.Handler) {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
webdavClient := gowebdav.NewClient(s.cfg.FileSystem.URL, s.cfg.FileSystem.User, s.cfg.FileSystem.Password)
|
webdavClient := gowebdav.NewClient(s.cfg.FileSystem.URL, s.cfg.FileSystem.User, s.cfg.FileSystem.Password)
|
||||||
if err := webdavClient.Connect(); err != nil {
|
if err := webdavClient.Connect(); err != nil {
|
||||||
slog.Error("could not connect webdavClient", "err", err)
|
slog.Error("could not connect webdavClient", "err", err)
|
||||||
@@ -49,7 +49,9 @@ func (s *Server) registerOther() (h http.Handler) {
|
|||||||
fs = filesystem.NewCachedClient(webdavClient, valkeyClient, 5*time.Hour)
|
fs = filesystem.NewCachedClient(webdavClient, valkeyClient, 5*time.Hour)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = resthome.New(mux, page.New(fs))
|
renderer := layouts.New(s.cfg)
|
||||||
|
|
||||||
|
_ = resthome.New(mux, renderer, page.New(fs))
|
||||||
_ = restimage.New(mux, images.New(fs, s.cfg.Image, valkeyClient))
|
_ = restimage.New(mux, images.New(fs, s.cfg.Image, valkeyClient))
|
||||||
|
|
||||||
mux.Handle("/", http.FileServer(http.FS(web.GetStaticFS())))
|
mux.Handle("/", http.FileServer(http.FS(web.GetStaticFS())))
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package layouts
|
|||||||
import "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/translate"
|
import "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/translate"
|
||||||
import "strings"
|
import "strings"
|
||||||
import "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
|
import "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
|
||||||
|
import "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/config"
|
||||||
|
|
||||||
templ Base(title string) {
|
templ Base(cfg config.Cfg, title string) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang={ translate.Language(ctx) }>
|
<html lang={ translate.Language(ctx) }>
|
||||||
<head>
|
<head>
|
||||||
@@ -15,6 +16,7 @@ templ Base(title string) {
|
|||||||
<link fetchpriority="high" href="/css/output.css" rel="stylesheet"/>
|
<link fetchpriority="high" href="/css/output.css" rel="stylesheet"/>
|
||||||
<script fetchpriority="low" src="/js/htmx.min.js"></script>
|
<script fetchpriority="low" src="/js/htmx.min.js"></script>
|
||||||
<script src="/js/preload.min.js"></script>
|
<script src="/js/preload.min.js"></script>
|
||||||
|
<script src={ cfg.Tracking.ScriptSrc } data-website-id={ cfg.Tracking.WebsiteID }></script>
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-black dark" hx-boost="true" hx-target="main" hx-ext="preload">
|
<body class="bg-black dark" hx-boost="true" hx-target="main" hx-ext="preload">
|
||||||
<header
|
<header
|
||||||
|
|||||||
+13
-2
@@ -7,19 +7,30 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/config"
|
||||||
"github.com/a-h/templ"
|
"github.com/a-h/templ"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Layouts struct {
|
||||||
|
cfg config.Cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(cfg config.Cfg) *Layouts {
|
||||||
|
return &Layouts{
|
||||||
|
cfg: cfg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Render renders a page. If the query paramenter "c" is set
|
// Render renders a page. If the query paramenter "c" is set
|
||||||
// the component gets rendered without the layout
|
// the component gets rendered without the layout
|
||||||
func Render(ctx context.Context, w io.Writer, r *http.Request, component templ.Component) {
|
func (l *Layouts) Render(ctx context.Context, w io.Writer, r *http.Request, component templ.Component) {
|
||||||
withLayout := !r.URL.Query().Has("c")
|
withLayout := !r.URL.Query().Has("c")
|
||||||
fmt.Println("layout: ", withLayout)
|
fmt.Println("layout: ", withLayout)
|
||||||
|
|
||||||
slog.Debug("HX-Request", "value", r.Header.Get("HX-Request"))
|
slog.Debug("HX-Request", "value", r.Header.Get("HX-Request"))
|
||||||
if r.Header.Get("HX-Request") != "true" {
|
if r.Header.Get("HX-Request") != "true" {
|
||||||
ctx = templ.WithChildren(ctx, component)
|
ctx = templ.WithChildren(ctx, component)
|
||||||
component = Base("Schreifuchs")
|
component = Base(l.cfg, "Schreifuchs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := component.Render(ctx, w); err != nil {
|
if err := component.Render(ctx, w); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user