當前位置: 首頁>>代碼示例>>Golang>>正文


Golang helpers.TruncateWordsToWholeSentence函數代碼示例

本文整理匯總了Golang中github.com/spf13/hugo/helpers.TruncateWordsToWholeSentence函數的典型用法代碼示例。如果您正苦於以下問題:Golang TruncateWordsToWholeSentence函數的具體用法?Golang TruncateWordsToWholeSentence怎麽用?Golang TruncateWordsToWholeSentence使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了TruncateWordsToWholeSentence函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: setSummary

func (p *Page) setSummary() {

	// at this point, p.rawContent contains placeholders for the short codes,
	// rendered and ready in p.contentShortcodes

	if bytes.Contains(p.rawContent, helpers.SummaryDivider) {
		// If user defines split:
		// Split, replace shortcode tokens, then render
		p.Truncated = true // by definition
		header := bytes.Split(p.rawContent, helpers.SummaryDivider)[0]
		renderedHeader := p.renderBytes(header)
		if len(p.contentShortCodes) > 0 {
			tmpContentWithTokensReplaced, err :=
				replaceShortcodeTokens(renderedHeader, shortcodePlaceholderPrefix, true, p.contentShortCodes)
			if err != nil {
				jww.FATAL.Printf("Failed to replace short code tokens in Summary for %s:\n%s", p.BaseFileName(), err.Error())
			} else {
				renderedHeader = tmpContentWithTokensReplaced
			}
		}
		p.Summary = helpers.BytesToHTML(renderedHeader)
	} else {
		// If hugo defines split:
		// render, strip html, then split
		plain := strings.Join(strings.Fields(p.Plain()), " ")
		p.Summary = helpers.BytesToHTML([]byte(helpers.TruncateWordsToWholeSentence(plain, helpers.SummaryLength)))
		p.Truncated = len(p.Summary) != len(plain)
	}
}
開發者ID:reedobrien,項目名稱:hugo,代碼行數:29,代碼來源:page.go

示例2: setSummary

func (p *Page) setSummary() {

	// at this point, p.rawContent contains placeholders for the short codes,
	// rendered and ready in p.contentShortcodes

	if bytes.Contains(p.rawContent, helpers.SummaryDivider) {
		sections := bytes.Split(p.rawContent, helpers.SummaryDivider)
		header := sections[0]
		p.Truncated = true
		if len(sections[1]) < 20 {
			// only whitespace?
			p.Truncated = len(bytes.Trim(sections[1], " \n\r")) > 0
		}

		renderedHeader := p.renderBytes(header)
		if len(p.contentShortCodes) > 0 {
			tmpContentWithTokensReplaced, err :=
				replaceShortcodeTokens(renderedHeader, shortcodePlaceholderPrefix, p.contentShortCodes)
			if err != nil {
				jww.FATAL.Printf("Failed to replace short code tokens in Summary for %s:\n%s", p.BaseFileName(), err.Error())
			} else {
				renderedHeader = tmpContentWithTokensReplaced
			}
		}
		p.Summary = helpers.BytesToHTML(renderedHeader)
	} else {
		// If hugo defines split:
		// render, strip html, then split
		summary, truncated := helpers.TruncateWordsToWholeSentence(p.PlainWords(), helpers.SummaryLength)
		p.Summary = template.HTML(summary)
		p.Truncated = truncated

	}
}
開發者ID:johndunne,項目名稱:hugo,代碼行數:34,代碼來源:page.go

示例3: setAutoSummary

func (p *Page) setAutoSummary() error {
	var summary string
	var truncated bool
	if p.isCJKLanguage {
		summary, truncated = helpers.TruncateWordsByRune(p.PlainWords(), helpers.SummaryLength)
	} else {
		summary, truncated = helpers.TruncateWordsToWholeSentence(p.Plain(), helpers.SummaryLength)
	}
	p.Summary = template.HTML(summary)
	p.Truncated = truncated

	return nil
}
開發者ID:digitalcraftsman,項目名稱:hugo,代碼行數:13,代碼來源:page.go

示例4: setSummary

func (p *Page) setSummary() {
	if bytes.Contains(p.rawContent, helpers.SummaryDivider) {
		// If user defines split:
		// Split then render
		p.Truncated = true // by definition
		header := bytes.Split(p.rawContent, helpers.SummaryDivider)[0]
		p.Summary = helpers.BytesToHTML(p.renderBytes(header))
	} else {
		// If hugo defines split:
		// render, strip html, then split
		plain := strings.TrimSpace(p.Plain())
		p.Summary = helpers.BytesToHTML([]byte(helpers.TruncateWordsToWholeSentence(plain, helpers.SummaryLength)))
		p.Truncated = len(p.Summary) != len(plain)
	}
}
開發者ID:kuruma,項目名稱:hugo,代碼行數:15,代碼來源:page.go


注:本文中的github.com/spf13/hugo/helpers.TruncateWordsToWholeSentence函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。