feat: dynamic last updated date in privacy policy

This commit is contained in:
Guz
2025-04-11 22:04:44 -03:00
parent 876d7a1acb
commit 990b29b3c8
4 changed files with 43 additions and 3 deletions

34
app.go
View File

@@ -12,6 +12,7 @@ import (
"slices" "slices"
"sort" "sort"
"strings" "strings"
"time"
"capytal.cc/assets" "capytal.cc/assets"
"capytal.cc/internals/natsort" "capytal.cc/internals/natsort"
@@ -25,6 +26,7 @@ import (
"forge.capytal.company/loreddev/x/smalltrip/exception" "forge.capytal.company/loreddev/x/smalltrip/exception"
"forge.capytal.company/loreddev/x/smalltrip/middleware" "forge.capytal.company/loreddev/x/smalltrip/middleware"
links "github.com/fundipper/goldmark-links" links "github.com/fundipper/goldmark-links"
"github.com/goodsign/monday"
"github.com/yuin/goldmark" "github.com/yuin/goldmark"
highlighting "github.com/yuin/goldmark-highlighting/v2" highlighting "github.com/yuin/goldmark-highlighting/v2"
meta "github.com/yuin/goldmark-meta" meta "github.com/yuin/goldmark-meta"
@@ -196,6 +198,20 @@ func (app *app) setup() {
} }
} }
changeDate, err := time.Parse(time.DateOnly, "2025-04-11")
app.assert.Nil(err, "This date should always be valid")
if d, ok := meta["modified"]; ok {
if s, ok := d.(string); ok {
t, err := time.Parse(time.RFC3339, s)
if err != nil {
exception.InternalServerError(err).ServeHTTP(w, r)
return
}
changeDate = t
}
}
f := new(strings.Builder) f := new(strings.Builder)
err = md.Renderer().Render(f, c, doc) err = md.Renderer().Render(f, c, doc)
if err != nil { if err != nil {
@@ -203,10 +219,22 @@ func (app *app) setup() {
return return
} }
locale := r.URL.Query().Get("lang")
if locale == "" {
locale = "en-US"
}
locale = strings.Replace(locale, "-", "_", 1)
format, ok := monday.LongFormatsByLocale[monday.Locale(locale)]
if !ok {
format = time.DateTime
}
err = app.templates.ExecuteTemplate(w, "privacy-policy", map[string]any{ err = app.templates.ExecuteTemplate(w, "privacy-policy", map[string]any{
"Title": title, "Title": title,
"Lang": r.URL.Query().Get("lang"), "Lang": r.URL.Query().Get("lang"),
"Content": template.HTML(f.String()), "Content": template.HTML(f.String()),
"ChangeDate": monday.Format(changeDate, format, monday.Locale(locale)),
}) })
if err != nil { if err != nil {
exception.InternalServerError(err).ServeHTTP(w, r) exception.InternalServerError(err).ServeHTTP(w, r)

1
go.mod
View File

@@ -5,6 +5,7 @@ go 1.24.1
require ( require (
forge.capytal.company/loreddev/x v0.0.0-20250311222825-ceda7536f16e forge.capytal.company/loreddev/x v0.0.0-20250311222825-ceda7536f16e
github.com/fundipper/goldmark-links v0.1.0 github.com/fundipper/goldmark-links v0.1.0
github.com/goodsign/monday v1.0.2
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
gitlab.com/staticnoise/goldmark-callout v0.0.0-20240609120641-6366b799e4ab gitlab.com/staticnoise/goldmark-callout v0.0.0-20240609120641-6366b799e4ab
go.abhg.dev/goldmark/anchor v0.2.0 go.abhg.dev/goldmark/anchor v0.2.0

2
go.sum
View File

@@ -14,6 +14,8 @@ github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/fundipper/goldmark-links v0.1.0 h1:T8k1+Utk/zirAgasOInXAaIEnOjtGkZQAWe69qYuhag= github.com/fundipper/goldmark-links v0.1.0 h1:T8k1+Utk/zirAgasOInXAaIEnOjtGkZQAWe69qYuhag=
github.com/fundipper/goldmark-links v0.1.0/go.mod h1:e+zrEj9H4lRpN96WDuT6Uk3CjFDRJJi4isKMYbUzvBI= github.com/fundipper/goldmark-links v0.1.0/go.mod h1:e+zrEj9H4lRpN96WDuT6Uk3CjFDRJJi4isKMYbUzvBI=
github.com/goodsign/monday v1.0.2 h1:k8kRMkCRVfCTWOU4dRfRgneQsWlB1+mJd3MxG0lGLzQ=
github.com/goodsign/monday v1.0.2/go.mod h1:r4T4breXpoFwspQNM+u2sLxJb2zyTaxVGqUfTBjWOu8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

View File

@@ -8,6 +8,15 @@
</header> </header>
<main class="mx-10 md:text-justify md:mx-auto md:w-[80%]"> <main class="mx-10 md:text-justify md:mx-auto md:w-[80%]">
{{.Content}} {{.Content}}
<hr>
<p>
{{if (eq .Lang "pt-BR")}}
Última atualização:
{{else}}
Latest update:
{{end}}
{{.ChangeDate}}
</p>
</main> </main>
{{template "nav-bar" (args "Lang" .Lang)}} {{template "nav-bar" (args "Lang" .Lang)}}
{{template "footer" (args "Lang" .Lang)}} {{template "footer" (args "Lang" .Lang)}}