示例#1
0
文件: page.go 项目: kanet77/hugo
func (p *Page) initPlainSecondary() {
	p.plainSecondaryInit.Do(func() {
		p.initPlain()
		runeCount := 0
		for _, r := range p.plain {
			if !helpers.IsWhitespace(r) {
				runeCount++
			}
		}
		p.plainRuneCount = runeCount
		return
	})
}
// countRunes returns the approximate rune count of the given content.
func countRunes(content interface{}) (int, error) {
	conv, err := cast.ToStringE(content)

	if err != nil {
		return 0, fmt.Errorf("Failed to convert content to string: %s", err.Error())
	}

	counter := 0
	for _, r := range helpers.StripHTML(conv) {
		if !helpers.IsWhitespace(r) {
			counter++
		}
	}

	return counter, nil
}