feat(posts): refactor to templ and add custom templating
d2b52aa1
28 file(s) · +2010 −304
| 31 | 31 | fi |
|
| 32 | 32 | done |
|
| 33 | 33 | ||
| 34 | + | - name: templ generated files are up to date |
|
| 35 | + | working-directory: apps/posts |
|
| 36 | + | run: | |
|
| 37 | + | set -euo pipefail |
|
| 38 | + | go generate ./... |
|
| 39 | + | if [ -n "$(git status --porcelain -- .)" ]; then |
|
| 40 | + | git status --porcelain -- . |
|
| 41 | + | echo "::error::run 'go generate ./...' in apps/posts and commit the result" |
|
| 42 | + | exit 1 |
|
| 43 | + | fi |
|
| 44 | + | ||
| 34 | 45 | - name: go vet all modules |
|
| 35 | 46 | run: | |
|
| 36 | 47 | set -euo pipefail |
| 51 | 51 | Without `name` a random ID is used. Returns 201 with JSON `url`, |
|
| 52 | 52 | `filename`, `original_name`, `content_type`, `size`. |
|
| 53 | 53 | ||
| 54 | + | - Public pages are [templ](https://templ.guide) components (`*.templ`). After |
|
| 55 | + | editing them run `go generate ./...` and commit the generated `*_templ.go`. |
|
| 56 | + | - `/admin/templates` lets you replace the body (inside `<main>`) of the home, |
|
| 57 | + | post, page and posts list views with a Go `html/template`. The editor starts |
|
| 58 | + | from `starters/*.html`, which must stay in sync with the templ defaults |
|
| 59 | + | (`TestStartersMatchTemplDefaults` checks this). Templates are validated |
|
| 60 | + | against sample data on save; if one fails at request time the default is |
|
| 61 | + | rendered instead. |
|
| 62 | + | ||
| 54 | 63 | See `.env.example`. |
| 11 | 11 | "github.com/stevedylandev/andromeda/pkg/auth" |
|
| 12 | 12 | ) |
|
| 13 | 13 | ||
| 14 | - | //go:embed templates/*.html static/* |
|
| 14 | + | //go:embed templates/*.html static/* starters/*.html |
|
| 15 | 15 | var appFS embed.FS |
|
| 16 | 16 | ||
| 17 | 17 | type App struct { |
|
| 25 | 25 | Storage poststorage.Backend |
|
| 26 | 26 | SiteURL string |
|
| 27 | 27 | APIKey string |
|
| 28 | + | Overrides *overrides |
|
| 28 | 29 | } |
|
| 29 | 30 | ||
| 30 | 31 | type Post struct { |
|
| 230 | 231 | Error string |
|
| 231 | 232 | } |
|
| 232 | 233 | ||
| 233 | - | type indexPageData struct { |
|
| 234 | - | BlogTitle string |
|
| 235 | - | BlogDescription string |
|
| 236 | - | IntroHTML template.HTML |
|
| 237 | - | Posts []Post |
|
| 238 | - | NavLinks []NavLink |
|
| 239 | - | FaviconURL string |
|
| 240 | - | OGImageURL string |
|
| 241 | - | SiteURL string |
|
| 242 | - | HeaderHTML template.HTML |
|
| 243 | - | FooterHTML template.HTML |
|
| 244 | - | } |
|
| 245 | - | ||
| 246 | - | type postPageData struct { |
|
| 247 | - | BlogTitle string |
|
| 248 | - | NavLinks []NavLink |
|
| 249 | - | Post Post |
|
| 250 | - | RenderedContent template.HTML |
|
| 251 | - | FaviconURL string |
|
| 252 | - | OGImageURL string |
|
| 253 | - | SiteURL string |
|
| 254 | - | HeaderHTML template.HTML |
|
| 255 | - | FooterHTML template.HTML |
|
| 256 | - | Weather Weather |
|
| 257 | - | } |
|
| 258 | - | ||
| 259 | - | type pagePageData struct { |
|
| 260 | - | BlogTitle string |
|
| 261 | - | NavLinks []NavLink |
|
| 262 | - | Page Page |
|
| 263 | - | RenderedContent template.HTML |
|
| 264 | - | FaviconURL string |
|
| 265 | - | OGImageURL string |
|
| 266 | - | SiteURL string |
|
| 267 | - | HeaderHTML template.HTML |
|
| 268 | - | FooterHTML template.HTML |
|
| 269 | - | } |
|
| 270 | - | ||
| 271 | - | type postsListPageData struct { |
|
| 272 | - | BlogTitle string |
|
| 273 | - | NavLinks []NavLink |
|
| 274 | - | Posts []Post |
|
| 275 | - | FaviconURL string |
|
| 276 | - | OGImageURL string |
|
| 277 | - | SiteURL string |
|
| 278 | - | HeaderHTML template.HTML |
|
| 279 | - | FooterHTML template.HTML |
|
| 280 | - | } |
|
| 281 | - | ||
| 282 | 234 | type adminIndexPageData struct { |
|
| 283 | 235 | Posts []Post |
|
| 284 | 236 | } |
|
| 317 | 269 | SiteURL string |
|
| 318 | 270 | Error string |
|
| 319 | 271 | Success bool |
|
| 272 | + | } |
|
| 273 | + | ||
| 274 | + | type adminTemplatesPageData struct { |
|
| 275 | + | Kinds []struct{ Kind, Label string } |
|
| 276 | + | Kind string |
|
| 277 | + | Template string |
|
| 278 | + | Custom bool |
|
| 279 | + | Error string |
|
| 280 | + | Success bool |
|
| 320 | 281 | } |
|
| 321 | 282 | ||
| 322 | 283 | type adminImportPageData struct { |
|
| 12 | 12 | ) |
|
| 13 | 13 | ||
| 14 | 14 | require ( |
|
| 15 | + | github.com/a-h/templ v0.3.1001 // indirect |
|
| 15 | 16 | github.com/aws/aws-sdk-go-v2 v1.41.7 // indirect |
|
| 16 | 17 | github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10 // indirect |
|
| 17 | 18 | github.com/aws/aws-sdk-go-v2/credentials v1.19.16 // indirect |
|
| 31 | 32 | github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect |
|
| 32 | 33 | golang.org/x/crypto v0.39.0 // indirect |
|
| 33 | 34 | golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect |
|
| 34 | - | golang.org/x/sys v0.33.0 // indirect |
|
| 35 | + | golang.org/x/sys v0.34.0 // indirect |
|
| 35 | 36 | modernc.org/libc v1.65.7 // indirect |
|
| 36 | 37 | modernc.org/mathutil v1.7.1 // indirect |
|
| 37 | 38 | modernc.org/memory v1.11.0 // indirect |
|
| 1 | + | github.com/a-h/templ v0.3.1001 h1:yHDTgexACdJttyiyamcTHXr2QkIeVF1MukLy44EAhMY= |
|
| 2 | + | github.com/a-h/templ v0.3.1001/go.mod h1:oCZcnKRf5jjsGpf2yELzQfodLphd2mwecwG4Crk5HBo= |
|
| 1 | 3 | github.com/aws/aws-sdk-go-v2 v1.41.7 h1:DWpAJt66FmnnaRIOT/8ASTucrvuDPZASqhhLey6tLY8= |
|
| 2 | 4 | github.com/aws/aws-sdk-go-v2 v1.41.7/go.mod h1:4LAfZOPHNVNQEckOACQx60Y8pSRjIkNZQz1w92xpMJc= |
|
| 3 | 5 | github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10 h1:gx1AwW1Iyk9Z9dD9F4akX5gnN3QZwUB20GGKH/I+Rho= |
|
| 42 | 44 | golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:S9Xr4PYopiDyqSyp5NjCrhFrqg6A5zA2E/iPHPhqnS8= |
|
| 43 | 45 | golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= |
|
| 44 | 46 | golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= |
|
| 47 | + | golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg= |
|
| 45 | 48 | golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= |
|
| 46 | 49 | golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= |
|
| 50 | + | golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= |
|
| 47 | 51 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
|
| 48 | 52 | golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= |
|
| 49 | 53 | golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= |
|
| 54 | + | golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= |
|
| 55 | + | golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= |
|
| 50 | 56 | golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= |
|
| 51 | 57 | golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= |
|
| 58 | + | golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0= |
|
| 52 | 59 | modernc.org/cc/v4 v4.26.1 h1:+X5NtzVBn0KgsBCBe+xkDC7twLb/jNVj9FPgiwSQO3s= |
|
| 53 | 60 | modernc.org/cc/v4 v4.26.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0= |
|
| 54 | 61 | modernc.org/ccgo/v4 v4.28.0 h1:rjznn6WWehKq7dG4JtLRKxb52Ecv8OUGah8+Z/SfpNU= |
|
| 573 | 573 | } |
|
| 574 | 574 | ||
| 575 | 575 | var _ = url.QueryEscape |
|
| 576 | + | ||
| 577 | + | func (a *App) adminGetTemplates(w http.ResponseWriter, r *http.Request) { |
|
| 578 | + | kind := r.URL.Query().Get("t") |
|
| 579 | + | if !isTemplateKind(kind) { |
|
| 580 | + | kind = "index" |
|
| 581 | + | } |
|
| 582 | + | src, _ := getSetting(a.DB, templateSettingKey(kind)) |
|
| 583 | + | a.renderTemplatesForm(w, http.StatusOK, kind, src, "", r.URL.Query().Get("success") == "true") |
|
| 584 | + | } |
|
| 585 | + | ||
| 586 | + | func (a *App) adminPostTemplate(w http.ResponseWriter, r *http.Request) { |
|
| 587 | + | kind := r.PathValue("kind") |
|
| 588 | + | if !isTemplateKind(kind) { |
|
| 589 | + | http.Error(w, "Not found", http.StatusNotFound) |
|
| 590 | + | return |
|
| 591 | + | } |
|
| 592 | + | if err := r.ParseForm(); err != nil { |
|
| 593 | + | http.Redirect(w, r, "/admin/templates?t="+kind, http.StatusSeeOther) |
|
| 594 | + | return |
|
| 595 | + | } |
|
| 596 | + | src := r.FormValue("template") |
|
| 597 | + | if strings.TrimSpace(src) == "" { |
|
| 598 | + | _ = setSetting(a.DB, templateSettingKey(kind), "") |
|
| 599 | + | a.Overrides.set(kind, nil) |
|
| 600 | + | http.Redirect(w, r, "/admin/templates?t="+kind+"&success=true", http.StatusSeeOther) |
|
| 601 | + | return |
|
| 602 | + | } |
|
| 603 | + | t, err := validateOverride(kind, src) |
|
| 604 | + | if err != nil { |
|
| 605 | + | a.renderTemplatesForm(w, http.StatusUnprocessableEntity, kind, src, err.Error(), false) |
|
| 606 | + | return |
|
| 607 | + | } |
|
| 608 | + | if err := setSetting(a.DB, templateSettingKey(kind), src); err != nil { |
|
| 609 | + | a.renderTemplatesForm(w, http.StatusInternalServerError, kind, src, "failed to save template", false) |
|
| 610 | + | return |
|
| 611 | + | } |
|
| 612 | + | a.Overrides.set(kind, t) |
|
| 613 | + | http.Redirect(w, r, "/admin/templates?t="+kind+"&success=true", http.StatusSeeOther) |
|
| 614 | + | } |
|
| 615 | + | ||
| 616 | + | // renderTemplatesForm shows the editor for kind. An empty src means no custom |
|
| 617 | + | // template is set, so the textarea is prefilled with the starter. |
|
| 618 | + | func (a *App) renderTemplatesForm(w http.ResponseWriter, status int, kind, src, errMsg string, success bool) { |
|
| 619 | + | custom := src != "" |
|
| 620 | + | if !custom { |
|
| 621 | + | starter, _ := appFS.ReadFile("starters/" + kind + ".html") |
|
| 622 | + | src = string(starter) |
|
| 623 | + | } |
|
| 624 | + | w.Header().Set("Content-Type", "text/html; charset=utf-8") |
|
| 625 | + | w.WriteHeader(status) |
|
| 626 | + | a.renderPage(w, "admin_templates.html", adminTemplatesPageData{ |
|
| 627 | + | Kinds: templateKinds, Kind: kind, Template: src, Custom: custom, |
|
| 628 | + | Error: errMsg, Success: success, |
|
| 629 | + | }) |
|
| 630 | + | } |
| 1 | 1 | package main |
|
| 2 | 2 | ||
| 3 | 3 | import ( |
|
| 4 | + | "context" |
|
| 4 | 5 | "html/template" |
|
| 5 | 6 | "net/http" |
|
| 6 | 7 | "strings" |
|
| 30 | 31 | ||
| 31 | 32 | func renderLatestPostsEmbed(posts []Post) string { |
|
| 32 | 33 | var b strings.Builder |
|
| 33 | - | b.WriteString(`<div class="post-list">`) |
|
| 34 | - | for i := range posts { |
|
| 35 | - | p := &posts[i] |
|
| 36 | - | b.WriteString(`<a href="/posts/` + p.Slug + `" class="post-item"><div class="post-item-info"><span class="post-title">` + p.DisplayTitle() + `</span>`) |
|
| 37 | - | if p.Tags != nil && *p.Tags != "" { |
|
| 38 | - | b.WriteString(`<span class="post-tags">`) |
|
| 39 | - | for _, t := range strings.Split(*p.Tags, ",") { |
|
| 40 | - | if v := strings.TrimSpace(t); v != "" { |
|
| 41 | - | b.WriteString(`<span class="tag">` + v + `</span>`) |
|
| 42 | - | } |
|
| 43 | - | } |
|
| 44 | - | b.WriteString(`</span>`) |
|
| 45 | - | } |
|
| 46 | - | b.WriteString(`</div>`) |
|
| 47 | - | if p.PublishedDate != nil { |
|
| 48 | - | b.WriteString(`<time class="post-date">` + *p.PublishedDate + `</time>`) |
|
| 49 | - | } |
|
| 50 | - | b.WriteString(`</a>`) |
|
| 51 | - | } |
|
| 52 | - | b.WriteString(`</div>`) |
|
| 34 | + | _ = latestPosts(posts).Render(context.Background(), &b) |
|
| 53 | 35 | return b.String() |
|
| 54 | 36 | } |
|
| 55 | 37 | ||
| 56 | 38 | func (a *App) publicIndex(w http.ResponseWriter, r *http.Request) { |
|
| 57 | - | ctx := a.site() |
|
| 58 | 39 | blogDesc, _ := getSetting(a.DB, "blog_description") |
|
| 59 | 40 | intro, _ := getSetting(a.DB, "intro_content") |
|
| 60 | 41 | ||
| 76 | 57 | introHTML = strings.ReplaceAll(introHTML, "{{latest_posts}}", embed) |
|
| 77 | 58 | } |
|
| 78 | 59 | ||
| 79 | - | a.renderPage(w, "index.html", indexPageData{ |
|
| 80 | - | BlogTitle: ctx.BlogTitle, BlogDescription: blogDesc, |
|
| 81 | - | IntroHTML: template.HTML(introHTML), |
|
| 82 | - | Posts: posts, |
|
| 83 | - | NavLinks: ctx.NavLinks, FaviconURL: ctx.FaviconURL, OGImageURL: ctx.OGImageURL, |
|
| 84 | - | SiteURL: ctx.SiteURL, HeaderHTML: ctx.HeaderHTML, FooterHTML: ctx.FooterHTML, |
|
| 85 | - | }) |
|
| 60 | + | v := indexView{ |
|
| 61 | + | siteContext: a.site(), |
|
| 62 | + | BlogDescription: blogDesc, |
|
| 63 | + | IntroHTML: template.HTML(introHTML), |
|
| 64 | + | Posts: posts, |
|
| 65 | + | } |
|
| 66 | + | a.renderPublic(w, r, v.siteContext, v.BlogTitle, indexMeta(v), a.body("index", v, indexBody(v))) |
|
| 86 | 67 | } |
|
| 87 | 68 | ||
| 88 | 69 | func (a *App) publicPost(w http.ResponseWriter, r *http.Request) { |
|
| 105 | 86 | weather = w |
|
| 106 | 87 | } |
|
| 107 | 88 | } |
|
| 108 | - | ctx := a.site() |
|
| 109 | - | rendered := renderMarkdown(post.Content) |
|
| 110 | - | a.renderPage(w, "post.html", postPageData{ |
|
| 111 | - | BlogTitle: ctx.BlogTitle, NavLinks: ctx.NavLinks, Post: *post, |
|
| 112 | - | RenderedContent: template.HTML(rendered), |
|
| 113 | - | FaviconURL: ctx.FaviconURL, OGImageURL: ctx.OGImageURL, |
|
| 114 | - | SiteURL: ctx.SiteURL, HeaderHTML: ctx.HeaderHTML, FooterHTML: ctx.FooterHTML, Weather: weather, |
|
| 115 | - | }) |
|
| 89 | + | v := postView{ |
|
| 90 | + | siteContext: a.site(), |
|
| 91 | + | Post: *post, |
|
| 92 | + | RenderedContent: template.HTML(renderMarkdown(post.Content)), |
|
| 93 | + | Weather: weather, |
|
| 94 | + | } |
|
| 95 | + | a.renderPublic(w, r, v.siteContext, post.DisplayTitle()+" — "+v.BlogTitle, postMeta(v), a.body("post", v, postBody(v))) |
|
| 116 | 96 | } |
|
| 117 | 97 | ||
| 118 | 98 | func (a *App) publicPage(w http.ResponseWriter, r *http.Request) { |
|
| 131 | 111 | http.Error(w, "Not found", http.StatusNotFound) |
|
| 132 | 112 | return |
|
| 133 | 113 | } |
|
| 134 | - | ctx := a.site() |
|
| 135 | - | rendered := renderMarkdown(page.Content) |
|
| 136 | - | a.renderPage(w, "page.html", pagePageData{ |
|
| 137 | - | BlogTitle: ctx.BlogTitle, NavLinks: ctx.NavLinks, Page: *page, |
|
| 138 | - | RenderedContent: template.HTML(rendered), |
|
| 139 | - | FaviconURL: ctx.FaviconURL, OGImageURL: ctx.OGImageURL, |
|
| 140 | - | SiteURL: ctx.SiteURL, HeaderHTML: ctx.HeaderHTML, FooterHTML: ctx.FooterHTML, |
|
| 141 | - | }) |
|
| 114 | + | v := pageView{ |
|
| 115 | + | siteContext: a.site(), |
|
| 116 | + | Page: *page, |
|
| 117 | + | RenderedContent: template.HTML(renderMarkdown(page.Content)), |
|
| 118 | + | } |
|
| 119 | + | a.renderPublic(w, r, v.siteContext, page.Title+" — "+v.BlogTitle, pageMeta(v), a.body("page", v, pageBody(v))) |
|
| 142 | 120 | } |
|
| 143 | 121 | ||
| 144 | 122 | func (a *App) publicPostsList(w http.ResponseWriter, r *http.Request) { |
|
| 145 | - | ctx := a.site() |
|
| 146 | 123 | posts, err := getPublishedPosts(a.DB, 0) |
|
| 147 | 124 | if err != nil { |
|
| 148 | 125 | http.Error(w, "Server error", http.StatusInternalServerError) |
|
| 149 | 126 | return |
|
| 150 | 127 | } |
|
| 151 | - | a.renderPage(w, "posts.html", postsListPageData{ |
|
| 152 | - | BlogTitle: ctx.BlogTitle, NavLinks: ctx.NavLinks, Posts: posts, |
|
| 153 | - | FaviconURL: ctx.FaviconURL, OGImageURL: ctx.OGImageURL, |
|
| 154 | - | SiteURL: ctx.SiteURL, HeaderHTML: ctx.HeaderHTML, FooterHTML: ctx.FooterHTML, |
|
| 155 | - | }) |
|
| 128 | + | v := postsView{siteContext: a.site(), Posts: posts} |
|
| 129 | + | a.renderPublic(w, r, v.siteContext, "Posts — "+v.BlogTitle, postsMeta(v), a.body("posts", v, postsBody(v))) |
|
| 156 | 130 | } |
|
| 157 | 131 | ||
| 158 | 132 | func (a *App) customCSS(w http.ResponseWriter, r *http.Request) { |
|
| 1 | + | package main |
|
| 2 | + | ||
| 3 | + | templ layout(site siteContext, title string, meta templ.Component, body templ.Component) { |
|
| 4 | + | <!DOCTYPE html> |
|
| 5 | + | <html lang="en"> |
|
| 6 | + | <head> |
|
| 7 | + | <meta charset="UTF-8"/> |
|
| 8 | + | <meta name="viewport" content="width=device-width, initial-scale=1.0"/> |
|
| 9 | + | <title>{ title }</title> |
|
| 10 | + | if site.FaviconURL != "" { |
|
| 11 | + | <link rel="apple-touch-icon" sizes="180x180" href={ site.FaviconURL }/> |
|
| 12 | + | <link rel="icon" type="image/png" sizes="32x32" href={ site.FaviconURL }/> |
|
| 13 | + | <link rel="icon" type="image/png" sizes="16x16" href={ site.FaviconURL }/> |
|
| 14 | + | } else { |
|
| 15 | + | <link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png"/> |
|
| 16 | + | <link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png"/> |
|
| 17 | + | <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png"/> |
|
| 18 | + | <link rel="manifest" href="/static/site.webmanifest"/> |
|
| 19 | + | } |
|
| 20 | + | <meta name="theme-color" content="#121113"/> |
|
| 21 | + | @meta |
|
| 22 | + | <link rel="stylesheet" href="/assets/darkmatter.css"/> |
|
| 23 | + | <link rel="stylesheet" href="/static/styles.css"/> |
|
| 24 | + | <link rel="stylesheet" href="/custom-styles.css"/> |
|
| 25 | + | </head> |
|
| 26 | + | <body> |
|
| 27 | + | if site.HeaderHTML != "" { |
|
| 28 | + | <div class="custom-header"> |
|
| 29 | + | @templ.Raw(string(site.HeaderHTML)) |
|
| 30 | + | </div> |
|
| 31 | + | } |
|
| 32 | + | <header class="header"> |
|
| 33 | + | <a href="/" class="logo">{ site.BlogTitle }</a> |
|
| 34 | + | <nav class="links"> |
|
| 35 | + | for _, l := range site.NavLinks { |
|
| 36 | + | <a href={ templ.URL(l.URL) }>{ l.Label }</a> |
|
| 37 | + | } |
|
| 38 | + | </nav> |
|
| 39 | + | </header> |
|
| 40 | + | <main> |
|
| 41 | + | @body |
|
| 42 | + | </main> |
|
| 43 | + | <footer class="footer"> |
|
| 44 | + | @templ.Raw(string(site.FooterHTML)) |
|
| 45 | + | </footer> |
|
| 46 | + | <script> |
|
| 47 | + | document.querySelectorAll('.post-date').forEach(el => { |
|
| 48 | + | const d = new Date(el.textContent.trim()); |
|
| 49 | + | if (!isNaN(d)) { |
|
| 50 | + | const day = String(d.getDate()).padStart(2, '0'); |
|
| 51 | + | const mon = d.toLocaleString('en-US', { month: 'short' }); |
|
| 52 | + | el.textContent = `${day} ${mon}, ${d.getFullYear()}`; |
|
| 53 | + | } |
|
| 54 | + | }); |
|
| 55 | + | </script> |
|
| 56 | + | </body> |
|
| 57 | + | </html> |
|
| 58 | + | } |
|
| 59 | + | ||
| 60 | + | templ ogImage(site siteContext) { |
|
| 61 | + | if site.OGImageURL != "" { |
|
| 62 | + | <meta property="og:image" content={ site.OGImageURL }/> |
|
| 63 | + | } else { |
|
| 64 | + | <meta property="og:image" content={ site.SiteURL + "/static/og.png" }/> |
|
| 65 | + | } |
|
| 66 | + | } |
| 1 | + | // Code generated by templ - DO NOT EDIT. |
|
| 2 | + | ||
| 3 | + | // templ: version: v0.3.1001 |
|
| 4 | + | package main |
|
| 5 | + | ||
| 6 | + | //lint:file-ignore SA4006 This context is only used if a nested component is present. |
|
| 7 | + | ||
| 8 | + | import "github.com/a-h/templ" |
|
| 9 | + | import templruntime "github.com/a-h/templ/runtime" |
|
| 10 | + | ||
| 11 | + | func layout(site siteContext, title string, meta templ.Component, body templ.Component) templ.Component { |
|
| 12 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 13 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 14 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 15 | + | return templ_7745c5c3_CtxErr |
|
| 16 | + | } |
|
| 17 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 18 | + | if !templ_7745c5c3_IsBuffer { |
|
| 19 | + | defer func() { |
|
| 20 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 21 | + | if templ_7745c5c3_Err == nil { |
|
| 22 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 23 | + | } |
|
| 24 | + | }() |
|
| 25 | + | } |
|
| 26 | + | ctx = templ.InitializeContext(ctx) |
|
| 27 | + | templ_7745c5c3_Var1 := templ.GetChildren(ctx) |
|
| 28 | + | if templ_7745c5c3_Var1 == nil { |
|
| 29 | + | templ_7745c5c3_Var1 = templ.NopComponent |
|
| 30 | + | } |
|
| 31 | + | ctx = templ.ClearChildren(ctx) |
|
| 32 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<!doctype html><html lang=\"en\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>") |
|
| 33 | + | if templ_7745c5c3_Err != nil { |
|
| 34 | + | return templ_7745c5c3_Err |
|
| 35 | + | } |
|
| 36 | + | var templ_7745c5c3_Var2 string |
|
| 37 | + | templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title) |
|
| 38 | + | if templ_7745c5c3_Err != nil { |
|
| 39 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `layout.templ`, Line: 9, Col: 17} |
|
| 40 | + | } |
|
| 41 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) |
|
| 42 | + | if templ_7745c5c3_Err != nil { |
|
| 43 | + | return templ_7745c5c3_Err |
|
| 44 | + | } |
|
| 45 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</title>") |
|
| 46 | + | if templ_7745c5c3_Err != nil { |
|
| 47 | + | return templ_7745c5c3_Err |
|
| 48 | + | } |
|
| 49 | + | if site.FaviconURL != "" { |
|
| 50 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<link rel=\"apple-touch-icon\" sizes=\"180x180\" href=\"") |
|
| 51 | + | if templ_7745c5c3_Err != nil { |
|
| 52 | + | return templ_7745c5c3_Err |
|
| 53 | + | } |
|
| 54 | + | var templ_7745c5c3_Var3 templ.SafeURL |
|
| 55 | + | templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinURLErrs(site.FaviconURL) |
|
| 56 | + | if templ_7745c5c3_Err != nil { |
|
| 57 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `layout.templ`, Line: 11, Col: 71} |
|
| 58 | + | } |
|
| 59 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) |
|
| 60 | + | if templ_7745c5c3_Err != nil { |
|
| 61 | + | return templ_7745c5c3_Err |
|
| 62 | + | } |
|
| 63 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\"><link rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"") |
|
| 64 | + | if templ_7745c5c3_Err != nil { |
|
| 65 | + | return templ_7745c5c3_Err |
|
| 66 | + | } |
|
| 67 | + | var templ_7745c5c3_Var4 templ.SafeURL |
|
| 68 | + | templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinURLErrs(site.FaviconURL) |
|
| 69 | + | if templ_7745c5c3_Err != nil { |
|
| 70 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `layout.templ`, Line: 12, Col: 74} |
|
| 71 | + | } |
|
| 72 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) |
|
| 73 | + | if templ_7745c5c3_Err != nil { |
|
| 74 | + | return templ_7745c5c3_Err |
|
| 75 | + | } |
|
| 76 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "\"><link rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"") |
|
| 77 | + | if templ_7745c5c3_Err != nil { |
|
| 78 | + | return templ_7745c5c3_Err |
|
| 79 | + | } |
|
| 80 | + | var templ_7745c5c3_Var5 templ.SafeURL |
|
| 81 | + | templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinURLErrs(site.FaviconURL) |
|
| 82 | + | if templ_7745c5c3_Err != nil { |
|
| 83 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `layout.templ`, Line: 13, Col: 74} |
|
| 84 | + | } |
|
| 85 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) |
|
| 86 | + | if templ_7745c5c3_Err != nil { |
|
| 87 | + | return templ_7745c5c3_Err |
|
| 88 | + | } |
|
| 89 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "\">") |
|
| 90 | + | if templ_7745c5c3_Err != nil { |
|
| 91 | + | return templ_7745c5c3_Err |
|
| 92 | + | } |
|
| 93 | + | } else { |
|
| 94 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<link rel=\"apple-touch-icon\" sizes=\"180x180\" href=\"/static/apple-touch-icon.png\"><link rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/static/favicon-32x32.png\"><link rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/static/favicon-16x16.png\"><link rel=\"manifest\" href=\"/static/site.webmanifest\">") |
|
| 95 | + | if templ_7745c5c3_Err != nil { |
|
| 96 | + | return templ_7745c5c3_Err |
|
| 97 | + | } |
|
| 98 | + | } |
|
| 99 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<meta name=\"theme-color\" content=\"#121113\">") |
|
| 100 | + | if templ_7745c5c3_Err != nil { |
|
| 101 | + | return templ_7745c5c3_Err |
|
| 102 | + | } |
|
| 103 | + | templ_7745c5c3_Err = meta.Render(ctx, templ_7745c5c3_Buffer) |
|
| 104 | + | if templ_7745c5c3_Err != nil { |
|
| 105 | + | return templ_7745c5c3_Err |
|
| 106 | + | } |
|
| 107 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "<link rel=\"stylesheet\" href=\"/assets/darkmatter.css\"><link rel=\"stylesheet\" href=\"/static/styles.css\"><link rel=\"stylesheet\" href=\"/custom-styles.css\"></head><body>") |
|
| 108 | + | if templ_7745c5c3_Err != nil { |
|
| 109 | + | return templ_7745c5c3_Err |
|
| 110 | + | } |
|
| 111 | + | if site.HeaderHTML != "" { |
|
| 112 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "<div class=\"custom-header\">") |
|
| 113 | + | if templ_7745c5c3_Err != nil { |
|
| 114 | + | return templ_7745c5c3_Err |
|
| 115 | + | } |
|
| 116 | + | templ_7745c5c3_Err = templ.Raw(string(site.HeaderHTML)).Render(ctx, templ_7745c5c3_Buffer) |
|
| 117 | + | if templ_7745c5c3_Err != nil { |
|
| 118 | + | return templ_7745c5c3_Err |
|
| 119 | + | } |
|
| 120 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</div>") |
|
| 121 | + | if templ_7745c5c3_Err != nil { |
|
| 122 | + | return templ_7745c5c3_Err |
|
| 123 | + | } |
|
| 124 | + | } |
|
| 125 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<header class=\"header\"><a href=\"/\" class=\"logo\">") |
|
| 126 | + | if templ_7745c5c3_Err != nil { |
|
| 127 | + | return templ_7745c5c3_Err |
|
| 128 | + | } |
|
| 129 | + | var templ_7745c5c3_Var6 string |
|
| 130 | + | templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(site.BlogTitle) |
|
| 131 | + | if templ_7745c5c3_Err != nil { |
|
| 132 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `layout.templ`, Line: 33, Col: 45} |
|
| 133 | + | } |
|
| 134 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) |
|
| 135 | + | if templ_7745c5c3_Err != nil { |
|
| 136 | + | return templ_7745c5c3_Err |
|
| 137 | + | } |
|
| 138 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</a><nav class=\"links\">") |
|
| 139 | + | if templ_7745c5c3_Err != nil { |
|
| 140 | + | return templ_7745c5c3_Err |
|
| 141 | + | } |
|
| 142 | + | for _, l := range site.NavLinks { |
|
| 143 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "<a href=\"") |
|
| 144 | + | if templ_7745c5c3_Err != nil { |
|
| 145 | + | return templ_7745c5c3_Err |
|
| 146 | + | } |
|
| 147 | + | var templ_7745c5c3_Var7 templ.SafeURL |
|
| 148 | + | templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinURLErrs(templ.URL(l.URL)) |
|
| 149 | + | if templ_7745c5c3_Err != nil { |
|
| 150 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `layout.templ`, Line: 36, Col: 32} |
|
| 151 | + | } |
|
| 152 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) |
|
| 153 | + | if templ_7745c5c3_Err != nil { |
|
| 154 | + | return templ_7745c5c3_Err |
|
| 155 | + | } |
|
| 156 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "\">") |
|
| 157 | + | if templ_7745c5c3_Err != nil { |
|
| 158 | + | return templ_7745c5c3_Err |
|
| 159 | + | } |
|
| 160 | + | var templ_7745c5c3_Var8 string |
|
| 161 | + | templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(l.Label) |
|
| 162 | + | if templ_7745c5c3_Err != nil { |
|
| 163 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `layout.templ`, Line: 36, Col: 44} |
|
| 164 | + | } |
|
| 165 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) |
|
| 166 | + | if templ_7745c5c3_Err != nil { |
|
| 167 | + | return templ_7745c5c3_Err |
|
| 168 | + | } |
|
| 169 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</a>") |
|
| 170 | + | if templ_7745c5c3_Err != nil { |
|
| 171 | + | return templ_7745c5c3_Err |
|
| 172 | + | } |
|
| 173 | + | } |
|
| 174 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "</nav></header><main>") |
|
| 175 | + | if templ_7745c5c3_Err != nil { |
|
| 176 | + | return templ_7745c5c3_Err |
|
| 177 | + | } |
|
| 178 | + | templ_7745c5c3_Err = body.Render(ctx, templ_7745c5c3_Buffer) |
|
| 179 | + | if templ_7745c5c3_Err != nil { |
|
| 180 | + | return templ_7745c5c3_Err |
|
| 181 | + | } |
|
| 182 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</main><footer class=\"footer\">") |
|
| 183 | + | if templ_7745c5c3_Err != nil { |
|
| 184 | + | return templ_7745c5c3_Err |
|
| 185 | + | } |
|
| 186 | + | templ_7745c5c3_Err = templ.Raw(string(site.FooterHTML)).Render(ctx, templ_7745c5c3_Buffer) |
|
| 187 | + | if templ_7745c5c3_Err != nil { |
|
| 188 | + | return templ_7745c5c3_Err |
|
| 189 | + | } |
|
| 190 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "</footer><script>\n\t\t\t\tdocument.querySelectorAll('.post-date').forEach(el => {\n\t\t\t\t\tconst d = new Date(el.textContent.trim());\n\t\t\t\t\tif (!isNaN(d)) {\n\t\t\t\t\t\tconst day = String(d.getDate()).padStart(2, '0');\n\t\t\t\t\t\tconst mon = d.toLocaleString('en-US', { month: 'short' });\n\t\t\t\t\t\tel.textContent = `${day} ${mon}, ${d.getFullYear()}`;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t</script></body></html>") |
|
| 191 | + | if templ_7745c5c3_Err != nil { |
|
| 192 | + | return templ_7745c5c3_Err |
|
| 193 | + | } |
|
| 194 | + | return nil |
|
| 195 | + | }) |
|
| 196 | + | } |
|
| 197 | + | ||
| 198 | + | func ogImage(site siteContext) templ.Component { |
|
| 199 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 200 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 201 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 202 | + | return templ_7745c5c3_CtxErr |
|
| 203 | + | } |
|
| 204 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 205 | + | if !templ_7745c5c3_IsBuffer { |
|
| 206 | + | defer func() { |
|
| 207 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 208 | + | if templ_7745c5c3_Err == nil { |
|
| 209 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 210 | + | } |
|
| 211 | + | }() |
|
| 212 | + | } |
|
| 213 | + | ctx = templ.InitializeContext(ctx) |
|
| 214 | + | templ_7745c5c3_Var9 := templ.GetChildren(ctx) |
|
| 215 | + | if templ_7745c5c3_Var9 == nil { |
|
| 216 | + | templ_7745c5c3_Var9 = templ.NopComponent |
|
| 217 | + | } |
|
| 218 | + | ctx = templ.ClearChildren(ctx) |
|
| 219 | + | if site.OGImageURL != "" { |
|
| 220 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "<meta property=\"og:image\" content=\"") |
|
| 221 | + | if templ_7745c5c3_Err != nil { |
|
| 222 | + | return templ_7745c5c3_Err |
|
| 223 | + | } |
|
| 224 | + | var templ_7745c5c3_Var10 string |
|
| 225 | + | templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(site.OGImageURL) |
|
| 226 | + | if templ_7745c5c3_Err != nil { |
|
| 227 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `layout.templ`, Line: 62, Col: 53} |
|
| 228 | + | } |
|
| 229 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) |
|
| 230 | + | if templ_7745c5c3_Err != nil { |
|
| 231 | + | return templ_7745c5c3_Err |
|
| 232 | + | } |
|
| 233 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "\">") |
|
| 234 | + | if templ_7745c5c3_Err != nil { |
|
| 235 | + | return templ_7745c5c3_Err |
|
| 236 | + | } |
|
| 237 | + | } else { |
|
| 238 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "<meta property=\"og:image\" content=\"") |
|
| 239 | + | if templ_7745c5c3_Err != nil { |
|
| 240 | + | return templ_7745c5c3_Err |
|
| 241 | + | } |
|
| 242 | + | var templ_7745c5c3_Var11 string |
|
| 243 | + | templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(site.SiteURL + "/static/og.png") |
|
| 244 | + | if templ_7745c5c3_Err != nil { |
|
| 245 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `layout.templ`, Line: 64, Col: 69} |
|
| 246 | + | } |
|
| 247 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) |
|
| 248 | + | if templ_7745c5c3_Err != nil { |
|
| 249 | + | return templ_7745c5c3_Err |
|
| 250 | + | } |
|
| 251 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "\">") |
|
| 252 | + | if templ_7745c5c3_Err != nil { |
|
| 253 | + | return templ_7745c5c3_Err |
|
| 254 | + | } |
|
| 255 | + | } |
|
| 256 | + | return nil |
|
| 257 | + | }) |
|
| 258 | + | } |
|
| 259 | + | ||
| 260 | + | var _ = templruntime.GeneratedTemplate |
| 77 | 77 | Storage: storageBackend, |
|
| 78 | 78 | SiteURL: strings.TrimRight(config.Getenv("SITE_URL", "http://localhost:3000"), "/"), |
|
| 79 | 79 | APIKey: config.Getenv("POSTS_API_KEY", ""), |
|
| 80 | + | Overrides: &overrides{}, |
|
| 80 | 81 | } |
|
| 82 | + | app.loadOverrides() |
|
| 81 | 83 | ||
| 82 | 84 | addr := config.Getenv("HOST", "127.0.0.1") + ":" + config.Getenv("PORT", "3000") |
|
| 83 | 85 | logger.Info("posts server running", "addr", addr) |
| 1 | + | package main |
|
| 2 | + | ||
| 3 | + | // Each public view has a meta component (kept in the layout's <head>) and a |
|
| 4 | + | // body component. The body can be replaced by a custom html/template from |
|
| 5 | + | // /admin/templates; the starters/*.html files mirror these defaults. |
|
| 6 | + | ||
| 7 | + | templ postItem(p Post, class string) { |
|
| 8 | + | <a href={ templ.URL("/posts/" + p.Slug) } class={ class }> |
|
| 9 | + | <div class="post-item-info"> |
|
| 10 | + | <span class="post-title">{ p.DisplayTitle() }</span> |
|
| 11 | + | </div> |
|
| 12 | + | if p.PublishedDate != nil { |
|
| 13 | + | <time class="post-date">{ p.PublishedDateStr() }</time> |
|
| 14 | + | } |
|
| 15 | + | </a> |
|
| 16 | + | } |
|
| 17 | + | ||
| 18 | + | templ latestPosts(posts []Post) { |
|
| 19 | + | <div class="post-list"> |
|
| 20 | + | for _, p := range posts { |
|
| 21 | + | <a href={ templ.URL("/posts/" + p.Slug) } class="post-item"> |
|
| 22 | + | <div class="post-item-info"> |
|
| 23 | + | <span class="post-title">{ p.DisplayTitle() }</span> |
|
| 24 | + | if tags := p.TagList(); len(tags) > 0 { |
|
| 25 | + | <span class="post-tags"> |
|
| 26 | + | for _, t := range tags { |
|
| 27 | + | <span class="tag">{ t }</span> |
|
| 28 | + | } |
|
| 29 | + | </span> |
|
| 30 | + | } |
|
| 31 | + | </div> |
|
| 32 | + | if p.PublishedDate != nil { |
|
| 33 | + | <time class="post-date">{ p.PublishedDateStr() }</time> |
|
| 34 | + | } |
|
| 35 | + | </a> |
|
| 36 | + | } |
|
| 37 | + | </div> |
|
| 38 | + | } |
|
| 39 | + | ||
| 40 | + | templ indexMeta(v indexView) { |
|
| 41 | + | <meta name="description" content={ v.BlogDescription }/> |
|
| 42 | + | <meta property="og:title" content={ v.BlogTitle }/> |
|
| 43 | + | <meta property="og:description" content={ v.BlogDescription }/> |
|
| 44 | + | <meta property="og:type" content="website"/> |
|
| 45 | + | <meta property="og:url" content={ v.SiteURL }/> |
|
| 46 | + | @ogImage(v.siteContext) |
|
| 47 | + | } |
|
| 48 | + | ||
| 49 | + | templ indexBody(v indexView) { |
|
| 50 | + | if v.IntroHTML != "" { |
|
| 51 | + | <article class="intro markdown-body"> |
|
| 52 | + | @templ.Raw(string(v.IntroHTML)) |
|
| 53 | + | </article> |
|
| 54 | + | } |
|
| 55 | + | if len(v.Posts) == 0 { |
|
| 56 | + | <p class="empty">no posts yet</p> |
|
| 57 | + | } |
|
| 58 | + | <div class="post-list"> |
|
| 59 | + | for _, p := range v.Posts { |
|
| 60 | + | @postItem(p, "post-item") |
|
| 61 | + | } |
|
| 62 | + | </div> |
|
| 63 | + | } |
|
| 64 | + | ||
| 65 | + | templ postsMeta(v postsView) { |
|
| 66 | + | @ogImage(v.siteContext) |
|
| 67 | + | <meta property="og:url" content={ v.SiteURL + "/posts" }/> |
|
| 68 | + | } |
|
| 69 | + | ||
| 70 | + | templ postsBody(v postsView) { |
|
| 71 | + | <h1>Posts</h1> |
|
| 72 | + | if len(v.Posts) == 0 { |
|
| 73 | + | <p class="empty">no posts yet</p> |
|
| 74 | + | } |
|
| 75 | + | <div class="post-list"> |
|
| 76 | + | for _, p := range v.Posts { |
|
| 77 | + | @postItem(p, "post-item post-item-enhanced") |
|
| 78 | + | } |
|
| 79 | + | </div> |
|
| 80 | + | } |
|
| 81 | + | ||
| 82 | + | templ pageMeta(v pageView) { |
|
| 83 | + | @ogImage(v.siteContext) |
|
| 84 | + | <meta property="og:url" content={ v.SiteURL + "/" + v.Page.Slug }/> |
|
| 85 | + | } |
|
| 86 | + | ||
| 87 | + | templ pageBody(v pageView) { |
|
| 88 | + | <div class="page-header"> |
|
| 89 | + | <h1>{ v.Page.Title }</h1> |
|
| 90 | + | </div> |
|
| 91 | + | <article class="markdown-body"> |
|
| 92 | + | @templ.Raw(string(v.RenderedContent)) |
|
| 93 | + | </article> |
|
| 94 | + | } |
|
| 95 | + | ||
| 96 | + | templ postMeta(v postView) { |
|
| 97 | + | if v.Post.MetaDescription != nil { |
|
| 98 | + | <meta name="description" content={ v.Post.MetaDescriptionStr() }/> |
|
| 99 | + | <meta property="og:description" content={ v.Post.MetaDescriptionStr() }/> |
|
| 100 | + | } |
|
| 101 | + | if v.Post.MetaImageStr() != "" { |
|
| 102 | + | <meta property="og:image" content={ v.Post.MetaImageStr() }/> |
|
| 103 | + | } else { |
|
| 104 | + | @ogImage(v.siteContext) |
|
| 105 | + | } |
|
| 106 | + | if v.Post.CanonicalURL != nil { |
|
| 107 | + | <link rel="canonical" href={ templ.URL(v.Post.CanonicalURLStr()) }/> |
|
| 108 | + | } |
|
| 109 | + | <meta property="og:title" content={ v.Post.DisplayTitle() }/> |
|
| 110 | + | <meta property="og:type" content="article"/> |
|
| 111 | + | <meta property="og:url" content={ v.SiteURL + "/posts/" + v.Post.Slug }/> |
|
| 112 | + | <meta property="article:published_time" content={ v.Post.PublishedDateStr() }/> |
|
| 113 | + | } |
|
| 114 | + | ||
| 115 | + | // The location icon is from Phosphor Icons: |
|
| 116 | + | // https://github.com/phosphor-icons/core/blob/main/LICENSE |
|
| 117 | + | templ postBody(v postView) { |
|
| 118 | + | <div class="post-header"> |
|
| 119 | + | if v.Post.HasTitle() { |
|
| 120 | + | <h1>{ v.Post.TitleStr() }</h1> |
|
| 121 | + | } |
|
| 122 | + | if v.Post.MetaDescription != nil { |
|
| 123 | + | <p class="post-description">{ v.Post.MetaDescriptionStr() }</p> |
|
| 124 | + | } |
|
| 125 | + | <div class="post-weather"> |
|
| 126 | + | if v.Post.PublishedDate != nil { |
|
| 127 | + | <span> |
|
| 128 | + | <time class="post-date">{ v.Post.PublishedDateStr() }</time> |
|
| 129 | + | </span> |
|
| 130 | + | <span>•</span> |
|
| 131 | + | } |
|
| 132 | + | if v.Post.Weather != nil { |
|
| 133 | + | @templ.Raw(string(v.Weather.Icon)) |
|
| 134 | + | <p class="weather-conditions">{ v.Weather.Conditions }</p> |
|
| 135 | + | <p class="weather-temp">{ v.Weather.Temperature }</p> |
|
| 136 | + | • |
|
| 137 | + | <div class="weather-location"> |
|
| 138 | + | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><path fill="currentColor" d="M128 68a36 36 0 1 0 36 36a36 36 0 0 0-36-36m0 64a28 28 0 1 1 28-28a28 28 0 0 1-28 28m0-112a84.09 84.09 0 0 0-84 84c0 30.42 14.17 62.79 41 93.62a250 250 0 0 0 40.73 37.66a4 4 0 0 0 4.58 0A250 250 0 0 0 171 197.62c26.81-30.83 41-63.2 41-93.62a84.09 84.09 0 0 0-84-84m37.1 172.23A254.6 254.6 0 0 1 128 227a254.6 254.6 0 0 1-37.1-34.81C73.15 171.8 52 139.9 52 104a76 76 0 0 1 152 0c0 35.9-21.15 67.8-38.9 88.23"></path></svg> |
|
| 139 | + | <p>{ v.Weather.Location }</p> |
|
| 140 | + | </div> |
|
| 141 | + | } |
|
| 142 | + | </div> |
|
| 143 | + | if len(v.Post.TagList()) > 0 { |
|
| 144 | + | <div class="post-tags"> |
|
| 145 | + | for _, t := range v.Post.TagList() { |
|
| 146 | + | <span class="tag">{ t }</span> |
|
| 147 | + | } |
|
| 148 | + | </div> |
|
| 149 | + | } |
|
| 150 | + | </div> |
|
| 151 | + | <article class="markdown-body"> |
|
| 152 | + | @templ.Raw(string(v.RenderedContent)) |
|
| 153 | + | </article> |
|
| 154 | + | } |
| 1 | + | // Code generated by templ - DO NOT EDIT. |
|
| 2 | + | ||
| 3 | + | // templ: version: v0.3.1001 |
|
| 4 | + | package main |
|
| 5 | + | ||
| 6 | + | //lint:file-ignore SA4006 This context is only used if a nested component is present. |
|
| 7 | + | ||
| 8 | + | import "github.com/a-h/templ" |
|
| 9 | + | import templruntime "github.com/a-h/templ/runtime" |
|
| 10 | + | ||
| 11 | + | // Each public view has a meta component (kept in the layout's <head>) and a |
|
| 12 | + | // body component. The body can be replaced by a custom html/template from |
|
| 13 | + | // /admin/templates; the starters/*.html files mirror these defaults. |
|
| 14 | + | func postItem(p Post, class string) templ.Component { |
|
| 15 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 16 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 17 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 18 | + | return templ_7745c5c3_CtxErr |
|
| 19 | + | } |
|
| 20 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 21 | + | if !templ_7745c5c3_IsBuffer { |
|
| 22 | + | defer func() { |
|
| 23 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 24 | + | if templ_7745c5c3_Err == nil { |
|
| 25 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 26 | + | } |
|
| 27 | + | }() |
|
| 28 | + | } |
|
| 29 | + | ctx = templ.InitializeContext(ctx) |
|
| 30 | + | templ_7745c5c3_Var1 := templ.GetChildren(ctx) |
|
| 31 | + | if templ_7745c5c3_Var1 == nil { |
|
| 32 | + | templ_7745c5c3_Var1 = templ.NopComponent |
|
| 33 | + | } |
|
| 34 | + | ctx = templ.ClearChildren(ctx) |
|
| 35 | + | var templ_7745c5c3_Var2 = []any{class} |
|
| 36 | + | templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var2...) |
|
| 37 | + | if templ_7745c5c3_Err != nil { |
|
| 38 | + | return templ_7745c5c3_Err |
|
| 39 | + | } |
|
| 40 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<a href=\"") |
|
| 41 | + | if templ_7745c5c3_Err != nil { |
|
| 42 | + | return templ_7745c5c3_Err |
|
| 43 | + | } |
|
| 44 | + | var templ_7745c5c3_Var3 templ.SafeURL |
|
| 45 | + | templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinURLErrs(templ.URL("/posts/" + p.Slug)) |
|
| 46 | + | if templ_7745c5c3_Err != nil { |
|
| 47 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 8, Col: 40} |
|
| 48 | + | } |
|
| 49 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) |
|
| 50 | + | if templ_7745c5c3_Err != nil { |
|
| 51 | + | return templ_7745c5c3_Err |
|
| 52 | + | } |
|
| 53 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\" class=\"") |
|
| 54 | + | if templ_7745c5c3_Err != nil { |
|
| 55 | + | return templ_7745c5c3_Err |
|
| 56 | + | } |
|
| 57 | + | var templ_7745c5c3_Var4 string |
|
| 58 | + | templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var2).String()) |
|
| 59 | + | if templ_7745c5c3_Err != nil { |
|
| 60 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 1, Col: 0} |
|
| 61 | + | } |
|
| 62 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) |
|
| 63 | + | if templ_7745c5c3_Err != nil { |
|
| 64 | + | return templ_7745c5c3_Err |
|
| 65 | + | } |
|
| 66 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "\"><div class=\"post-item-info\"><span class=\"post-title\">") |
|
| 67 | + | if templ_7745c5c3_Err != nil { |
|
| 68 | + | return templ_7745c5c3_Err |
|
| 69 | + | } |
|
| 70 | + | var templ_7745c5c3_Var5 string |
|
| 71 | + | templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(p.DisplayTitle()) |
|
| 72 | + | if templ_7745c5c3_Err != nil { |
|
| 73 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 10, Col: 46} |
|
| 74 | + | } |
|
| 75 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) |
|
| 76 | + | if templ_7745c5c3_Err != nil { |
|
| 77 | + | return templ_7745c5c3_Err |
|
| 78 | + | } |
|
| 79 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</span></div>") |
|
| 80 | + | if templ_7745c5c3_Err != nil { |
|
| 81 | + | return templ_7745c5c3_Err |
|
| 82 | + | } |
|
| 83 | + | if p.PublishedDate != nil { |
|
| 84 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "<time class=\"post-date\">") |
|
| 85 | + | if templ_7745c5c3_Err != nil { |
|
| 86 | + | return templ_7745c5c3_Err |
|
| 87 | + | } |
|
| 88 | + | var templ_7745c5c3_Var6 string |
|
| 89 | + | templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(p.PublishedDateStr()) |
|
| 90 | + | if templ_7745c5c3_Err != nil { |
|
| 91 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 13, Col: 49} |
|
| 92 | + | } |
|
| 93 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) |
|
| 94 | + | if templ_7745c5c3_Err != nil { |
|
| 95 | + | return templ_7745c5c3_Err |
|
| 96 | + | } |
|
| 97 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</time>") |
|
| 98 | + | if templ_7745c5c3_Err != nil { |
|
| 99 | + | return templ_7745c5c3_Err |
|
| 100 | + | } |
|
| 101 | + | } |
|
| 102 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "</a>") |
|
| 103 | + | if templ_7745c5c3_Err != nil { |
|
| 104 | + | return templ_7745c5c3_Err |
|
| 105 | + | } |
|
| 106 | + | return nil |
|
| 107 | + | }) |
|
| 108 | + | } |
|
| 109 | + | ||
| 110 | + | func latestPosts(posts []Post) templ.Component { |
|
| 111 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 112 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 113 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 114 | + | return templ_7745c5c3_CtxErr |
|
| 115 | + | } |
|
| 116 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 117 | + | if !templ_7745c5c3_IsBuffer { |
|
| 118 | + | defer func() { |
|
| 119 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 120 | + | if templ_7745c5c3_Err == nil { |
|
| 121 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 122 | + | } |
|
| 123 | + | }() |
|
| 124 | + | } |
|
| 125 | + | ctx = templ.InitializeContext(ctx) |
|
| 126 | + | templ_7745c5c3_Var7 := templ.GetChildren(ctx) |
|
| 127 | + | if templ_7745c5c3_Var7 == nil { |
|
| 128 | + | templ_7745c5c3_Var7 = templ.NopComponent |
|
| 129 | + | } |
|
| 130 | + | ctx = templ.ClearChildren(ctx) |
|
| 131 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<div class=\"post-list\">") |
|
| 132 | + | if templ_7745c5c3_Err != nil { |
|
| 133 | + | return templ_7745c5c3_Err |
|
| 134 | + | } |
|
| 135 | + | for _, p := range posts { |
|
| 136 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "<a href=\"") |
|
| 137 | + | if templ_7745c5c3_Err != nil { |
|
| 138 | + | return templ_7745c5c3_Err |
|
| 139 | + | } |
|
| 140 | + | var templ_7745c5c3_Var8 templ.SafeURL |
|
| 141 | + | templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinURLErrs(templ.URL("/posts/" + p.Slug)) |
|
| 142 | + | if templ_7745c5c3_Err != nil { |
|
| 143 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 21, Col: 42} |
|
| 144 | + | } |
|
| 145 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) |
|
| 146 | + | if templ_7745c5c3_Err != nil { |
|
| 147 | + | return templ_7745c5c3_Err |
|
| 148 | + | } |
|
| 149 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\" class=\"post-item\"><div class=\"post-item-info\"><span class=\"post-title\">") |
|
| 150 | + | if templ_7745c5c3_Err != nil { |
|
| 151 | + | return templ_7745c5c3_Err |
|
| 152 | + | } |
|
| 153 | + | var templ_7745c5c3_Var9 string |
|
| 154 | + | templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(p.DisplayTitle()) |
|
| 155 | + | if templ_7745c5c3_Err != nil { |
|
| 156 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 23, Col: 48} |
|
| 157 | + | } |
|
| 158 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) |
|
| 159 | + | if templ_7745c5c3_Err != nil { |
|
| 160 | + | return templ_7745c5c3_Err |
|
| 161 | + | } |
|
| 162 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</span> ") |
|
| 163 | + | if templ_7745c5c3_Err != nil { |
|
| 164 | + | return templ_7745c5c3_Err |
|
| 165 | + | } |
|
| 166 | + | if tags := p.TagList(); len(tags) > 0 { |
|
| 167 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<span class=\"post-tags\">") |
|
| 168 | + | if templ_7745c5c3_Err != nil { |
|
| 169 | + | return templ_7745c5c3_Err |
|
| 170 | + | } |
|
| 171 | + | for _, t := range tags { |
|
| 172 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "<span class=\"tag\">") |
|
| 173 | + | if templ_7745c5c3_Err != nil { |
|
| 174 | + | return templ_7745c5c3_Err |
|
| 175 | + | } |
|
| 176 | + | var templ_7745c5c3_Var10 string |
|
| 177 | + | templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(t) |
|
| 178 | + | if templ_7745c5c3_Err != nil { |
|
| 179 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 27, Col: 29} |
|
| 180 | + | } |
|
| 181 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) |
|
| 182 | + | if templ_7745c5c3_Err != nil { |
|
| 183 | + | return templ_7745c5c3_Err |
|
| 184 | + | } |
|
| 185 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</span>") |
|
| 186 | + | if templ_7745c5c3_Err != nil { |
|
| 187 | + | return templ_7745c5c3_Err |
|
| 188 | + | } |
|
| 189 | + | } |
|
| 190 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</span>") |
|
| 191 | + | if templ_7745c5c3_Err != nil { |
|
| 192 | + | return templ_7745c5c3_Err |
|
| 193 | + | } |
|
| 194 | + | } |
|
| 195 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</div>") |
|
| 196 | + | if templ_7745c5c3_Err != nil { |
|
| 197 | + | return templ_7745c5c3_Err |
|
| 198 | + | } |
|
| 199 | + | if p.PublishedDate != nil { |
|
| 200 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<time class=\"post-date\">") |
|
| 201 | + | if templ_7745c5c3_Err != nil { |
|
| 202 | + | return templ_7745c5c3_Err |
|
| 203 | + | } |
|
| 204 | + | var templ_7745c5c3_Var11 string |
|
| 205 | + | templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(p.PublishedDateStr()) |
|
| 206 | + | if templ_7745c5c3_Err != nil { |
|
| 207 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 33, Col: 51} |
|
| 208 | + | } |
|
| 209 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) |
|
| 210 | + | if templ_7745c5c3_Err != nil { |
|
| 211 | + | return templ_7745c5c3_Err |
|
| 212 | + | } |
|
| 213 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</time>") |
|
| 214 | + | if templ_7745c5c3_Err != nil { |
|
| 215 | + | return templ_7745c5c3_Err |
|
| 216 | + | } |
|
| 217 | + | } |
|
| 218 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "</a>") |
|
| 219 | + | if templ_7745c5c3_Err != nil { |
|
| 220 | + | return templ_7745c5c3_Err |
|
| 221 | + | } |
|
| 222 | + | } |
|
| 223 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "</div>") |
|
| 224 | + | if templ_7745c5c3_Err != nil { |
|
| 225 | + | return templ_7745c5c3_Err |
|
| 226 | + | } |
|
| 227 | + | return nil |
|
| 228 | + | }) |
|
| 229 | + | } |
|
| 230 | + | ||
| 231 | + | func indexMeta(v indexView) templ.Component { |
|
| 232 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 233 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 234 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 235 | + | return templ_7745c5c3_CtxErr |
|
| 236 | + | } |
|
| 237 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 238 | + | if !templ_7745c5c3_IsBuffer { |
|
| 239 | + | defer func() { |
|
| 240 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 241 | + | if templ_7745c5c3_Err == nil { |
|
| 242 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 243 | + | } |
|
| 244 | + | }() |
|
| 245 | + | } |
|
| 246 | + | ctx = templ.InitializeContext(ctx) |
|
| 247 | + | templ_7745c5c3_Var12 := templ.GetChildren(ctx) |
|
| 248 | + | if templ_7745c5c3_Var12 == nil { |
|
| 249 | + | templ_7745c5c3_Var12 = templ.NopComponent |
|
| 250 | + | } |
|
| 251 | + | ctx = templ.ClearChildren(ctx) |
|
| 252 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "<meta name=\"description\" content=\"") |
|
| 253 | + | if templ_7745c5c3_Err != nil { |
|
| 254 | + | return templ_7745c5c3_Err |
|
| 255 | + | } |
|
| 256 | + | var templ_7745c5c3_Var13 string |
|
| 257 | + | templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(v.BlogDescription) |
|
| 258 | + | if templ_7745c5c3_Err != nil { |
|
| 259 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 41, Col: 53} |
|
| 260 | + | } |
|
| 261 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) |
|
| 262 | + | if templ_7745c5c3_Err != nil { |
|
| 263 | + | return templ_7745c5c3_Err |
|
| 264 | + | } |
|
| 265 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "\"><meta property=\"og:title\" content=\"") |
|
| 266 | + | if templ_7745c5c3_Err != nil { |
|
| 267 | + | return templ_7745c5c3_Err |
|
| 268 | + | } |
|
| 269 | + | var templ_7745c5c3_Var14 string |
|
| 270 | + | templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(v.BlogTitle) |
|
| 271 | + | if templ_7745c5c3_Err != nil { |
|
| 272 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 42, Col: 48} |
|
| 273 | + | } |
|
| 274 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) |
|
| 275 | + | if templ_7745c5c3_Err != nil { |
|
| 276 | + | return templ_7745c5c3_Err |
|
| 277 | + | } |
|
| 278 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "\"><meta property=\"og:description\" content=\"") |
|
| 279 | + | if templ_7745c5c3_Err != nil { |
|
| 280 | + | return templ_7745c5c3_Err |
|
| 281 | + | } |
|
| 282 | + | var templ_7745c5c3_Var15 string |
|
| 283 | + | templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(v.BlogDescription) |
|
| 284 | + | if templ_7745c5c3_Err != nil { |
|
| 285 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 43, Col: 60} |
|
| 286 | + | } |
|
| 287 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) |
|
| 288 | + | if templ_7745c5c3_Err != nil { |
|
| 289 | + | return templ_7745c5c3_Err |
|
| 290 | + | } |
|
| 291 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "\"><meta property=\"og:type\" content=\"website\"><meta property=\"og:url\" content=\"") |
|
| 292 | + | if templ_7745c5c3_Err != nil { |
|
| 293 | + | return templ_7745c5c3_Err |
|
| 294 | + | } |
|
| 295 | + | var templ_7745c5c3_Var16 string |
|
| 296 | + | templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(v.SiteURL) |
|
| 297 | + | if templ_7745c5c3_Err != nil { |
|
| 298 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 45, Col: 44} |
|
| 299 | + | } |
|
| 300 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) |
|
| 301 | + | if templ_7745c5c3_Err != nil { |
|
| 302 | + | return templ_7745c5c3_Err |
|
| 303 | + | } |
|
| 304 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "\">") |
|
| 305 | + | if templ_7745c5c3_Err != nil { |
|
| 306 | + | return templ_7745c5c3_Err |
|
| 307 | + | } |
|
| 308 | + | templ_7745c5c3_Err = ogImage(v.siteContext).Render(ctx, templ_7745c5c3_Buffer) |
|
| 309 | + | if templ_7745c5c3_Err != nil { |
|
| 310 | + | return templ_7745c5c3_Err |
|
| 311 | + | } |
|
| 312 | + | return nil |
|
| 313 | + | }) |
|
| 314 | + | } |
|
| 315 | + | ||
| 316 | + | func indexBody(v indexView) templ.Component { |
|
| 317 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 318 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 319 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 320 | + | return templ_7745c5c3_CtxErr |
|
| 321 | + | } |
|
| 322 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 323 | + | if !templ_7745c5c3_IsBuffer { |
|
| 324 | + | defer func() { |
|
| 325 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 326 | + | if templ_7745c5c3_Err == nil { |
|
| 327 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 328 | + | } |
|
| 329 | + | }() |
|
| 330 | + | } |
|
| 331 | + | ctx = templ.InitializeContext(ctx) |
|
| 332 | + | templ_7745c5c3_Var17 := templ.GetChildren(ctx) |
|
| 333 | + | if templ_7745c5c3_Var17 == nil { |
|
| 334 | + | templ_7745c5c3_Var17 = templ.NopComponent |
|
| 335 | + | } |
|
| 336 | + | ctx = templ.ClearChildren(ctx) |
|
| 337 | + | if v.IntroHTML != "" { |
|
| 338 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "<article class=\"intro markdown-body\">") |
|
| 339 | + | if templ_7745c5c3_Err != nil { |
|
| 340 | + | return templ_7745c5c3_Err |
|
| 341 | + | } |
|
| 342 | + | templ_7745c5c3_Err = templ.Raw(string(v.IntroHTML)).Render(ctx, templ_7745c5c3_Buffer) |
|
| 343 | + | if templ_7745c5c3_Err != nil { |
|
| 344 | + | return templ_7745c5c3_Err |
|
| 345 | + | } |
|
| 346 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "</article>") |
|
| 347 | + | if templ_7745c5c3_Err != nil { |
|
| 348 | + | return templ_7745c5c3_Err |
|
| 349 | + | } |
|
| 350 | + | } |
|
| 351 | + | if len(v.Posts) == 0 { |
|
| 352 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "<p class=\"empty\">no posts yet</p>") |
|
| 353 | + | if templ_7745c5c3_Err != nil { |
|
| 354 | + | return templ_7745c5c3_Err |
|
| 355 | + | } |
|
| 356 | + | } |
|
| 357 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "<div class=\"post-list\">") |
|
| 358 | + | if templ_7745c5c3_Err != nil { |
|
| 359 | + | return templ_7745c5c3_Err |
|
| 360 | + | } |
|
| 361 | + | for _, p := range v.Posts { |
|
| 362 | + | templ_7745c5c3_Err = postItem(p, "post-item").Render(ctx, templ_7745c5c3_Buffer) |
|
| 363 | + | if templ_7745c5c3_Err != nil { |
|
| 364 | + | return templ_7745c5c3_Err |
|
| 365 | + | } |
|
| 366 | + | } |
|
| 367 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "</div>") |
|
| 368 | + | if templ_7745c5c3_Err != nil { |
|
| 369 | + | return templ_7745c5c3_Err |
|
| 370 | + | } |
|
| 371 | + | return nil |
|
| 372 | + | }) |
|
| 373 | + | } |
|
| 374 | + | ||
| 375 | + | func postsMeta(v postsView) templ.Component { |
|
| 376 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 377 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 378 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 379 | + | return templ_7745c5c3_CtxErr |
|
| 380 | + | } |
|
| 381 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 382 | + | if !templ_7745c5c3_IsBuffer { |
|
| 383 | + | defer func() { |
|
| 384 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 385 | + | if templ_7745c5c3_Err == nil { |
|
| 386 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 387 | + | } |
|
| 388 | + | }() |
|
| 389 | + | } |
|
| 390 | + | ctx = templ.InitializeContext(ctx) |
|
| 391 | + | templ_7745c5c3_Var18 := templ.GetChildren(ctx) |
|
| 392 | + | if templ_7745c5c3_Var18 == nil { |
|
| 393 | + | templ_7745c5c3_Var18 = templ.NopComponent |
|
| 394 | + | } |
|
| 395 | + | ctx = templ.ClearChildren(ctx) |
|
| 396 | + | templ_7745c5c3_Err = ogImage(v.siteContext).Render(ctx, templ_7745c5c3_Buffer) |
|
| 397 | + | if templ_7745c5c3_Err != nil { |
|
| 398 | + | return templ_7745c5c3_Err |
|
| 399 | + | } |
|
| 400 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "<meta property=\"og:url\" content=\"") |
|
| 401 | + | if templ_7745c5c3_Err != nil { |
|
| 402 | + | return templ_7745c5c3_Err |
|
| 403 | + | } |
|
| 404 | + | var templ_7745c5c3_Var19 string |
|
| 405 | + | templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(v.SiteURL + "/posts") |
|
| 406 | + | if templ_7745c5c3_Err != nil { |
|
| 407 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 67, Col: 55} |
|
| 408 | + | } |
|
| 409 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) |
|
| 410 | + | if templ_7745c5c3_Err != nil { |
|
| 411 | + | return templ_7745c5c3_Err |
|
| 412 | + | } |
|
| 413 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "\">") |
|
| 414 | + | if templ_7745c5c3_Err != nil { |
|
| 415 | + | return templ_7745c5c3_Err |
|
| 416 | + | } |
|
| 417 | + | return nil |
|
| 418 | + | }) |
|
| 419 | + | } |
|
| 420 | + | ||
| 421 | + | func postsBody(v postsView) templ.Component { |
|
| 422 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 423 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 424 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 425 | + | return templ_7745c5c3_CtxErr |
|
| 426 | + | } |
|
| 427 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 428 | + | if !templ_7745c5c3_IsBuffer { |
|
| 429 | + | defer func() { |
|
| 430 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 431 | + | if templ_7745c5c3_Err == nil { |
|
| 432 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 433 | + | } |
|
| 434 | + | }() |
|
| 435 | + | } |
|
| 436 | + | ctx = templ.InitializeContext(ctx) |
|
| 437 | + | templ_7745c5c3_Var20 := templ.GetChildren(ctx) |
|
| 438 | + | if templ_7745c5c3_Var20 == nil { |
|
| 439 | + | templ_7745c5c3_Var20 = templ.NopComponent |
|
| 440 | + | } |
|
| 441 | + | ctx = templ.ClearChildren(ctx) |
|
| 442 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "<h1>Posts</h1>") |
|
| 443 | + | if templ_7745c5c3_Err != nil { |
|
| 444 | + | return templ_7745c5c3_Err |
|
| 445 | + | } |
|
| 446 | + | if len(v.Posts) == 0 { |
|
| 447 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "<p class=\"empty\">no posts yet</p>") |
|
| 448 | + | if templ_7745c5c3_Err != nil { |
|
| 449 | + | return templ_7745c5c3_Err |
|
| 450 | + | } |
|
| 451 | + | } |
|
| 452 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "<div class=\"post-list\">") |
|
| 453 | + | if templ_7745c5c3_Err != nil { |
|
| 454 | + | return templ_7745c5c3_Err |
|
| 455 | + | } |
|
| 456 | + | for _, p := range v.Posts { |
|
| 457 | + | templ_7745c5c3_Err = postItem(p, "post-item post-item-enhanced").Render(ctx, templ_7745c5c3_Buffer) |
|
| 458 | + | if templ_7745c5c3_Err != nil { |
|
| 459 | + | return templ_7745c5c3_Err |
|
| 460 | + | } |
|
| 461 | + | } |
|
| 462 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "</div>") |
|
| 463 | + | if templ_7745c5c3_Err != nil { |
|
| 464 | + | return templ_7745c5c3_Err |
|
| 465 | + | } |
|
| 466 | + | return nil |
|
| 467 | + | }) |
|
| 468 | + | } |
|
| 469 | + | ||
| 470 | + | func pageMeta(v pageView) templ.Component { |
|
| 471 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 472 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 473 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 474 | + | return templ_7745c5c3_CtxErr |
|
| 475 | + | } |
|
| 476 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 477 | + | if !templ_7745c5c3_IsBuffer { |
|
| 478 | + | defer func() { |
|
| 479 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 480 | + | if templ_7745c5c3_Err == nil { |
|
| 481 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 482 | + | } |
|
| 483 | + | }() |
|
| 484 | + | } |
|
| 485 | + | ctx = templ.InitializeContext(ctx) |
|
| 486 | + | templ_7745c5c3_Var21 := templ.GetChildren(ctx) |
|
| 487 | + | if templ_7745c5c3_Var21 == nil { |
|
| 488 | + | templ_7745c5c3_Var21 = templ.NopComponent |
|
| 489 | + | } |
|
| 490 | + | ctx = templ.ClearChildren(ctx) |
|
| 491 | + | templ_7745c5c3_Err = ogImage(v.siteContext).Render(ctx, templ_7745c5c3_Buffer) |
|
| 492 | + | if templ_7745c5c3_Err != nil { |
|
| 493 | + | return templ_7745c5c3_Err |
|
| 494 | + | } |
|
| 495 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "<meta property=\"og:url\" content=\"") |
|
| 496 | + | if templ_7745c5c3_Err != nil { |
|
| 497 | + | return templ_7745c5c3_Err |
|
| 498 | + | } |
|
| 499 | + | var templ_7745c5c3_Var22 string |
|
| 500 | + | templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(v.SiteURL + "/" + v.Page.Slug) |
|
| 501 | + | if templ_7745c5c3_Err != nil { |
|
| 502 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 84, Col: 64} |
|
| 503 | + | } |
|
| 504 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22)) |
|
| 505 | + | if templ_7745c5c3_Err != nil { |
|
| 506 | + | return templ_7745c5c3_Err |
|
| 507 | + | } |
|
| 508 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "\">") |
|
| 509 | + | if templ_7745c5c3_Err != nil { |
|
| 510 | + | return templ_7745c5c3_Err |
|
| 511 | + | } |
|
| 512 | + | return nil |
|
| 513 | + | }) |
|
| 514 | + | } |
|
| 515 | + | ||
| 516 | + | func pageBody(v pageView) templ.Component { |
|
| 517 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 518 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 519 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 520 | + | return templ_7745c5c3_CtxErr |
|
| 521 | + | } |
|
| 522 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 523 | + | if !templ_7745c5c3_IsBuffer { |
|
| 524 | + | defer func() { |
|
| 525 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 526 | + | if templ_7745c5c3_Err == nil { |
|
| 527 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 528 | + | } |
|
| 529 | + | }() |
|
| 530 | + | } |
|
| 531 | + | ctx = templ.InitializeContext(ctx) |
|
| 532 | + | templ_7745c5c3_Var23 := templ.GetChildren(ctx) |
|
| 533 | + | if templ_7745c5c3_Var23 == nil { |
|
| 534 | + | templ_7745c5c3_Var23 = templ.NopComponent |
|
| 535 | + | } |
|
| 536 | + | ctx = templ.ClearChildren(ctx) |
|
| 537 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "<div class=\"page-header\"><h1>") |
|
| 538 | + | if templ_7745c5c3_Err != nil { |
|
| 539 | + | return templ_7745c5c3_Err |
|
| 540 | + | } |
|
| 541 | + | var templ_7745c5c3_Var24 string |
|
| 542 | + | templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(v.Page.Title) |
|
| 543 | + | if templ_7745c5c3_Err != nil { |
|
| 544 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 89, Col: 20} |
|
| 545 | + | } |
|
| 546 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24)) |
|
| 547 | + | if templ_7745c5c3_Err != nil { |
|
| 548 | + | return templ_7745c5c3_Err |
|
| 549 | + | } |
|
| 550 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "</h1></div><article class=\"markdown-body\">") |
|
| 551 | + | if templ_7745c5c3_Err != nil { |
|
| 552 | + | return templ_7745c5c3_Err |
|
| 553 | + | } |
|
| 554 | + | templ_7745c5c3_Err = templ.Raw(string(v.RenderedContent)).Render(ctx, templ_7745c5c3_Buffer) |
|
| 555 | + | if templ_7745c5c3_Err != nil { |
|
| 556 | + | return templ_7745c5c3_Err |
|
| 557 | + | } |
|
| 558 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "</article>") |
|
| 559 | + | if templ_7745c5c3_Err != nil { |
|
| 560 | + | return templ_7745c5c3_Err |
|
| 561 | + | } |
|
| 562 | + | return nil |
|
| 563 | + | }) |
|
| 564 | + | } |
|
| 565 | + | ||
| 566 | + | func postMeta(v postView) templ.Component { |
|
| 567 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 568 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 569 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 570 | + | return templ_7745c5c3_CtxErr |
|
| 571 | + | } |
|
| 572 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 573 | + | if !templ_7745c5c3_IsBuffer { |
|
| 574 | + | defer func() { |
|
| 575 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 576 | + | if templ_7745c5c3_Err == nil { |
|
| 577 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 578 | + | } |
|
| 579 | + | }() |
|
| 580 | + | } |
|
| 581 | + | ctx = templ.InitializeContext(ctx) |
|
| 582 | + | templ_7745c5c3_Var25 := templ.GetChildren(ctx) |
|
| 583 | + | if templ_7745c5c3_Var25 == nil { |
|
| 584 | + | templ_7745c5c3_Var25 = templ.NopComponent |
|
| 585 | + | } |
|
| 586 | + | ctx = templ.ClearChildren(ctx) |
|
| 587 | + | if v.Post.MetaDescription != nil { |
|
| 588 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "<meta name=\"description\" content=\"") |
|
| 589 | + | if templ_7745c5c3_Err != nil { |
|
| 590 | + | return templ_7745c5c3_Err |
|
| 591 | + | } |
|
| 592 | + | var templ_7745c5c3_Var26 string |
|
| 593 | + | templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(v.Post.MetaDescriptionStr()) |
|
| 594 | + | if templ_7745c5c3_Err != nil { |
|
| 595 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 98, Col: 64} |
|
| 596 | + | } |
|
| 597 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) |
|
| 598 | + | if templ_7745c5c3_Err != nil { |
|
| 599 | + | return templ_7745c5c3_Err |
|
| 600 | + | } |
|
| 601 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "\"><meta property=\"og:description\" content=\"") |
|
| 602 | + | if templ_7745c5c3_Err != nil { |
|
| 603 | + | return templ_7745c5c3_Err |
|
| 604 | + | } |
|
| 605 | + | var templ_7745c5c3_Var27 string |
|
| 606 | + | templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(v.Post.MetaDescriptionStr()) |
|
| 607 | + | if templ_7745c5c3_Err != nil { |
|
| 608 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 99, Col: 71} |
|
| 609 | + | } |
|
| 610 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) |
|
| 611 | + | if templ_7745c5c3_Err != nil { |
|
| 612 | + | return templ_7745c5c3_Err |
|
| 613 | + | } |
|
| 614 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "\">") |
|
| 615 | + | if templ_7745c5c3_Err != nil { |
|
| 616 | + | return templ_7745c5c3_Err |
|
| 617 | + | } |
|
| 618 | + | } |
|
| 619 | + | if v.Post.MetaImageStr() != "" { |
|
| 620 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "<meta property=\"og:image\" content=\"") |
|
| 621 | + | if templ_7745c5c3_Err != nil { |
|
| 622 | + | return templ_7745c5c3_Err |
|
| 623 | + | } |
|
| 624 | + | var templ_7745c5c3_Var28 string |
|
| 625 | + | templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(v.Post.MetaImageStr()) |
|
| 626 | + | if templ_7745c5c3_Err != nil { |
|
| 627 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 102, Col: 59} |
|
| 628 | + | } |
|
| 629 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28)) |
|
| 630 | + | if templ_7745c5c3_Err != nil { |
|
| 631 | + | return templ_7745c5c3_Err |
|
| 632 | + | } |
|
| 633 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "\">") |
|
| 634 | + | if templ_7745c5c3_Err != nil { |
|
| 635 | + | return templ_7745c5c3_Err |
|
| 636 | + | } |
|
| 637 | + | } else { |
|
| 638 | + | templ_7745c5c3_Err = ogImage(v.siteContext).Render(ctx, templ_7745c5c3_Buffer) |
|
| 639 | + | if templ_7745c5c3_Err != nil { |
|
| 640 | + | return templ_7745c5c3_Err |
|
| 641 | + | } |
|
| 642 | + | } |
|
| 643 | + | if v.Post.CanonicalURL != nil { |
|
| 644 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "<link rel=\"canonical\" href=\"") |
|
| 645 | + | if templ_7745c5c3_Err != nil { |
|
| 646 | + | return templ_7745c5c3_Err |
|
| 647 | + | } |
|
| 648 | + | var templ_7745c5c3_Var29 templ.SafeURL |
|
| 649 | + | templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinURLErrs(templ.URL(v.Post.CanonicalURLStr())) |
|
| 650 | + | if templ_7745c5c3_Err != nil { |
|
| 651 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 107, Col: 66} |
|
| 652 | + | } |
|
| 653 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29)) |
|
| 654 | + | if templ_7745c5c3_Err != nil { |
|
| 655 | + | return templ_7745c5c3_Err |
|
| 656 | + | } |
|
| 657 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "\">") |
|
| 658 | + | if templ_7745c5c3_Err != nil { |
|
| 659 | + | return templ_7745c5c3_Err |
|
| 660 | + | } |
|
| 661 | + | } |
|
| 662 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "<meta property=\"og:title\" content=\"") |
|
| 663 | + | if templ_7745c5c3_Err != nil { |
|
| 664 | + | return templ_7745c5c3_Err |
|
| 665 | + | } |
|
| 666 | + | var templ_7745c5c3_Var30 string |
|
| 667 | + | templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(v.Post.DisplayTitle()) |
|
| 668 | + | if templ_7745c5c3_Err != nil { |
|
| 669 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 109, Col: 58} |
|
| 670 | + | } |
|
| 671 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30)) |
|
| 672 | + | if templ_7745c5c3_Err != nil { |
|
| 673 | + | return templ_7745c5c3_Err |
|
| 674 | + | } |
|
| 675 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "\"><meta property=\"og:type\" content=\"article\"><meta property=\"og:url\" content=\"") |
|
| 676 | + | if templ_7745c5c3_Err != nil { |
|
| 677 | + | return templ_7745c5c3_Err |
|
| 678 | + | } |
|
| 679 | + | var templ_7745c5c3_Var31 string |
|
| 680 | + | templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(v.SiteURL + "/posts/" + v.Post.Slug) |
|
| 681 | + | if templ_7745c5c3_Err != nil { |
|
| 682 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 111, Col: 70} |
|
| 683 | + | } |
|
| 684 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31)) |
|
| 685 | + | if templ_7745c5c3_Err != nil { |
|
| 686 | + | return templ_7745c5c3_Err |
|
| 687 | + | } |
|
| 688 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "\"><meta property=\"article:published_time\" content=\"") |
|
| 689 | + | if templ_7745c5c3_Err != nil { |
|
| 690 | + | return templ_7745c5c3_Err |
|
| 691 | + | } |
|
| 692 | + | var templ_7745c5c3_Var32 string |
|
| 693 | + | templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(v.Post.PublishedDateStr()) |
|
| 694 | + | if templ_7745c5c3_Err != nil { |
|
| 695 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 112, Col: 76} |
|
| 696 | + | } |
|
| 697 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) |
|
| 698 | + | if templ_7745c5c3_Err != nil { |
|
| 699 | + | return templ_7745c5c3_Err |
|
| 700 | + | } |
|
| 701 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "\">") |
|
| 702 | + | if templ_7745c5c3_Err != nil { |
|
| 703 | + | return templ_7745c5c3_Err |
|
| 704 | + | } |
|
| 705 | + | return nil |
|
| 706 | + | }) |
|
| 707 | + | } |
|
| 708 | + | ||
| 709 | + | // The location icon is from Phosphor Icons: |
|
| 710 | + | // https://github.com/phosphor-icons/core/blob/main/LICENSE |
|
| 711 | + | func postBody(v postView) templ.Component { |
|
| 712 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
|
| 713 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
|
| 714 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
|
| 715 | + | return templ_7745c5c3_CtxErr |
|
| 716 | + | } |
|
| 717 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
|
| 718 | + | if !templ_7745c5c3_IsBuffer { |
|
| 719 | + | defer func() { |
|
| 720 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
|
| 721 | + | if templ_7745c5c3_Err == nil { |
|
| 722 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr |
|
| 723 | + | } |
|
| 724 | + | }() |
|
| 725 | + | } |
|
| 726 | + | ctx = templ.InitializeContext(ctx) |
|
| 727 | + | templ_7745c5c3_Var33 := templ.GetChildren(ctx) |
|
| 728 | + | if templ_7745c5c3_Var33 == nil { |
|
| 729 | + | templ_7745c5c3_Var33 = templ.NopComponent |
|
| 730 | + | } |
|
| 731 | + | ctx = templ.ClearChildren(ctx) |
|
| 732 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "<div class=\"post-header\">") |
|
| 733 | + | if templ_7745c5c3_Err != nil { |
|
| 734 | + | return templ_7745c5c3_Err |
|
| 735 | + | } |
|
| 736 | + | if v.Post.HasTitle() { |
|
| 737 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "<h1>") |
|
| 738 | + | if templ_7745c5c3_Err != nil { |
|
| 739 | + | return templ_7745c5c3_Err |
|
| 740 | + | } |
|
| 741 | + | var templ_7745c5c3_Var34 string |
|
| 742 | + | templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(v.Post.TitleStr()) |
|
| 743 | + | if templ_7745c5c3_Err != nil { |
|
| 744 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 120, Col: 26} |
|
| 745 | + | } |
|
| 746 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34)) |
|
| 747 | + | if templ_7745c5c3_Err != nil { |
|
| 748 | + | return templ_7745c5c3_Err |
|
| 749 | + | } |
|
| 750 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "</h1>") |
|
| 751 | + | if templ_7745c5c3_Err != nil { |
|
| 752 | + | return templ_7745c5c3_Err |
|
| 753 | + | } |
|
| 754 | + | } |
|
| 755 | + | if v.Post.MetaDescription != nil { |
|
| 756 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "<p class=\"post-description\">") |
|
| 757 | + | if templ_7745c5c3_Err != nil { |
|
| 758 | + | return templ_7745c5c3_Err |
|
| 759 | + | } |
|
| 760 | + | var templ_7745c5c3_Var35 string |
|
| 761 | + | templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(v.Post.MetaDescriptionStr()) |
|
| 762 | + | if templ_7745c5c3_Err != nil { |
|
| 763 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 123, Col: 60} |
|
| 764 | + | } |
|
| 765 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35)) |
|
| 766 | + | if templ_7745c5c3_Err != nil { |
|
| 767 | + | return templ_7745c5c3_Err |
|
| 768 | + | } |
|
| 769 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "</p>") |
|
| 770 | + | if templ_7745c5c3_Err != nil { |
|
| 771 | + | return templ_7745c5c3_Err |
|
| 772 | + | } |
|
| 773 | + | } |
|
| 774 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "<div class=\"post-weather\">") |
|
| 775 | + | if templ_7745c5c3_Err != nil { |
|
| 776 | + | return templ_7745c5c3_Err |
|
| 777 | + | } |
|
| 778 | + | if v.Post.PublishedDate != nil { |
|
| 779 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "<span><time class=\"post-date\">") |
|
| 780 | + | if templ_7745c5c3_Err != nil { |
|
| 781 | + | return templ_7745c5c3_Err |
|
| 782 | + | } |
|
| 783 | + | var templ_7745c5c3_Var36 string |
|
| 784 | + | templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(v.Post.PublishedDateStr()) |
|
| 785 | + | if templ_7745c5c3_Err != nil { |
|
| 786 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 128, Col: 56} |
|
| 787 | + | } |
|
| 788 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36)) |
|
| 789 | + | if templ_7745c5c3_Err != nil { |
|
| 790 | + | return templ_7745c5c3_Err |
|
| 791 | + | } |
|
| 792 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "</time></span> <span>•</span> ") |
|
| 793 | + | if templ_7745c5c3_Err != nil { |
|
| 794 | + | return templ_7745c5c3_Err |
|
| 795 | + | } |
|
| 796 | + | } |
|
| 797 | + | if v.Post.Weather != nil { |
|
| 798 | + | templ_7745c5c3_Err = templ.Raw(string(v.Weather.Icon)).Render(ctx, templ_7745c5c3_Buffer) |
|
| 799 | + | if templ_7745c5c3_Err != nil { |
|
| 800 | + | return templ_7745c5c3_Err |
|
| 801 | + | } |
|
| 802 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, " <p class=\"weather-conditions\">") |
|
| 803 | + | if templ_7745c5c3_Err != nil { |
|
| 804 | + | return templ_7745c5c3_Err |
|
| 805 | + | } |
|
| 806 | + | var templ_7745c5c3_Var37 string |
|
| 807 | + | templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(v.Weather.Conditions) |
|
| 808 | + | if templ_7745c5c3_Err != nil { |
|
| 809 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 134, Col: 56} |
|
| 810 | + | } |
|
| 811 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37)) |
|
| 812 | + | if templ_7745c5c3_Err != nil { |
|
| 813 | + | return templ_7745c5c3_Err |
|
| 814 | + | } |
|
| 815 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "</p><p class=\"weather-temp\">") |
|
| 816 | + | if templ_7745c5c3_Err != nil { |
|
| 817 | + | return templ_7745c5c3_Err |
|
| 818 | + | } |
|
| 819 | + | var templ_7745c5c3_Var38 string |
|
| 820 | + | templ_7745c5c3_Var38, templ_7745c5c3_Err = templ.JoinStringErrs(v.Weather.Temperature) |
|
| 821 | + | if templ_7745c5c3_Err != nil { |
|
| 822 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 135, Col: 51} |
|
| 823 | + | } |
|
| 824 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var38)) |
|
| 825 | + | if templ_7745c5c3_Err != nil { |
|
| 826 | + | return templ_7745c5c3_Err |
|
| 827 | + | } |
|
| 828 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "</p>•<div class=\"weather-location\"><svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\"><path fill=\"currentColor\" d=\"M128 68a36 36 0 1 0 36 36a36 36 0 0 0-36-36m0 64a28 28 0 1 1 28-28a28 28 0 0 1-28 28m0-112a84.09 84.09 0 0 0-84 84c0 30.42 14.17 62.79 41 93.62a250 250 0 0 0 40.73 37.66a4 4 0 0 0 4.58 0A250 250 0 0 0 171 197.62c26.81-30.83 41-63.2 41-93.62a84.09 84.09 0 0 0-84-84m37.1 172.23A254.6 254.6 0 0 1 128 227a254.6 254.6 0 0 1-37.1-34.81C73.15 171.8 52 139.9 52 104a76 76 0 0 1 152 0c0 35.9-21.15 67.8-38.9 88.23\"></path></svg><p>") |
|
| 829 | + | if templ_7745c5c3_Err != nil { |
|
| 830 | + | return templ_7745c5c3_Err |
|
| 831 | + | } |
|
| 832 | + | var templ_7745c5c3_Var39 string |
|
| 833 | + | templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(v.Weather.Location) |
|
| 834 | + | if templ_7745c5c3_Err != nil { |
|
| 835 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 139, Col: 28} |
|
| 836 | + | } |
|
| 837 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var39)) |
|
| 838 | + | if templ_7745c5c3_Err != nil { |
|
| 839 | + | return templ_7745c5c3_Err |
|
| 840 | + | } |
|
| 841 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "</p></div>") |
|
| 842 | + | if templ_7745c5c3_Err != nil { |
|
| 843 | + | return templ_7745c5c3_Err |
|
| 844 | + | } |
|
| 845 | + | } |
|
| 846 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "</div>") |
|
| 847 | + | if templ_7745c5c3_Err != nil { |
|
| 848 | + | return templ_7745c5c3_Err |
|
| 849 | + | } |
|
| 850 | + | if len(v.Post.TagList()) > 0 { |
|
| 851 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "<div class=\"post-tags\">") |
|
| 852 | + | if templ_7745c5c3_Err != nil { |
|
| 853 | + | return templ_7745c5c3_Err |
|
| 854 | + | } |
|
| 855 | + | for _, t := range v.Post.TagList() { |
|
| 856 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "<span class=\"tag\">") |
|
| 857 | + | if templ_7745c5c3_Err != nil { |
|
| 858 | + | return templ_7745c5c3_Err |
|
| 859 | + | } |
|
| 860 | + | var templ_7745c5c3_Var40 string |
|
| 861 | + | templ_7745c5c3_Var40, templ_7745c5c3_Err = templ.JoinStringErrs(t) |
|
| 862 | + | if templ_7745c5c3_Err != nil { |
|
| 863 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `public.templ`, Line: 146, Col: 26} |
|
| 864 | + | } |
|
| 865 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var40)) |
|
| 866 | + | if templ_7745c5c3_Err != nil { |
|
| 867 | + | return templ_7745c5c3_Err |
|
| 868 | + | } |
|
| 869 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "</span>") |
|
| 870 | + | if templ_7745c5c3_Err != nil { |
|
| 871 | + | return templ_7745c5c3_Err |
|
| 872 | + | } |
|
| 873 | + | } |
|
| 874 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "</div>") |
|
| 875 | + | if templ_7745c5c3_Err != nil { |
|
| 876 | + | return templ_7745c5c3_Err |
|
| 877 | + | } |
|
| 878 | + | } |
|
| 879 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "</div><article class=\"markdown-body\">") |
|
| 880 | + | if templ_7745c5c3_Err != nil { |
|
| 881 | + | return templ_7745c5c3_Err |
|
| 882 | + | } |
|
| 883 | + | templ_7745c5c3_Err = templ.Raw(string(v.RenderedContent)).Render(ctx, templ_7745c5c3_Buffer) |
|
| 884 | + | if templ_7745c5c3_Err != nil { |
|
| 885 | + | return templ_7745c5c3_Err |
|
| 886 | + | } |
|
| 887 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, "</article>") |
|
| 888 | + | if templ_7745c5c3_Err != nil { |
|
| 889 | + | return templ_7745c5c3_Err |
|
| 890 | + | } |
|
| 891 | + | return nil |
|
| 892 | + | }) |
|
| 893 | + | } |
|
| 894 | + | ||
| 895 | + | var _ = templruntime.GeneratedTemplate |
| 20 | 20 | out := make(map[string]*template.Template, len(pages)) |
|
| 21 | 21 | for _, page := range pages { |
|
| 22 | 22 | name := path.Base(page) |
|
| 23 | - | if name == "base.html" || name == "admin_base.html" { |
|
| 23 | + | if name == "admin_base.html" { |
|
| 24 | 24 | continue |
|
| 25 | 25 | } |
|
| 26 | 26 | ||
| 27 | + | // Public pages are templ components (see *.templ); what's left here is |
|
| 28 | + | // the admin UI plus the standalone login page. |
|
| 27 | 29 | patterns := []string{page} |
|
| 28 | - | switch { |
|
| 29 | - | case strings.HasPrefix(name, "admin_"): |
|
| 30 | + | if strings.HasPrefix(name, "admin_") { |
|
| 30 | 31 | patterns = append([]string{"templates/admin_base.html"}, patterns...) |
|
| 31 | - | case name == "login.html": |
|
| 32 | - | // standalone template |
|
| 33 | - | default: |
|
| 34 | - | patterns = append([]string{"templates/base.html"}, patterns...) |
|
| 35 | 32 | } |
|
| 36 | 33 | ||
| 37 | 34 | tmpl, err := template.ParseFS(appFS, patterns...) |
| 69 | 69 | mux.HandleFunc("GET /admin/settings", requireSession(a.adminGetSettings)) |
|
| 70 | 70 | mux.HandleFunc("POST /admin/settings", requireSession(a.adminPostSettings)) |
|
| 71 | 71 | ||
| 72 | + | // Templates |
|
| 73 | + | mux.HandleFunc("GET /admin/templates", requireSession(a.adminGetTemplates)) |
|
| 74 | + | mux.HandleFunc("POST /admin/templates/{kind}", requireSession(a.adminPostTemplate)) |
|
| 75 | + | ||
| 72 | 76 | // Downloads |
|
| 73 | 77 | mux.HandleFunc("GET /admin/downloads/posts", requireSession(a.adminDownloadPosts)) |
|
| 74 | 78 | mux.HandleFunc("GET /admin/downloads/uploads", requireSession(a.adminDownloadUploads)) |
| 1 | + | {{if .IntroHTML}} |
|
| 2 | + | <article class="intro markdown-body"> |
|
| 3 | + | {{.IntroHTML}} |
|
| 4 | + | </article> |
|
| 5 | + | {{end}} |
|
| 6 | + | {{if not .Posts}} |
|
| 7 | + | <p class="empty">no posts yet</p> |
|
| 8 | + | {{end}} |
|
| 9 | + | <div class="post-list"> |
|
| 10 | + | {{range .Posts}} |
|
| 11 | + | <a href="/posts/{{.Slug}}" class="post-item"> |
|
| 12 | + | <div class="post-item-info"> |
|
| 13 | + | <span class="post-title">{{.DisplayTitle}}</span> |
|
| 14 | + | </div> |
|
| 15 | + | {{if .PublishedDate}} |
|
| 16 | + | <time class="post-date">{{.PublishedDateStr}}</time> |
|
| 17 | + | {{end}} |
|
| 18 | + | </a> |
|
| 19 | + | {{end}} |
|
| 20 | + | </div> |
| 1 | + | <div class="page-header"> |
|
| 2 | + | <h1>{{.Page.Title}}</h1> |
|
| 3 | + | </div> |
|
| 4 | + | <article class="markdown-body"> |
|
| 5 | + | {{.RenderedContent}} |
|
| 6 | + | </article> |
| 1 | + | <div class="post-header"> |
|
| 2 | + | {{if .Post.HasTitle}} |
|
| 3 | + | <h1>{{.Post.TitleStr}}</h1> |
|
| 4 | + | {{end}} |
|
| 5 | + | {{if .Post.MetaDescription}} |
|
| 6 | + | <p class="post-description">{{.Post.MetaDescriptionStr}}</p> |
|
| 7 | + | {{end}} |
|
| 8 | + | <div class="post-weather"> |
|
| 9 | + | {{if .Post.PublishedDate}} |
|
| 10 | + | <span> |
|
| 11 | + | <time class="post-date">{{.Post.PublishedDateStr}}</time> |
|
| 12 | + | </span> |
|
| 13 | + | <span>•</span> |
|
| 14 | + | {{end}} |
|
| 15 | + | {{if .Post.Weather}} |
|
| 16 | + | {{.Weather.Icon}} |
|
| 17 | + | <p class="weather-conditions">{{.Weather.Conditions}}</p> |
|
| 18 | + | <p class="weather-temp">{{.Weather.Temperature}}</p> |
|
| 19 | + | • |
|
| 20 | + | <div class="weather-location"> |
|
| 21 | + | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><path fill="currentColor" d="M128 68a36 36 0 1 0 36 36a36 36 0 0 0-36-36m0 64a28 28 0 1 1 28-28a28 28 0 0 1-28 28m0-112a84.09 84.09 0 0 0-84 84c0 30.42 14.17 62.79 41 93.62a250 250 0 0 0 40.73 37.66a4 4 0 0 0 4.58 0A250 250 0 0 0 171 197.62c26.81-30.83 41-63.2 41-93.62a84.09 84.09 0 0 0-84-84m37.1 172.23A254.6 254.6 0 0 1 128 227a254.6 254.6 0 0 1-37.1-34.81C73.15 171.8 52 139.9 52 104a76 76 0 0 1 152 0c0 35.9-21.15 67.8-38.9 88.23"></path></svg> |
|
| 22 | + | <p>{{.Weather.Location}}</p> |
|
| 23 | + | </div> |
|
| 24 | + | {{end}} |
|
| 25 | + | </div> |
|
| 26 | + | {{if .Post.TagList}} |
|
| 27 | + | <div class="post-tags"> |
|
| 28 | + | {{range .Post.TagList}} |
|
| 29 | + | <span class="tag">{{.}}</span> |
|
| 30 | + | {{end}} |
|
| 31 | + | </div> |
|
| 32 | + | {{end}} |
|
| 33 | + | </div> |
|
| 34 | + | <article class="markdown-body"> |
|
| 35 | + | {{.RenderedContent}} |
|
| 36 | + | </article> |
| 1 | + | <h1>Posts</h1> |
|
| 2 | + | {{if not .Posts}} |
|
| 3 | + | <p class="empty">no posts yet</p> |
|
| 4 | + | {{end}} |
|
| 5 | + | <div class="post-list"> |
|
| 6 | + | {{range .Posts}} |
|
| 7 | + | <a href="/posts/{{.Slug}}" class="post-item post-item-enhanced"> |
|
| 8 | + | <div class="post-item-info"> |
|
| 9 | + | <span class="post-title">{{.DisplayTitle}}</span> |
|
| 10 | + | </div> |
|
| 11 | + | {{if .PublishedDate}} |
|
| 12 | + | <time class="post-date">{{.PublishedDateStr}}</time> |
|
| 13 | + | {{end}} |
|
| 14 | + | </a> |
|
| 15 | + | {{end}} |
|
| 16 | + | </div> |
| 37 | 37 | opacity: 0.6; |
|
| 38 | 38 | } |
|
| 39 | 39 | ||
| 40 | + | .template-tabs .btn[aria-current] { |
|
| 41 | + | opacity: 0.5; |
|
| 42 | + | pointer-events: none; |
|
| 43 | + | } |
|
| 44 | + | ||
| 40 | 45 | /* Post list (public) */ |
|
| 41 | 46 | ||
| 42 | 47 | .post-list { |
| 17 | 17 | <a href="/admin/pages">pages</a> |
|
| 18 | 18 | <a href="/admin/files">files</a> |
|
| 19 | 19 | <a href="/admin/import">import</a> |
|
| 20 | + | <a href="/admin/templates">templates</a> |
|
| 20 | 21 | <a href="/admin/settings">settings</a> |
|
| 21 | 22 | <a href="/" target="_blank">view site</a> |
|
| 22 | 23 | <a href="/admin/logout">logout</a> |
| 1 | + | {{define "admin_templates.html"}}{{template "admin_base.html" .}}{{end}} |
|
| 2 | + | {{define "title"}}Admin — Templates{{end}} |
|
| 3 | + | {{define "content"}} |
|
| 4 | + | <h2>Templates</h2> |
|
| 5 | + | <nav class="form-actions template-tabs"> |
|
| 6 | + | {{range .Kinds}} |
|
| 7 | + | <a href="/admin/templates?t={{.Kind}}" class="btn" {{if eq .Kind $.Kind}}aria-current="page"{{end}}>{{.Label}}</a> |
|
| 8 | + | {{end}} |
|
| 9 | + | </nav> |
|
| 10 | + | {{if .Success}}<p class="success">Template saved.</p>{{end}} |
|
| 11 | + | {{if .Error}}<p class="error">{{.Error}}</p>{{end}} |
|
| 12 | + | <form method="POST" action="/admin/templates/{{.Kind}}" class="form"> |
|
| 13 | + | <div class="switch-row"> |
|
| 14 | + | <label class="switch"> |
|
| 15 | + | <input type="checkbox" id="custom_template_toggle" {{if .Custom}}checked{{end}}> |
|
| 16 | + | <span class="switch-slider"></span> |
|
| 17 | + | </label> |
|
| 18 | + | <span class="switch-label">custom template</span> |
|
| 19 | + | </div> |
|
| 20 | + | <div id="custom_template_section" {{if not .Custom}}class="hidden"{{end}}> |
|
| 21 | + | <label for="template">page body (Go html/template, replaces the default content inside <main>)</label> |
|
| 22 | + | <textarea id="template" name="template" class="post-content">{{.Template}}</textarea> |
|
| 23 | + | <details class="available-fields"> |
|
| 24 | + | <summary>available fields</summary> |
|
| 25 | + | <div class="fields-list"> |
|
| 26 | + | <span>.BlogTitle, .SiteURL, .FaviconURL, .OGImageURL</span> |
|
| 27 | + | <span>.NavLinks (range: .Label, .URL)</span> |
|
| 28 | + | <span>.HeaderHTML, .FooterHTML</span> |
|
| 29 | + | {{if eq .Kind "index"}} |
|
| 30 | + | <span>.BlogDescription</span> |
|
| 31 | + | <span>.IntroHTML</span> |
|
| 32 | + | <span>.Posts (range: see post fields)</span> |
|
| 33 | + | {{else if eq .Kind "posts"}} |
|
| 34 | + | <span>.Posts (range: see post fields)</span> |
|
| 35 | + | {{else if eq .Kind "page"}} |
|
| 36 | + | <span>.Page.Title, .Page.Slug, .Page.Content, .Page.CreatedAt, .Page.UpdatedAt</span> |
|
| 37 | + | <span>.RenderedContent</span> |
|
| 38 | + | {{else if eq .Kind "post"}} |
|
| 39 | + | <span>.Post (see post fields)</span> |
|
| 40 | + | <span>.RenderedContent</span> |
|
| 41 | + | <span>.Weather.Icon, .Weather.Conditions, .Weather.Temperature, .Weather.Location</span> |
|
| 42 | + | {{end}} |
|
| 43 | + | {{if ne .Kind "page"}} |
|
| 44 | + | <span>post fields: .Slug, .DisplayTitle, .TitleStr, .HasTitle, .PublishedDateStr, .MetaDescriptionStr, .MetaImageStr, .CanonicalURLStr, .TagList, .Lang, .Content</span> |
|
| 45 | + | {{end}} |
|
| 46 | + | </div> |
|
| 47 | + | </details> |
|
| 48 | + | </div> |
|
| 49 | + | <button type="submit">save</button> |
|
| 50 | + | </form> |
|
| 51 | + | <script> |
|
| 52 | + | var toggle = document.getElementById('custom_template_toggle'); |
|
| 53 | + | var section = document.getElementById('custom_template_section'); |
|
| 54 | + | var textarea = document.getElementById('template'); |
|
| 55 | + | toggle.addEventListener('change', function() { |
|
| 56 | + | section.classList.toggle('hidden', !this.checked); |
|
| 57 | + | }); |
|
| 58 | + | document.querySelector('form').addEventListener('submit', function() { |
|
| 59 | + | if (!toggle.checked) { textarea.value = ''; } |
|
| 60 | + | }); |
|
| 61 | + | </script> |
|
| 62 | + | {{end}} |
| 1 | - | {{define "base.html"}}<!DOCTYPE html> |
|
| 2 | - | <html lang="en"> |
|
| 3 | - | <head> |
|
| 4 | - | <meta charset="UTF-8"> |
|
| 5 | - | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
| 6 | - | <title>{{block "title" .}}{{.BlogTitle}}{{end}}</title> |
|
| 7 | - | {{if .FaviconURL}} |
|
| 8 | - | <link rel="apple-touch-icon" sizes="180x180" href="{{.FaviconURL}}"> |
|
| 9 | - | <link rel="icon" type="image/png" sizes="32x32" href="{{.FaviconURL}}"> |
|
| 10 | - | <link rel="icon" type="image/png" sizes="16x16" href="{{.FaviconURL}}"> |
|
| 11 | - | {{else}} |
|
| 12 | - | <link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png"> |
|
| 13 | - | <link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png"> |
|
| 14 | - | <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png"> |
|
| 15 | - | <link rel="manifest" href="/static/site.webmanifest"> |
|
| 16 | - | {{end}} |
|
| 17 | - | <meta name="theme-color" content="#121113" /> |
|
| 18 | - | {{block "meta" .}}{{end}} |
|
| 19 | - | <link rel="stylesheet" href="/assets/darkmatter.css"> |
|
| 20 | - | <link rel="stylesheet" href="/static/styles.css"> |
|
| 21 | - | <link rel="stylesheet" href="/custom-styles.css"> |
|
| 22 | - | </head> |
|
| 23 | - | <body> |
|
| 24 | - | {{if .HeaderHTML}} |
|
| 25 | - | <div class="custom-header"> |
|
| 26 | - | {{.HeaderHTML}} |
|
| 27 | - | </div> |
|
| 28 | - | {{end}} |
|
| 29 | - | <header class="header"> |
|
| 30 | - | <a href="/" class="logo">{{.BlogTitle}}</a> |
|
| 31 | - | <nav class="links"> |
|
| 32 | - | {{range .NavLinks}} |
|
| 33 | - | <a href="{{.URL}}">{{.Label}}</a> |
|
| 34 | - | {{end}} |
|
| 35 | - | </nav> |
|
| 36 | - | </header> |
|
| 37 | - | <main> |
|
| 38 | - | {{block "content" .}}{{end}} |
|
| 39 | - | </main> |
|
| 40 | - | <footer class="footer"> |
|
| 41 | - | {{.FooterHTML}} |
|
| 42 | - | </footer> |
|
| 43 | - | <script> |
|
| 44 | - | document.querySelectorAll('.post-date').forEach(el => { |
|
| 45 | - | const d = new Date(el.textContent.trim()); |
|
| 46 | - | if (!isNaN(d)) { |
|
| 47 | - | const day = String(d.getDate()).padStart(2, '0'); |
|
| 48 | - | const mon = d.toLocaleString('en-US', { month: 'short' }); |
|
| 49 | - | el.textContent = `${day} ${mon}, ${d.getFullYear()}`; |
|
| 50 | - | } |
|
| 51 | - | }); |
|
| 52 | - | </script> |
|
| 53 | - | </body> |
|
| 54 | - | </html>{{end}} |
| 1 | - | {{define "index.html"}}{{template "base.html" .}}{{end}} |
|
| 2 | - | {{define "title"}}{{.BlogTitle}}{{end}} |
|
| 3 | - | {{define "meta"}} |
|
| 4 | - | <meta name="description" content="{{.BlogDescription}}"> |
|
| 5 | - | <meta property="og:title" content="{{.BlogTitle}}"> |
|
| 6 | - | <meta property="og:description" content="{{.BlogDescription}}"> |
|
| 7 | - | <meta property="og:type" content="website"> |
|
| 8 | - | <meta property="og:url" content="{{.SiteURL}}"> |
|
| 9 | - | {{if .OGImageURL}} |
|
| 10 | - | <meta property="og:image" content="{{.OGImageURL}}"> |
|
| 11 | - | {{else}} |
|
| 12 | - | <meta property="og:image" content="{{.SiteURL}}/static/og.png"> |
|
| 13 | - | {{end}} |
|
| 14 | - | {{end}} |
|
| 15 | - | {{define "content"}} |
|
| 16 | - | {{if .IntroHTML}} |
|
| 17 | - | <article class="intro markdown-body"> |
|
| 18 | - | {{.IntroHTML}} |
|
| 19 | - | </article> |
|
| 20 | - | {{end}} |
|
| 21 | - | {{if not .Posts}} |
|
| 22 | - | <p class="empty">no posts yet</p> |
|
| 23 | - | {{end}} |
|
| 24 | - | <div class="post-list"> |
|
| 25 | - | {{range .Posts}} |
|
| 26 | - | <a href="/posts/{{.Slug}}" class="post-item"> |
|
| 27 | - | <div class="post-item-info"> |
|
| 28 | - | <span class="post-title">{{.DisplayTitle}}</span> |
|
| 29 | - | </div> |
|
| 30 | - | {{if .PublishedDate}} |
|
| 31 | - | <time class="post-date">{{.PublishedDateStr}}</time> |
|
| 32 | - | {{end}} |
|
| 33 | - | </a> |
|
| 34 | - | {{end}} |
|
| 35 | - | </div> |
|
| 36 | - | {{end}} |
| 1 | - | {{define "page.html"}}{{template "base.html" .}}{{end}} |
|
| 2 | - | {{define "title"}}{{.Page.Title}} — {{.BlogTitle}}{{end}} |
|
| 3 | - | {{define "meta"}} |
|
| 4 | - | {{if .OGImageURL}} |
|
| 5 | - | <meta property="og:image" content="{{.OGImageURL}}"> |
|
| 6 | - | {{else}} |
|
| 7 | - | <meta property="og:image" content="{{.SiteURL}}/static/og.png"> |
|
| 8 | - | {{end}} |
|
| 9 | - | <meta property="og:url" content="{{.SiteURL}}/{{.Page.Slug}}"> |
|
| 10 | - | {{end}} |
|
| 11 | - | {{define "content"}} |
|
| 12 | - | <div class="page-header"> |
|
| 13 | - | <h1>{{.Page.Title}}</h1> |
|
| 14 | - | </div> |
|
| 15 | - | <article class="markdown-body"> |
|
| 16 | - | {{.RenderedContent}} |
|
| 17 | - | </article> |
|
| 18 | - | {{end}} |
| 1 | - | {{define "post.html"}}{{template "base.html" .}}{{end}} |
|
| 2 | - | {{define "title"}}{{.Post.DisplayTitle}} — {{.BlogTitle}}{{end}} |
|
| 3 | - | {{define "meta"}} |
|
| 4 | - | {{if .Post.MetaDescription}} |
|
| 5 | - | <meta name="description" content="{{.Post.MetaDescriptionStr}}"> |
|
| 6 | - | <meta property="og:description" content="{{.Post.MetaDescriptionStr}}"> |
|
| 7 | - | {{end}} |
|
| 8 | - | {{if and .Post.MetaImage .Post.MetaImageStr}} |
|
| 9 | - | <meta property="og:image" content="{{.Post.MetaImageStr}}"> |
|
| 10 | - | {{else if .OGImageURL}} |
|
| 11 | - | <meta property="og:image" content="{{.OGImageURL}}"> |
|
| 12 | - | {{else}} |
|
| 13 | - | <meta property="og:image" content="{{.SiteURL}}/static/og.png"> |
|
| 14 | - | {{end}} |
|
| 15 | - | {{if .Post.CanonicalURL}} |
|
| 16 | - | <link rel="canonical" href="{{.Post.CanonicalURLStr}}"> |
|
| 17 | - | {{end}} |
|
| 18 | - | <meta property="og:title" content="{{.Post.DisplayTitle}}"> |
|
| 19 | - | <meta property="og:type" content="article"> |
|
| 20 | - | <meta property="og:url" content="{{.SiteURL}}/posts/{{.Post.Slug}}"> |
|
| 21 | - | <meta property="article:published_time" content="{{.Post.PublishedDateStr}}"> |
|
| 22 | - | {{end}} |
|
| 23 | - | {{define "content"}} |
|
| 24 | - | <div class="post-header"> |
|
| 25 | - | {{if .Post.HasTitle}} |
|
| 26 | - | <h1>{{.Post.TitleStr}}</h1> |
|
| 27 | - | {{end}} |
|
| 28 | - | {{if .Post.MetaDescription}} |
|
| 29 | - | <p class="post-description">{{.Post.MetaDescriptionStr}}</p> |
|
| 30 | - | {{end}} |
|
| 31 | - | <div class="post-weather"> |
|
| 32 | - | {{if .Post.PublishedDate}} |
|
| 33 | - | <span> |
|
| 34 | - | <time class="post-date">{{.Post.PublishedDateStr}}</time> |
|
| 35 | - | </span> |
|
| 36 | - | <span>•</span> |
|
| 37 | - | {{end}} |
|
| 38 | - | {{if .Post.Weather}} |
|
| 39 | - | {{.Weather.Icon}} |
|
| 40 | - | <p class="weather-conditions">{{.Weather.Conditions}}</p> |
|
| 41 | - | <p class="weather-temp">{{.Weather.Temperature}}</p> |
|
| 42 | - | • |
|
| 43 | - | <div class="weather-location"> |
|
| 44 | - | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><!-- Icon from Phosphor by Phosphor Icons - https://github.com/phosphor-icons/core/blob/main/LICENSE --><path fill="currentColor" d="M128 68a36 36 0 1 0 36 36a36 36 0 0 0-36-36m0 64a28 28 0 1 1 28-28a28 28 0 0 1-28 28m0-112a84.09 84.09 0 0 0-84 84c0 30.42 14.17 62.79 41 93.62a250 250 0 0 0 40.73 37.66a4 4 0 0 0 4.58 0A250 250 0 0 0 171 197.62c26.81-30.83 41-63.2 41-93.62a84.09 84.09 0 0 0-84-84m37.1 172.23A254.6 254.6 0 0 1 128 227a254.6 254.6 0 0 1-37.1-34.81C73.15 171.8 52 139.9 52 104a76 76 0 0 1 152 0c0 35.9-21.15 67.8-38.9 88.23"/></svg> |
|
| 45 | - | <p>{{.Weather.Location}}</p> |
|
| 46 | - | </div> |
|
| 47 | - | {{end}} |
|
| 48 | - | </div> |
|
| 49 | - | {{if .Post.Tags}} |
|
| 50 | - | <div class="post-tags"> |
|
| 51 | - | {{range .Post.TagList}} |
|
| 52 | - | <span class="tag">{{.}}</span> |
|
| 53 | - | {{end}} |
|
| 54 | - | </div> |
|
| 55 | - | {{end}} |
|
| 56 | - | </div> |
|
| 57 | - | <article class="markdown-body"> |
|
| 58 | - | {{.RenderedContent}} |
|
| 59 | - | </article> |
|
| 60 | - | {{end}} |
| 1 | - | {{define "posts.html"}}{{template "base.html" .}}{{end}} |
|
| 2 | - | {{define "title"}}Posts — {{.BlogTitle}}{{end}} |
|
| 3 | - | {{define "meta"}} |
|
| 4 | - | {{if .OGImageURL}} |
|
| 5 | - | <meta property="og:image" content="{{.OGImageURL}}"> |
|
| 6 | - | {{else}} |
|
| 7 | - | <meta property="og:image" content="{{.SiteURL}}/static/og.png"> |
|
| 8 | - | {{end}} |
|
| 9 | - | <meta property="og:url" content="{{.SiteURL}}/posts"> |
|
| 10 | - | {{end}} |
|
| 11 | - | {{define "content"}} |
|
| 12 | - | <h1>Posts</h1> |
|
| 13 | - | {{if not .Posts}} |
|
| 14 | - | <p class="empty">no posts yet</p> |
|
| 15 | - | {{end}} |
|
| 16 | - | <div class="post-list"> |
|
| 17 | - | {{range .Posts}} |
|
| 18 | - | <a href="/posts/{{.Slug}}" class="post-item post-item-enhanced"> |
|
| 19 | - | <div class="post-item-info"> |
|
| 20 | - | <span class="post-title">{{.DisplayTitle}}</span> |
|
| 21 | - | </div> |
|
| 22 | - | {{if .PublishedDate}} |
|
| 23 | - | <time class="post-date">{{.PublishedDateStr}}</time> |
|
| 24 | - | {{end}} |
|
| 25 | - | </a> |
|
| 26 | - | {{end}} |
|
| 27 | - | </div> |
|
| 28 | - | {{end}} |
| 1 | + | package main |
|
| 2 | + | ||
| 3 | + | //go:generate go run github.com/a-h/templ/cmd/templ@v0.3.1001 generate |
|
| 4 | + | ||
| 5 | + | import ( |
|
| 6 | + | "bytes" |
|
| 7 | + | "html/template" |
|
| 8 | + | "net/http" |
|
| 9 | + | "sync" |
|
| 10 | + | ||
| 11 | + | "github.com/a-h/templ" |
|
| 12 | + | ) |
|
| 13 | + | ||
| 14 | + | // View models for the public pages. They are passed both to the templ |
|
| 15 | + | // components and to custom body templates, so their fields (including the |
|
| 16 | + | // promoted siteContext ones) are the contract documented on /admin/templates. |
|
| 17 | + | ||
| 18 | + | type indexView struct { |
|
| 19 | + | siteContext |
|
| 20 | + | BlogDescription string |
|
| 21 | + | IntroHTML template.HTML |
|
| 22 | + | Posts []Post |
|
| 23 | + | } |
|
| 24 | + | ||
| 25 | + | type postView struct { |
|
| 26 | + | siteContext |
|
| 27 | + | Post Post |
|
| 28 | + | RenderedContent template.HTML |
|
| 29 | + | Weather Weather |
|
| 30 | + | } |
|
| 31 | + | ||
| 32 | + | type pageView struct { |
|
| 33 | + | siteContext |
|
| 34 | + | Page Page |
|
| 35 | + | RenderedContent template.HTML |
|
| 36 | + | } |
|
| 37 | + | ||
| 38 | + | type postsView struct { |
|
| 39 | + | siteContext |
|
| 40 | + | Posts []Post |
|
| 41 | + | } |
|
| 42 | + | ||
| 43 | + | // templateKinds are the public views whose body can be replaced from |
|
| 44 | + | // /admin/templates. Each is stored in the "template_<kind>" setting. |
|
| 45 | + | var templateKinds = []struct{ Kind, Label string }{ |
|
| 46 | + | {"index", "home"}, |
|
| 47 | + | {"post", "post"}, |
|
| 48 | + | {"page", "page"}, |
|
| 49 | + | {"posts", "posts list"}, |
|
| 50 | + | } |
|
| 51 | + | ||
| 52 | + | func isTemplateKind(kind string) bool { |
|
| 53 | + | for _, k := range templateKinds { |
|
| 54 | + | if k.Kind == kind { |
|
| 55 | + | return true |
|
| 56 | + | } |
|
| 57 | + | } |
|
| 58 | + | return false |
|
| 59 | + | } |
|
| 60 | + | ||
| 61 | + | func templateSettingKey(kind string) string { return "template_" + kind } |
|
| 62 | + | ||
| 63 | + | // overrides caches parsed custom body templates by kind. |
|
| 64 | + | type overrides struct { |
|
| 65 | + | mu sync.RWMutex |
|
| 66 | + | tmpls map[string]*template.Template |
|
| 67 | + | } |
|
| 68 | + | ||
| 69 | + | func (o *overrides) get(kind string) *template.Template { |
|
| 70 | + | o.mu.RLock() |
|
| 71 | + | defer o.mu.RUnlock() |
|
| 72 | + | return o.tmpls[kind] |
|
| 73 | + | } |
|
| 74 | + | ||
| 75 | + | func (o *overrides) set(kind string, t *template.Template) { |
|
| 76 | + | o.mu.Lock() |
|
| 77 | + | defer o.mu.Unlock() |
|
| 78 | + | if o.tmpls == nil { |
|
| 79 | + | o.tmpls = map[string]*template.Template{} |
|
| 80 | + | } |
|
| 81 | + | if t == nil { |
|
| 82 | + | delete(o.tmpls, kind) |
|
| 83 | + | return |
|
| 84 | + | } |
|
| 85 | + | o.tmpls[kind] = t |
|
| 86 | + | } |
|
| 87 | + | ||
| 88 | + | func (a *App) loadOverrides() { |
|
| 89 | + | for _, k := range templateKinds { |
|
| 90 | + | src, _ := getSetting(a.DB, templateSettingKey(k.Kind)) |
|
| 91 | + | if src == "" { |
|
| 92 | + | continue |
|
| 93 | + | } |
|
| 94 | + | t, err := template.New(k.Kind).Parse(src) |
|
| 95 | + | if err != nil { |
|
| 96 | + | a.Log.Error("custom template parse failed", "kind", k.Kind, "err", err) |
|
| 97 | + | continue |
|
| 98 | + | } |
|
| 99 | + | a.Overrides.set(k.Kind, t) |
|
| 100 | + | } |
|
| 101 | + | } |
|
| 102 | + | ||
| 103 | + | // validateOverride parses src and executes it against sample data, so errors |
|
| 104 | + | // like unknown fields surface on save rather than on the live site. |
|
| 105 | + | func validateOverride(kind, src string) (*template.Template, error) { |
|
| 106 | + | t, err := template.New(kind).Parse(src) |
|
| 107 | + | if err != nil { |
|
| 108 | + | return nil, err |
|
| 109 | + | } |
|
| 110 | + | var buf bytes.Buffer |
|
| 111 | + | if err := t.Execute(&buf, sampleView(kind)); err != nil { |
|
| 112 | + | return nil, err |
|
| 113 | + | } |
|
| 114 | + | return t, nil |
|
| 115 | + | } |
|
| 116 | + | ||
| 117 | + | // body returns the custom body for kind if one is set and renders cleanly, |
|
| 118 | + | // otherwise the default templ component. |
|
| 119 | + | func (a *App) body(kind string, data any, def templ.Component) templ.Component { |
|
| 120 | + | t := a.Overrides.get(kind) |
|
| 121 | + | if t == nil { |
|
| 122 | + | return def |
|
| 123 | + | } |
|
| 124 | + | var buf bytes.Buffer |
|
| 125 | + | if err := t.Execute(&buf, data); err != nil { |
|
| 126 | + | a.Log.Error("custom template render failed, using default", "kind", kind, "err", err) |
|
| 127 | + | return def |
|
| 128 | + | } |
|
| 129 | + | return templ.Raw(buf.String()) |
|
| 130 | + | } |
|
| 131 | + | ||
| 132 | + | func (a *App) renderPublic(w http.ResponseWriter, r *http.Request, site siteContext, title string, meta, body templ.Component) { |
|
| 133 | + | var buf bytes.Buffer |
|
| 134 | + | if err := layout(site, title, meta, body).Render(r.Context(), &buf); err != nil { |
|
| 135 | + | a.Log.Error("render failed", "err", err) |
|
| 136 | + | http.Error(w, "render error", http.StatusInternalServerError) |
|
| 137 | + | return |
|
| 138 | + | } |
|
| 139 | + | w.Header().Set("Content-Type", "text/html; charset=utf-8") |
|
| 140 | + | _, _ = buf.WriteTo(w) |
|
| 141 | + | } |
|
| 142 | + | ||
| 143 | + | // sampleView returns representative data for kind, used to validate custom |
|
| 144 | + | // templates and to check the starters match the templ defaults. |
|
| 145 | + | func sampleView(kind string) any { |
|
| 146 | + | s := func(v string) *string { return &v } |
|
| 147 | + | site := siteContext{ |
|
| 148 | + | BlogTitle: "My Blog", |
|
| 149 | + | NavLinks: []NavLink{{Label: "about", URL: "/about"}}, |
|
| 150 | + | SiteURL: "https://example.com", |
|
| 151 | + | } |
|
| 152 | + | posts := []Post{ |
|
| 153 | + | { |
|
| 154 | + | Slug: "hello-world", Title: s("Hello world"), PublishedDate: s("2026-01-02"), |
|
| 155 | + | MetaDescription: s("A first post"), Tags: s("go, templ"), Weather: s("{}"), |
|
| 156 | + | Content: "Hello **world**", Status: "published", |
|
| 157 | + | }, |
|
| 158 | + | {Slug: "untitled", Content: "A post with no title that runs on for a while", Status: "published"}, |
|
| 159 | + | } |
|
| 160 | + | switch kind { |
|
| 161 | + | case "index": |
|
| 162 | + | return indexView{siteContext: site, BlogDescription: "A blog", IntroHTML: "<p>Welcome</p>", Posts: posts} |
|
| 163 | + | case "post": |
|
| 164 | + | return postView{ |
|
| 165 | + | siteContext: site, Post: posts[0], RenderedContent: "<p>Hello <strong>world</strong></p>", |
|
| 166 | + | Weather: Weather{Icon: "<svg></svg>", Conditions: "Sunny", Temperature: "72°F", Location: "Somewhere, OK"}, |
|
| 167 | + | } |
|
| 168 | + | case "page": |
|
| 169 | + | return pageView{siteContext: site, Page: Page{Title: "About", Slug: "about", IsPublished: true}, RenderedContent: "<p>About me</p>"} |
|
| 170 | + | case "posts": |
|
| 171 | + | return postsView{siteContext: site, Posts: posts} |
|
| 172 | + | } |
|
| 173 | + | return nil |
|
| 174 | + | } |
| 1 | + | package main |
|
| 2 | + | ||
| 3 | + | import ( |
|
| 4 | + | "bytes" |
|
| 5 | + | "context" |
|
| 6 | + | "html/template" |
|
| 7 | + | "io" |
|
| 8 | + | "log/slog" |
|
| 9 | + | "net/http" |
|
| 10 | + | "net/http/httptest" |
|
| 11 | + | "net/url" |
|
| 12 | + | "regexp" |
|
| 13 | + | "strings" |
|
| 14 | + | "testing" |
|
| 15 | + | ||
| 16 | + | "github.com/a-h/templ" |
|
| 17 | + | ) |
|
| 18 | + | ||
| 19 | + | var betweenTags = regexp.MustCompile(`>\s+<`) |
|
| 20 | + | var spaces = regexp.MustCompile(`\s+`) |
|
| 21 | + | ||
| 22 | + | func normalizeHTML(s string) string { |
|
| 23 | + | s = betweenTags.ReplaceAllString(s, "><") |
|
| 24 | + | s = spaces.ReplaceAllString(s, " ") |
|
| 25 | + | s = strings.ReplaceAll(s, "> ", ">") |
|
| 26 | + | s = strings.ReplaceAll(s, " <", "<") |
|
| 27 | + | return strings.TrimSpace(s) |
|
| 28 | + | } |
|
| 29 | + | ||
| 30 | + | // The starters prefill the /admin/templates editor, so they must render the |
|
| 31 | + | // same markup as the templ defaults they stand in for. |
|
| 32 | + | func TestStartersMatchTemplDefaults(t *testing.T) { |
|
| 33 | + | defaults := map[string]func(any) templ.Component{ |
|
| 34 | + | "index": func(v any) templ.Component { return indexBody(v.(indexView)) }, |
|
| 35 | + | "post": func(v any) templ.Component { return postBody(v.(postView)) }, |
|
| 36 | + | "page": func(v any) templ.Component { return pageBody(v.(pageView)) }, |
|
| 37 | + | "posts": func(v any) templ.Component { return postsBody(v.(postsView)) }, |
|
| 38 | + | } |
|
| 39 | + | for _, k := range templateKinds { |
|
| 40 | + | t.Run(k.Kind, func(t *testing.T) { |
|
| 41 | + | v := sampleView(k.Kind) |
|
| 42 | + | var want bytes.Buffer |
|
| 43 | + | if err := defaults[k.Kind](v).Render(context.Background(), &want); err != nil { |
|
| 44 | + | t.Fatal(err) |
|
| 45 | + | } |
|
| 46 | + | src, err := appFS.ReadFile("starters/" + k.Kind + ".html") |
|
| 47 | + | if err != nil { |
|
| 48 | + | t.Fatal(err) |
|
| 49 | + | } |
|
| 50 | + | tmpl, err := validateOverride(k.Kind, string(src)) |
|
| 51 | + | if err != nil { |
|
| 52 | + | t.Fatal(err) |
|
| 53 | + | } |
|
| 54 | + | var got bytes.Buffer |
|
| 55 | + | if err := tmpl.Execute(&got, v); err != nil { |
|
| 56 | + | t.Fatal(err) |
|
| 57 | + | } |
|
| 58 | + | if g, w := normalizeHTML(got.String()), normalizeHTML(want.String()); g != w { |
|
| 59 | + | t.Errorf("starter differs from templ default\nstarter: %s\ndefault: %s", g, w) |
|
| 60 | + | } |
|
| 61 | + | }) |
|
| 62 | + | } |
|
| 63 | + | } |
|
| 64 | + | ||
| 65 | + | func newTestApp(t *testing.T) *App { |
|
| 66 | + | t.Helper() |
|
| 67 | + | tmpls, err := buildTemplates() |
|
| 68 | + | if err != nil { |
|
| 69 | + | t.Fatal(err) |
|
| 70 | + | } |
|
| 71 | + | return &App{ |
|
| 72 | + | DB: openPostsTestDB(t), |
|
| 73 | + | Log: slog.New(slog.NewTextHandler(io.Discard, nil)), |
|
| 74 | + | Templates: tmpls, |
|
| 75 | + | Overrides: &overrides{}, |
|
| 76 | + | SiteURL: "https://example.com", |
|
| 77 | + | } |
|
| 78 | + | } |
|
| 79 | + | ||
| 80 | + | func get(t *testing.T, h http.Handler, path string) *httptest.ResponseRecorder { |
|
| 81 | + | t.Helper() |
|
| 82 | + | rec := httptest.NewRecorder() |
|
| 83 | + | h.ServeHTTP(rec, httptest.NewRequest("GET", path, nil)) |
|
| 84 | + | return rec |
|
| 85 | + | } |
|
| 86 | + | ||
| 87 | + | func TestCustomTemplateOverridesBody(t *testing.T) { |
|
| 88 | + | a := newTestApp(t) |
|
| 89 | + | defer a.DB.Close() |
|
| 90 | + | if _, err := createPost(a.DB, PostInput{Title: strp("Hi"), Slug: "hi", Content: "body", Status: "published", Lang: "en"}); err != nil { |
|
| 91 | + | t.Fatal(err) |
|
| 92 | + | } |
|
| 93 | + | h := a.routes() |
|
| 94 | + | ||
| 95 | + | rec := get(t, h, "/posts/hi") |
|
| 96 | + | if rec.Code != 200 || !strings.Contains(rec.Body.String(), `<h1>Hi</h1>`) { |
|
| 97 | + | t.Fatalf("default render: %d %s", rec.Code, rec.Body.String()) |
|
| 98 | + | } |
|
| 99 | + | ||
| 100 | + | // Invalid templates are rejected and leave the default in place. |
|
| 101 | + | for _, src := range []string{"{{.Post.Nope}}", "{{if}}"} { |
|
| 102 | + | rec = httptest.NewRecorder() |
|
| 103 | + | req := httptest.NewRequest("POST", "/admin/templates/post", strings.NewReader(url.Values{"template": {src}}.Encode())) |
|
| 104 | + | req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
|
| 105 | + | a.adminPostTemplate(rec, withKind(req, "post")) |
|
| 106 | + | if rec.Code != http.StatusUnprocessableEntity { |
|
| 107 | + | t.Fatalf("%q: want 422, got %d", src, rec.Code) |
|
| 108 | + | } |
|
| 109 | + | } |
|
| 110 | + | if a.Overrides.get("post") != nil { |
|
| 111 | + | t.Fatal("invalid template was cached") |
|
| 112 | + | } |
|
| 113 | + | ||
| 114 | + | save := func(src string) { |
|
| 115 | + | rec := httptest.NewRecorder() |
|
| 116 | + | req := httptest.NewRequest("POST", "/admin/templates/post", strings.NewReader(url.Values{"template": {src}}.Encode())) |
|
| 117 | + | req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
|
| 118 | + | a.adminPostTemplate(rec, withKind(req, "post")) |
|
| 119 | + | if rec.Code != http.StatusSeeOther { |
|
| 120 | + | t.Fatalf("save: %d %s", rec.Code, rec.Body.String()) |
|
| 121 | + | } |
|
| 122 | + | } |
|
| 123 | + | save(`<h2 class="custom">{{.Post.TitleStr}} on {{.BlogTitle}}</h2>{{.RenderedContent}}`) |
|
| 124 | + | body := get(t, h, "/posts/hi").Body.String() |
|
| 125 | + | if !strings.Contains(body, `<h2 class="custom">Hi on My Blog</h2><p>body</p>`) { |
|
| 126 | + | t.Fatalf("override not rendered: %s", body) |
|
| 127 | + | } |
|
| 128 | + | if !strings.Contains(body, `<meta property="og:title" content="Hi">`) { |
|
| 129 | + | t.Fatal("layout meta missing with override") |
|
| 130 | + | } |
|
| 131 | + | ||
| 132 | + | // Overrides survive a restart. |
|
| 133 | + | b := &App{DB: a.DB, Log: a.Log, Overrides: &overrides{}} |
|
| 134 | + | b.loadOverrides() |
|
| 135 | + | if b.Overrides.get("post") == nil { |
|
| 136 | + | t.Fatal("override not loaded from settings") |
|
| 137 | + | } |
|
| 138 | + | ||
| 139 | + | // A runtime failure falls back to the default body. |
|
| 140 | + | a.Overrides.set("post", template.Must(template.New("post").Parse(`{{index .Post.TagList 5}}`))) |
|
| 141 | + | rec = get(t, h, "/posts/hi") |
|
| 142 | + | if rec.Code != 200 || !strings.Contains(rec.Body.String(), `<h1>Hi</h1>`) { |
|
| 143 | + | t.Fatalf("fallback: %d %s", rec.Code, rec.Body.String()) |
|
| 144 | + | } |
|
| 145 | + | ||
| 146 | + | // Clearing removes the override. |
|
| 147 | + | save("") |
|
| 148 | + | if a.Overrides.get("post") != nil { |
|
| 149 | + | t.Fatal("override not cleared") |
|
| 150 | + | } |
|
| 151 | + | if v, _ := getSetting(a.DB, templateSettingKey("post")); v != "" { |
|
| 152 | + | t.Fatalf("setting not cleared: %q", v) |
|
| 153 | + | } |
|
| 154 | + | } |
|
| 155 | + | ||
| 156 | + | func withKind(r *http.Request, kind string) *http.Request { |
|
| 157 | + | r.SetPathValue("kind", kind) |
|
| 158 | + | return r |
|
| 159 | + | } |
|
| 160 | + | ||
| 161 | + | func TestPublicPagesRender(t *testing.T) { |
|
| 162 | + | a := newTestApp(t) |
|
| 163 | + | defer a.DB.Close() |
|
| 164 | + | if _, err := createPost(a.DB, PostInput{Title: strp("<b>x</b>"), Slug: "x", Content: "body", Status: "published", Lang: "en", Tags: strp("a")}); err != nil { |
|
| 165 | + | t.Fatal(err) |
|
| 166 | + | } |
|
| 167 | + | if _, err := createPage(a.DB, "About", "about", "about me", true, 0); err != nil { |
|
| 168 | + | t.Fatal(err) |
|
| 169 | + | } |
|
| 170 | + | _ = setSetting(a.DB, "intro_content", "hi\n\n{{latest_posts}}") |
|
| 171 | + | h := a.routes() |
|
| 172 | + | for path, want := range map[string]string{ |
|
| 173 | + | "/": `<span class="tag">a</span>`, |
|
| 174 | + | "/posts": `<h1>Posts</h1>`, |
|
| 175 | + | "/posts/x": `<h1><b>x</b></h1>`, |
|
| 176 | + | "/about": `<h1>About</h1>`, |
|
| 177 | + | } { |
|
| 178 | + | rec := get(t, h, path) |
|
| 179 | + | if rec.Code != 200 || !strings.Contains(rec.Body.String(), want) { |
|
| 180 | + | t.Errorf("%s: %d, missing %q in %s", path, rec.Code, want, rec.Body.String()) |
|
| 181 | + | } |
|
| 182 | + | if strings.Contains(rec.Body.String(), "<b>x</b>") { |
|
| 183 | + | t.Errorf("%s: unescaped title", path) |
|
| 184 | + | } |
|
| 185 | + | } |
|
| 186 | + | } |