forked from blevesearch/hugoidx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
43 lines (39 loc) · 1.02 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"strings"
"time"
"github.com/spf13/hugo/hugolib"
)
type Page struct {
Title string `json:"title"`
Type string `json:"type"`
Section string `json:"section"`
Content string `json:"content"`
WordCount float64 `json:"word_count"`
ReadingTime float64 `json:"reading_time"`
Keywords []string `json:"keywords"`
Date time.Time `json:"date"`
LastModified time.Time `json:"last_modified"`
Author string `json:"author"`
}
func NewPageForIndex(page *hugolib.Page) *Page {
var author string
switch str := page.Params["author"].(type) {
case string:
author = str
case []string:
author = strings.Join(str, ", ")
}
return &Page{
Title: page.Title,
Type: page.Type(),
Section: page.Section(),
Content: page.Plain(),
WordCount: float64(page.WordCount),
ReadingTime: float64(page.ReadingTime),
Keywords: page.Keywords,
Date: page.Date,
LastModified: page.Lastmod,
Author: author,
}
}