feat: title on pages
This commit is contained in:
+26
-15
@@ -1,24 +1,35 @@
|
||||
package layouts
|
||||
|
||||
import "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/translate"
|
||||
import "strings"
|
||||
import "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
|
||||
import "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/config"
|
||||
import (
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/translate"
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/config"
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
|
||||
"strings"
|
||||
)
|
||||
|
||||
templ Head(cfg config.Cfg, title string) {
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>{ title }</title>
|
||||
<link rel="icon" type="image/png" href="/favicon.png"/>
|
||||
<link fetchpriority="high" href="/css/output.css" rel="stylesheet"/>
|
||||
<script src="/js/htmx.min.js"></script>
|
||||
<script src="/js/head-support.min.js"></script>
|
||||
<script src="/js/preload.min.js"></script>
|
||||
<script src={ cfg.Tracking.ScriptSrc } data-website-id={ cfg.Tracking.WebsiteID }></script>
|
||||
for _, h := range templer.GetHeader(ctx) {
|
||||
@templ.Raw(h)
|
||||
}
|
||||
</head>
|
||||
{ children... }
|
||||
}
|
||||
|
||||
templ Base(cfg config.Cfg, title string) {
|
||||
<!DOCTYPE html>
|
||||
<html lang={ translate.Language(ctx) }>
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>{ title }</title>
|
||||
<link rel="icon" type="image/png" href="/favicon.png"/>
|
||||
<link fetchpriority="high" href="/css/output.css" rel="stylesheet"/>
|
||||
<script fetchpriority="low" src="/js/htmx.min.js"></script>
|
||||
<script src="/js/preload.min.js"></script>
|
||||
<script src={ cfg.Tracking.ScriptSrc } data-website-id={ cfg.Tracking.WebsiteID }></script>
|
||||
</head>
|
||||
<body class="bg-black dark" hx-boost="true" hx-target="main" hx-ext="preload">
|
||||
@Head(cfg, title)
|
||||
<body class="bg-black dark" hx-boost="true" hx-target="main" hx-ext="head-support,preload">
|
||||
<header
|
||||
class="fixed z-50 mix-blend-difference p-1 w-full flex justify-between items-start"
|
||||
>
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/config"
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
@@ -27,10 +28,15 @@ func (l *Layouts) Render(ctx context.Context, w io.Writer, r *http.Request, comp
|
||||
withLayout := !r.URL.Query().Has("c")
|
||||
fmt.Println("layout: ", withLayout)
|
||||
|
||||
title := templer.GetTitle(ctx, "Schreifuchs")
|
||||
|
||||
slog.Debug("HX-Request", "value", r.Header.Get("HX-Request"))
|
||||
if r.Header.Get("HX-Request") != "true" {
|
||||
ctx = templ.WithChildren(ctx, component)
|
||||
component = Base(l.cfg, "Schreifuchs")
|
||||
component = Base(l.cfg, title)
|
||||
} else {
|
||||
ctx = templ.WithChildren(ctx, component)
|
||||
component = Head(l.cfg, title)
|
||||
}
|
||||
|
||||
if err := component.Render(ctx, w); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user