207 lines
7.6 KiB
Go
207 lines
7.6 KiB
Go
|
// Code generated by templ - DO NOT EDIT.
|
|||
|
|
|||
|
// templ: version: v0.2.778
|
|||
|
package tpl
|
|||
|
|
|||
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
|||
|
|
|||
|
import "github.com/a-h/templ"
|
|||
|
import templruntime "github.com/a-h/templ/runtime"
|
|||
|
|
|||
|
import (
|
|||
|
"fmt"
|
|||
|
"sh.org.ru/pkg/model"
|
|||
|
"strconv"
|
|||
|
)
|
|||
|
|
|||
|
func Index(quotes []model.Quote, page, count int) 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 {
|
|||
|
return templ_7745c5c3_CtxErr
|
|||
|
}
|
|||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|||
|
if !templ_7745c5c3_IsBuffer {
|
|||
|
defer func() {
|
|||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|||
|
if templ_7745c5c3_Err == nil {
|
|||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|||
|
}
|
|||
|
}()
|
|||
|
}
|
|||
|
ctx = templ.InitializeContext(ctx)
|
|||
|
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
|||
|
if templ_7745c5c3_Var1 == nil {
|
|||
|
templ_7745c5c3_Var1 = templ.NopComponent
|
|||
|
}
|
|||
|
ctx = templ.ClearChildren(ctx)
|
|||
|
templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|||
|
if !templ_7745c5c3_IsBuffer {
|
|||
|
defer func() {
|
|||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|||
|
if templ_7745c5c3_Err == nil {
|
|||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|||
|
}
|
|||
|
}()
|
|||
|
}
|
|||
|
ctx = templ.InitializeContext(ctx)
|
|||
|
for _, q := range quotes {
|
|||
|
templ_7745c5c3_Err = Quote(&q).Render(ctx, templ_7745c5c3_Buffer)
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
}
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" <nav><ul>")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
if page > 0 {
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><a href=\"")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
var templ_7745c5c3_Var3 templ.SafeURL = templ.URL(fmt.Sprintf("/?page=%d", page-1))
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var3)))
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">←</a></li>")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
}
|
|||
|
for _, p := range generatePagination(page, count/20) {
|
|||
|
if p == "..." {
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li>...</li>")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
} else if p == strconv.Itoa(page) {
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li>[")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
var templ_7745c5c3_Var4 string
|
|||
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(p)
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/tpl/index.templ`, Line: 27, Col: 14}
|
|||
|
}
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("]</li>")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
} else {
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><a href=\"")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
var templ_7745c5c3_Var5 templ.SafeURL = templ.URL(fmt.Sprintf("/?page=%s", p))
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var5)))
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
var templ_7745c5c3_Var6 string
|
|||
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(p)
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/tpl/index.templ`, Line: 29, Col: 64}
|
|||
|
}
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></li>")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if page < count/20 {
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><a href=\"")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
var templ_7745c5c3_Var7 templ.SafeURL = templ.URL(fmt.Sprintf("/?page=%d", page+1))
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var7)))
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">→</a></li>")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
}
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</ul></nav>Всего ")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
var templ_7745c5c3_Var8 string
|
|||
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(count))
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/tpl/index.templ`, Line: 38, Col: 34}
|
|||
|
}
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" цитат.")
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
return templ_7745c5c3_Err
|
|||
|
})
|
|||
|
templ_7745c5c3_Err = Layout(HeaderParams{
|
|||
|
Title: "Цитатник Рунета",
|
|||
|
Description: "Новый цитатник Рунета",
|
|||
|
URL: "https://sh.org.ru/",
|
|||
|
}).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
|
|||
|
if templ_7745c5c3_Err != nil {
|
|||
|
return templ_7745c5c3_Err
|
|||
|
}
|
|||
|
return templ_7745c5c3_Err
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
func generatePagination(currentPage, totalPages int) []string {
|
|||
|
pagination := make([]string, 0, 11)
|
|||
|
|
|||
|
if currentPage <= 3 {
|
|||
|
for i := 0; i <= currentPage+3; i++ {
|
|||
|
pagination = append(pagination, strconv.Itoa(i))
|
|||
|
}
|
|||
|
pagination = append(pagination, "...")
|
|||
|
pagination = append(pagination, strconv.Itoa(totalPages-2))
|
|||
|
pagination = append(pagination, strconv.Itoa(totalPages-1))
|
|||
|
pagination = append(pagination, strconv.Itoa(totalPages))
|
|||
|
} else if currentPage >= totalPages-3 {
|
|||
|
pagination = append(pagination, "0")
|
|||
|
pagination = append(pagination, "1")
|
|||
|
pagination = append(pagination, "2")
|
|||
|
pagination = append(pagination, "...")
|
|||
|
for i := currentPage - 3; i <= totalPages; i++ {
|
|||
|
pagination = append(pagination, strconv.Itoa(i))
|
|||
|
}
|
|||
|
} else {
|
|||
|
pagination = append(pagination, "0")
|
|||
|
pagination = append(pagination, "...")
|
|||
|
for i := currentPage - 2; i <= currentPage+2; i++ {
|
|||
|
pagination = append(pagination, strconv.Itoa(i))
|
|||
|
}
|
|||
|
pagination = append(pagination, "...")
|
|||
|
pagination = append(pagination, strconv.Itoa(totalPages))
|
|||
|
}
|
|||
|
|
|||
|
return pagination
|
|||
|
}
|
|||
|
|
|||
|
var _ = templruntime.GeneratedTemplate
|