mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02:00
Adding support for MinRead. Closed #106
This commit is contained in:
@@ -60,6 +60,7 @@ type File struct {
|
|||||||
type PageMeta struct {
|
type PageMeta struct {
|
||||||
WordCount int
|
WordCount int
|
||||||
FuzzyWordCount int
|
FuzzyWordCount int
|
||||||
|
MinRead int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Position struct {
|
type Position struct {
|
||||||
@@ -226,6 +227,7 @@ func ReadFrom(buf io.Reader, name string) (page *Page, err error) {
|
|||||||
func (p *Page) analyzePage() {
|
func (p *Page) analyzePage() {
|
||||||
p.WordCount = TotalWords(p.Plain())
|
p.WordCount = TotalWords(p.Plain())
|
||||||
p.FuzzyWordCount = int((p.WordCount+100)/100) * 100
|
p.FuzzyWordCount = int((p.WordCount+100)/100) * 100
|
||||||
|
p.MinRead = int((p.WordCount + 212) / 213)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) permalink() (*url.URL, error) {
|
func (p *Page) permalink() (*url.URL, error) {
|
||||||
|
@@ -277,6 +277,10 @@ func TestWordCount(t *testing.T) {
|
|||||||
if p.FuzzyWordCount != 500 {
|
if p.FuzzyWordCount != 500 {
|
||||||
t.Fatalf("incorrect word count. expected %v, got %v", 500, p.WordCount)
|
t.Fatalf("incorrect word count. expected %v, got %v", 500, p.WordCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.MinRead != 3 {
|
||||||
|
t.Fatalf("incorrect min read. expected %v, got %v", 3, p.MinRead)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreatePage(t *testing.T) {
|
func TestCreatePage(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user