当前位置: 首页>>代码示例>>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;未经允许,请勿转载。