model.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package main
  2. import (
  3. "strings"
  4. "time"
  5. "github.com/spf13/hugo/hugolib"
  6. )
  7. type Page struct {
  8. Title string `json:"title"`
  9. Type string `json:"type"`
  10. Section string `json:"section"`
  11. Content string `json:"content"`
  12. WordCount float64 `json:"word_count"`
  13. ReadingTime float64 `json:"reading_time"`
  14. Keywords []string `json:"keywords"`
  15. Date time.Time `json:"date"`
  16. LastModified time.Time `json:"last_modified"`
  17. Author string `json:"author"`
  18. }
  19. func NewPageForIndex(page *hugolib.Page) *Page {
  20. var author string
  21. switch str := page.Params["author"].(type) {
  22. case string:
  23. author = str
  24. case []string:
  25. author = strings.Join(str, ", ")
  26. }
  27. return &Page{
  28. Title: page.Title,
  29. Type: page.Type(),
  30. Section: page.Section(),
  31. Content: page.Plain(),
  32. WordCount: float64(page.WordCount),
  33. ReadingTime: float64(page.ReadingTime),
  34. Keywords: page.Keywords,
  35. Date: page.Date,
  36. LastModified: page.Lastmod,
  37. Author: author,
  38. }
  39. }