diff --git a/Dockerfile b/Dockerfile index cff442f..065aa59 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,7 +48,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ COPY --from=build /blog /usr/local/bin/blog # ─── Content + Assets ─── -RUN mkdir -p /content /static /pages /app +RUN mkdir -p /content /static /pages /app /templates /ticks COPY . /app COPY --from=content /out/content /content COPY --from=content /out/static /static @@ -59,6 +59,7 @@ ENV BLOG_CONTENT_DIR=/content ENV BLOG_STATIC_DIR=/static ENV BLOG_PAGES_DIR=/pages ENV BLOG_TEMPLATES_DIR=/templates +ENV BLOG_TICKS_DIR=/ticks EXPOSE 8080 CMD ["blog"] diff --git a/cmd/blog/main.go b/cmd/blog/main.go index fe652ed..55062bc 100644 --- a/cmd/blog/main.go +++ b/cmd/blog/main.go @@ -12,6 +12,35 @@ import ( "git.send.nrw/sendnrw/b1tsblog/internal/article" ) +var TickCatalog []TickEntry + +func IncTick(xSlug string) error { + for a, b := range TickCatalog { + if b.Slug == xSlug { + TickCatalog[a].Count = TickCatalog[a].Count + 1 + return nil + } + } + newEntry := TickEntry{Slug: xSlug, Count: 1} + TickCatalog = append(TickCatalog, newEntry) + return fmt.Errorf("") +} + +func getTick(xSlug string) string { + for _, b := range TickCatalog { + if b.Slug == xSlug { + var n int64 = b.Count + return strconv.FormatInt(n, 10) + } + } + return "-1" +} + +type TickEntry struct { + Slug string + Count int64 +} + func getenv(k, d string) string { if v := os.Getenv(k); v != "" { return v @@ -42,35 +71,17 @@ var ( func main() { // --- Verzeichnisse konfigurierbar machen ------------------------- - contentDir := os.Getenv("BLOG_CONTENT_DIR") - if contentDir == "" { - contentDir = "/content" // Fallback für local run - } - - staticDir := os.Getenv("BLOG_STATIC_DIR") - if staticDir == "" { - staticDir = "/app/internal/web/static" - } - - pagesDir := os.Getenv("BLOG_PAGES_DIR") - if staticDir == "" { - staticDir = "/pages" - } - - templatesDir := os.Getenv("BLOG_TEMPLATES_DIR") - if templatesDir == "" { - templatesDir = "/templates" - } + contentDir := getenv("BLOG_CONTENT_DIR", "/content") + staticDir := getenv("BLOG_STATIC_DIR", "/app/internal/web/static") + pagesDir := getenv("BLOG_PAGES_DIR", "/pages") + templatesDir := getenv("BLOG_TEMPLATES_DIR", "/templates") funcs := template.FuncMap{ "now": time.Now, // jetzt‑Zeit bereitstellen } // Basislayout zuerst parsen - layout := template.Must( - template.New("base").Funcs(funcs). - ParseFiles(templatesDir + "/base.html"), - ) + layout := template.Must(template.New("base").Funcs(funcs).ParseFiles(templatesDir + "/base.html")) // LIST‑Seite: base + list.html tplList = template.Must(layout.Clone()) @@ -90,6 +101,14 @@ func main() { fmt.Println(err) } + /* */ + + for a, b := range articles { + articles[a].Counter = getTick(b.Slug) + } + + /* */ + staticPages, err := article.LoadStatic(pagesDir) if err != nil { fmt.Println(err) @@ -116,6 +135,9 @@ func main() { slug := strings.TrimPrefix(r.URL.Path, "/post/") for _, a := range articles { if a.Slug == slug { + IncTick(slug) + t := getTick(slug) + a.Counter = t if err := tplArticle.ExecuteTemplate(w, "layout", a); err != nil { http.Error(w, err.Error(), 500) } diff --git a/internal/article/model.go b/internal/article/model.go index 0f1dbf6..932bf17 100644 --- a/internal/article/model.go +++ b/internal/article/model.go @@ -13,6 +13,7 @@ type Article struct { Cover string Body template.HTML Description string + Counter string } type ListPage struct { diff --git a/internal/web/static/main.css b/internal/web/static/main.css index 31da770..b1082a8 100644 --- a/internal/web/static/main.css +++ b/internal/web/static/main.css @@ -127,6 +127,7 @@ footer { .card-content { padding: 1rem 1.25rem 1.5rem; } .card h2 { margin: .25rem 0 .5rem; font-size: 1.25rem; line-height: 1.3; } .card time { color: var(--text-muted); font-size: .85rem; } +.card-count { color: var(--text-muted); font-size: .85rem; } /* ---------- Artikel ---------- */ .hero { diff --git a/internal/web/templates/list.html b/internal/web/templates/list.html index eb634b9..4e8a695 100644 --- a/internal/web/templates/list.html +++ b/internal/web/templates/list.html @@ -11,6 +11,7 @@
{{ .Counter }}