Adding support for MinRead. Closed #106
authorspf13 <steve.francia@gmail.com>
Tue, 15 Oct 2013 13:32:21 +0000 (09:32 -0400)
committerspf13 <steve.francia@gmail.com>
Tue, 15 Oct 2013 13:32:21 +0000 (09:32 -0400)
hugolib/page.go
hugolib/page_test.go

index 8e05ba8f9bc36f626b1a471db57d07e1ca9a3d28..56b604407bc664c3974a62bf93d612c075020346 100644 (file)
@@ -60,6 +60,7 @@ type File struct {
 type PageMeta struct {
        WordCount      int
        FuzzyWordCount int
+       MinRead        int
 }
 
 type Position struct {
@@ -226,6 +227,7 @@ func ReadFrom(buf io.Reader, name string) (page *Page, err error) {
 func (p *Page) analyzePage() {
        p.WordCount = TotalWords(p.Plain())
        p.FuzzyWordCount = int((p.WordCount+100)/100) * 100
+       p.MinRead = int((p.WordCount + 212) / 213)
 }
 
 func (p *Page) permalink() (*url.URL, error) {
index b0b844c8d125645881509547c7adcd43c35dcb27..01737c4ff758d808b79b2ae32dc33e0aa9a6d3a9 100644 (file)
@@ -277,6 +277,10 @@ func TestWordCount(t *testing.T) {
        if p.FuzzyWordCount != 500 {
                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) {