router_news.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package back
  2. import (
  3. "html/template"
  4. "strconv"
  5. )
  6. func getNewsByPage(page int) template.HTML {
  7. tNews := template.HTML("")
  8. news := material{}
  9. news.Category = "новость"
  10. e := news.Select(page*8, 8)
  11. if e != nil {
  12. logger.Println(e.Error())
  13. return tNews
  14. }
  15. for i, m := range news.Rows {
  16. images := `<div class="image no"><img src="/asset/img/no-image.png" /></div>`
  17. if m.Image.Valid {
  18. images = `<div class="image"><img src="/` + m.Image.String + `" /><img class="blur" src="/` + m.Image.String + `" /></div>`
  19. }
  20. if i == 0 || i == 3 || i == 4 || i == 7 || i == 8 {
  21. tNews += template.HTML(`<div class="news"><div class="caption">` + m.Caption + `</div><div class="text">` + m.Preview.String + `</div><a href="/данные/новость/` + m.Link + `" class="gradient-button">Читать далее</a>` + images + `</div>`)
  22. } else {
  23. tNews += template.HTML(`<div class="news"><div class="caption">` + m.Caption + `</div><div class="text">` + m.Preview.String + `</div><a href="/данные/новость/` + m.Link + `" class="gradient-button">Читать далее</a></div>`)
  24. }
  25. }
  26. return tNews
  27. }
  28. func getNewsPaginationByPage(page int) template.HTML {
  29. tNewsPagination := template.HTML("")
  30. news := material{}
  31. news.Category = "новость"
  32. count, e := news.SelectCount()
  33. if e != nil {
  34. logger.Println(e.Error())
  35. return tNewsPagination
  36. }
  37. count = count / 8
  38. if count%8 != 0 {
  39. count++
  40. }
  41. for i := 0; i < count; i++ {
  42. if i == page {
  43. tNewsPagination += template.HTML(`<a class="active" href="javascript:void(0)">` + strconv.Itoa(i+1) + `</a>`)
  44. } else {
  45. tNewsPagination += template.HTML(`<a href="/страница/` + strconv.Itoa(i) + `">` + strconv.Itoa(i+1) + `</a>`)
  46. }
  47. }
  48. return tNewsPagination
  49. }