Exemplo n.º 1
0
Arquivo: page.go Projeto: 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
	})
}
Exemplo n.º 2
0
// 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
}