Implementierung eines anonymen Counters - Nicht persistent
All checks were successful
release-tag / release-image (push) Successful in 2m9s
All checks were successful
release-tag / release-image (push) Successful in 2m9s
This commit is contained in:
@@ -48,7 +48,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
COPY --from=build /blog /usr/local/bin/blog
|
COPY --from=build /blog /usr/local/bin/blog
|
||||||
|
|
||||||
# ─── Content + Assets ───
|
# ─── Content + Assets ───
|
||||||
RUN mkdir -p /content /static /pages /app
|
RUN mkdir -p /content /static /pages /app /templates /ticks
|
||||||
COPY . /app
|
COPY . /app
|
||||||
COPY --from=content /out/content /content
|
COPY --from=content /out/content /content
|
||||||
COPY --from=content /out/static /static
|
COPY --from=content /out/static /static
|
||||||
@@ -59,6 +59,7 @@ ENV BLOG_CONTENT_DIR=/content
|
|||||||
ENV BLOG_STATIC_DIR=/static
|
ENV BLOG_STATIC_DIR=/static
|
||||||
ENV BLOG_PAGES_DIR=/pages
|
ENV BLOG_PAGES_DIR=/pages
|
||||||
ENV BLOG_TEMPLATES_DIR=/templates
|
ENV BLOG_TEMPLATES_DIR=/templates
|
||||||
|
ENV BLOG_TICKS_DIR=/ticks
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
CMD ["blog"]
|
CMD ["blog"]
|
||||||
|
@@ -12,6 +12,35 @@ import (
|
|||||||
"git.send.nrw/sendnrw/b1tsblog/internal/article"
|
"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 {
|
func getenv(k, d string) string {
|
||||||
if v := os.Getenv(k); v != "" {
|
if v := os.Getenv(k); v != "" {
|
||||||
return v
|
return v
|
||||||
@@ -42,35 +71,17 @@ var (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// --- Verzeichnisse konfigurierbar machen -------------------------
|
// --- Verzeichnisse konfigurierbar machen -------------------------
|
||||||
contentDir := os.Getenv("BLOG_CONTENT_DIR")
|
contentDir := getenv("BLOG_CONTENT_DIR", "/content")
|
||||||
if contentDir == "" {
|
staticDir := getenv("BLOG_STATIC_DIR", "/app/internal/web/static")
|
||||||
contentDir = "/content" // Fallback für local run
|
pagesDir := getenv("BLOG_PAGES_DIR", "/pages")
|
||||||
}
|
templatesDir := getenv("BLOG_TEMPLATES_DIR", "/templates")
|
||||||
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
funcs := template.FuncMap{
|
funcs := template.FuncMap{
|
||||||
"now": time.Now, // jetzt‑Zeit bereitstellen
|
"now": time.Now, // jetzt‑Zeit bereitstellen
|
||||||
}
|
}
|
||||||
|
|
||||||
// Basislayout zuerst parsen
|
// Basislayout zuerst parsen
|
||||||
layout := template.Must(
|
layout := template.Must(template.New("base").Funcs(funcs).ParseFiles(templatesDir + "/base.html"))
|
||||||
template.New("base").Funcs(funcs).
|
|
||||||
ParseFiles(templatesDir + "/base.html"),
|
|
||||||
)
|
|
||||||
|
|
||||||
// LIST‑Seite: base + list.html
|
// LIST‑Seite: base + list.html
|
||||||
tplList = template.Must(layout.Clone())
|
tplList = template.Must(layout.Clone())
|
||||||
@@ -90,6 +101,14 @@ func main() {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
|
for a, b := range articles {
|
||||||
|
articles[a].Counter = getTick(b.Slug)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
staticPages, err := article.LoadStatic(pagesDir)
|
staticPages, err := article.LoadStatic(pagesDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -116,6 +135,9 @@ func main() {
|
|||||||
slug := strings.TrimPrefix(r.URL.Path, "/post/")
|
slug := strings.TrimPrefix(r.URL.Path, "/post/")
|
||||||
for _, a := range articles {
|
for _, a := range articles {
|
||||||
if a.Slug == slug {
|
if a.Slug == slug {
|
||||||
|
IncTick(slug)
|
||||||
|
t := getTick(slug)
|
||||||
|
a.Counter = t
|
||||||
if err := tplArticle.ExecuteTemplate(w, "layout", a); err != nil {
|
if err := tplArticle.ExecuteTemplate(w, "layout", a); err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@ type Article struct {
|
|||||||
Cover string
|
Cover string
|
||||||
Body template.HTML
|
Body template.HTML
|
||||||
Description string
|
Description string
|
||||||
|
Counter string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListPage struct {
|
type ListPage struct {
|
||||||
|
@@ -127,6 +127,7 @@ footer {
|
|||||||
.card-content { padding: 1rem 1.25rem 1.5rem; }
|
.card-content { padding: 1rem 1.25rem 1.5rem; }
|
||||||
.card h2 { margin: .25rem 0 .5rem; font-size: 1.25rem; line-height: 1.3; }
|
.card h2 { margin: .25rem 0 .5rem; font-size: 1.25rem; line-height: 1.3; }
|
||||||
.card time { color: var(--text-muted); font-size: .85rem; }
|
.card time { color: var(--text-muted); font-size: .85rem; }
|
||||||
|
.card-count { color: var(--text-muted); font-size: .85rem; }
|
||||||
|
|
||||||
/* ---------- Artikel ---------- */
|
/* ---------- Artikel ---------- */
|
||||||
.hero {
|
.hero {
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<h2>{{ .Title }}</h2>
|
<h2>{{ .Title }}</h2>
|
||||||
<time datetime="{{ .Date.Format "2006-01-02" }}">{{ .Date.Format "02.01.2006" }}</time>
|
<time datetime="{{ .Date.Format "2006-01-02" }}">{{ .Date.Format "02.01.2006" }}</time>
|
||||||
|
<p class="card-count">{{ .Counter }}</p>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
Reference in New Issue
Block a user