simplified some loops, added day2.md to test new footer date functionality
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
package templates
|
||||
|
||||
templ Footer() {
|
||||
import "time"
|
||||
|
||||
func FormatLastUpdated(t time.Time) string {
|
||||
updatedAt := "Now-ish"
|
||||
if !t.IsZero() {
|
||||
updatedAt = t.Format("January 2, 2006")
|
||||
}
|
||||
return updatedAt
|
||||
}
|
||||
|
||||
templ Footer(lastUpdated time.Time) {
|
||||
<footer class="footer">
|
||||
<p>
|
||||
© 2025 Valentine Bott | Built with Go + Templ + HTMX |
|
||||
© 2026 Valentine Bott | Built with Go + Templ + HTMX |
|
||||
<a href="https://git.valxntine.dev/valxntine/blog">Source Code</a> |
|
||||
Last updated: <span class="blink">●</span> Now-ish
|
||||
Last updated: <span class="blink">●</span> { FormatLastUpdated(lastUpdated) }
|
||||
</p>
|
||||
</footer>
|
||||
}
|
||||
|
||||
@@ -8,7 +8,17 @@ package templates
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
func Footer() templ.Component {
|
||||
import "time"
|
||||
|
||||
func FormatLastUpdated(t time.Time) string {
|
||||
updatedAt := "Now-ish"
|
||||
if !t.IsZero() {
|
||||
updatedAt = t.Format("January 2, 2006")
|
||||
}
|
||||
return updatedAt
|
||||
}
|
||||
|
||||
func Footer(lastUpdated time.Time) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
@@ -29,7 +39,20 @@ func Footer() templ.Component {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<footer class=\"footer\"><p>© 2025 Valentine Bott | Built with Go + Templ + HTMX | <a href=\"https://git.valxntine.dev/valxntine/blog\">Source Code</a> | Last updated: <span class=\"blink\">●</span> Now-ish</p></footer>")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<footer class=\"footer\"><p>© 2026 Valentine Bott | Built with Go + Templ + HTMX | <a href=\"https://git.valxntine.dev/valxntine/blog\">Source Code</a> | Last updated: <span class=\"blink\">●</span> ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(FormatLastUpdated(lastUpdated))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/footer.templ`, Line: 18, Col: 80}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</p></footer>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
package templates
|
||||
|
||||
import "git.valxntine.dev/valxntine/blog/models"
|
||||
import (
|
||||
"git.valxntine.dev/valxntine/blog/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetLastUpdated(p []models.Post) time.Time {
|
||||
if len(p) == 0 {
|
||||
return time.Time{}
|
||||
}
|
||||
return p[0].PublishedAt
|
||||
}
|
||||
|
||||
templ HomePage(data models.Data) {
|
||||
@Layout(data.Title) {
|
||||
@@ -9,6 +19,6 @@ templ HomePage(data models.Data) {
|
||||
<main>
|
||||
@PostList(data.Posts, data.CurrentPage, data.TotalPages)
|
||||
</main>
|
||||
@Footer()
|
||||
@Footer(GetLastUpdated(data.Posts))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,17 @@ package templates
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import "git.valxntine.dev/valxntine/blog/models"
|
||||
import (
|
||||
"git.valxntine.dev/valxntine/blog/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetLastUpdated(p []models.Post) time.Time {
|
||||
if len(p) == 0 {
|
||||
return time.Time{}
|
||||
}
|
||||
return p[0].PublishedAt
|
||||
}
|
||||
|
||||
func HomePage(data models.Data) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
@@ -67,7 +77,7 @@ func HomePage(data models.Data) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = Footer().Render(ctx, templ_7745c5c3_Buffer)
|
||||
templ_7745c5c3_Err = Footer(GetLastUpdated(data.Posts)).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ templ PostPageFull(post models.Post) {
|
||||
<main>
|
||||
@PostDetail(post)
|
||||
</main>
|
||||
@Footer()
|
||||
@Footer(post.PublishedAt)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func PostPageFull(post models.Post) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = Footer().Render(ctx, templ_7745c5c3_Buffer)
|
||||
templ_7745c5c3_Err = Footer(post.PublishedAt).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user