50 lines
982 B
Go
50 lines
982 B
Go
package models
|
|
|
|
import (
|
|
"bytes"
|
|
"html/template"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
// Имя соответствующего шаблона
|
|
PostsPageTmplName = "posts.gohtml"
|
|
)
|
|
|
|
type Posts map[PostName]Post
|
|
|
|
func RenderPostsPage(templates *template.Template, version int64) ([]byte, error) {
|
|
var pageData bytes.Buffer
|
|
|
|
posts := Posts{
|
|
"post 1": *NewPost(
|
|
"post 1",
|
|
"post-1",
|
|
"full content 1 with more than 100 characters Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod...",
|
|
),
|
|
"post 2": *NewPost(
|
|
"post 2",
|
|
"post-2",
|
|
"full content 2",
|
|
),
|
|
"post 3": *NewPost(
|
|
"post 3",
|
|
"post-3",
|
|
strings.Repeat("This is post 3 content. ", 30),
|
|
),
|
|
}
|
|
|
|
context := map[string]any{
|
|
"version": version,
|
|
"renderingTimestamp": time.Now().Unix(),
|
|
"posts": posts,
|
|
}
|
|
|
|
if err := templates.ExecuteTemplate(&pageData, PostsPageTmplName, context); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return pageData.Bytes(), nil
|
|
}
|