• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang transform.NewChain函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/spf13/hugo/transform.NewChain函数的典型用法代码示例。如果您正苦于以下问题:Golang NewChain函数的具体用法?Golang NewChain怎么用?Golang NewChain使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewChain函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: renderAndWriteXML

func (s *Site) renderAndWriteXML(name string, dest string, d interface{}, layouts ...string) error {
	renderBuffer := bp.GetBuffer()
	defer bp.PutBuffer(renderBuffer)
	renderBuffer.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n")

	err := s.render(name, d, renderBuffer, layouts...)

	outBuffer := bp.GetBuffer()
	defer bp.PutBuffer(outBuffer)

	var path []byte
	if viper.GetBool("RelativeURLs") {
		path = []byte(helpers.GetDottedRelativePath(dest))
	} else {
		s := viper.GetString("BaseURL")
		if !strings.HasSuffix(s, "/") {
			s += "/"
		}
		path = []byte(s)
	}
	transformer := transform.NewChain(transform.AbsURLInXML)
	transformer.Apply(outBuffer, renderBuffer, path)

	if err == nil {
		err = s.WriteDestFile(dest, outBuffer)
	}

	return err
}
开发者ID:maruel,项目名称:hugo,代码行数:29,代码来源:site.go


示例2: renderAndWritePage

func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layouts ...string) error {
	renderBuffer := bp.GetBuffer()
	defer bp.PutBuffer(renderBuffer)

	err := s.render(name, d, renderBuffer, layouts...)

	outBuffer := bp.GetBuffer()
	defer bp.PutBuffer(outBuffer)

	transformLinks := transform.NewEmptyTransforms()

	if viper.GetBool("CanonifyUrls") {
		absURL, err := transform.AbsURL(viper.GetString("BaseUrl"))
		if err != nil {
			return err
		}
		transformLinks = append(transformLinks, absURL...)
	}

	if viper.GetBool("watch") && !viper.GetBool("DisableLiveReload") {
		transformLinks = append(transformLinks, transform.LiveReloadInject)
	}

	transformer := transform.NewChain(transformLinks...)
	transformer.Apply(outBuffer, renderBuffer)

	if err == nil {
		if err = s.WriteDestPage(dest, outBuffer); err != nil {
			return err
		}
	}
	return err
}
开发者ID:dunn,项目名称:hugo,代码行数:33,代码来源:site.go


示例3: renderAndWritePage

func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layouts ...string) error {
	renderBuffer := bp.GetBuffer()
	defer bp.PutBuffer(renderBuffer)

	err := s.render(name, d, renderBuffer, layouts...)

	outBuffer := bp.GetBuffer()
	defer bp.PutBuffer(outBuffer)

	transformLinks := transform.NewEmptyTransforms()

	if viper.GetBool("RelativeURLs") || viper.GetBool("CanonifyURLs") {
		transformLinks = append(transformLinks, transform.AbsURL)
	}

	if s.Running() && viper.GetBool("watch") && !viper.GetBool("DisableLiveReload") {
		transformLinks = append(transformLinks, transform.LiveReloadInject)
	}

	var path []byte

	if viper.GetBool("RelativeURLs") {
		translated, err := s.PageTarget().(target.OptionalTranslator).TranslateRelative(dest)
		if err != nil {
			return err
		}
		path = []byte(helpers.GetDottedRelativePath(translated))
	} else if viper.GetBool("CanonifyURLs") {
		s := viper.GetString("BaseURL")
		if !strings.HasSuffix(s, "/") {
			s += "/"
		}
		path = []byte(s)
	}

	transformer := transform.NewChain(transformLinks...)
	transformer.Apply(outBuffer, renderBuffer, path)

	if outBuffer.Len() == 0 {
		jww.WARN.Printf("%q is rendered empty\n", dest)
		if dest == "/" {
			jww.ERROR.Println("=============================================================")
			jww.ERROR.Println("Your rendered home page is blank: /index.html is zero-length")
			jww.ERROR.Println(" * Did you specify a theme on the command-line or in your")
			jww.ERROR.Printf("   %q file?  (Current theme: %q)\n", filepath.Base(viper.ConfigFileUsed()), viper.GetString("Theme"))
			if !viper.GetBool("Verbose") {
				jww.ERROR.Println(" * For more debugging information, run \"hugo -v\"")
			}
			jww.ERROR.Println("=============================================================")
		}
	}

	if err == nil {
		if err = s.WriteDestPage(dest, outBuffer); err != nil {
			return err
		}
	}
	return err
}
开发者ID:michaelsync,项目名称:hugo,代码行数:59,代码来源:site.go


示例4: render

func (s *Site) render(d interface{}, out string, layouts ...string) (err error) {

	layout, found := s.findFirstLayout(layouts...)
	if found == false {
		jww.WARN.Printf("Unable to locate layout: %s\n", layouts)
		return
	}

	transformLinks := transform.NewEmptyTransforms()

	if viper.GetBool("CanonifyUrls") {
		absURL, err := transform.AbsURL(viper.GetString("BaseUrl"))
		if err != nil {
			return err
		}
		transformLinks = append(transformLinks, absURL...)
	}

	if viper.GetBool("watch") && !viper.GetBool("DisableLiveReload") {
		transformLinks = append(transformLinks, transform.LiveReloadInject)
	}

	transformer := transform.NewChain(transformLinks...)

	var renderBuffer *bytes.Buffer

	if strings.HasSuffix(out, ".xml") {
		renderBuffer = s.NewXMLBuffer()
	} else {
		renderBuffer = new(bytes.Buffer)
	}

	err = s.renderThing(d, layout, renderBuffer)
	if err != nil {
		// Behavior here should be dependent on if running in server or watch mode.
		jww.ERROR.Println(fmt.Errorf("Rendering error: %v", err))
		if !s.Running() {
			os.Exit(-1)
		}
	}

	var outBuffer = new(bytes.Buffer)
	if strings.HasSuffix(out, ".xml") {
		outBuffer = renderBuffer
	} else {
		transformer.Apply(outBuffer, renderBuffer)
	}

	return s.WritePublic(out, outBuffer)
}
开发者ID:johnsto,项目名称:hugo,代码行数:50,代码来源:site.go


示例5: renderXML

func (s *Site) renderXML(name string, d interface{}, layouts ...string) (io.Reader, error) {
	renderBuffer := s.NewXMLBuffer()
	err := s.render(name, d, renderBuffer, layouts...)

	var outBuffer = new(bytes.Buffer)

	absURLInXML, err := transform.AbsURLInXML(viper.GetString("BaseUrl"))
	if err != nil {
		return nil, err
	}

	transformer := transform.NewChain(absURLInXML...)
	transformer.Apply(outBuffer, renderBuffer)
	return outBuffer, err
}
开发者ID:jaden,项目名称:hugo,代码行数:15,代码来源:site.go


示例6: render

func (s *Site) render(d interface{}, out string, layouts ...string) (err error) {

	layout := s.findFirstLayout(layouts...)
	if layout == "" {
		if s.Config.Verbose {
			fmt.Printf("Unable to locate layout: %s\n", layouts)
		}
		return
	}

	transformLinks := transform.NewEmptyTransforms()

	if s.Config.CanonifyUrls {
		absURL, err := transform.AbsURL(s.Config.BaseUrl)
		if err != nil {
			return err
		}
		transformLinks = append(transformLinks, absURL...)
	}

	transformer := transform.NewChain(transformLinks...)

	var renderBuffer *bytes.Buffer

	if strings.HasSuffix(out, ".xml") {
		renderBuffer = s.NewXMLBuffer()
	} else {
		renderBuffer = new(bytes.Buffer)
	}

	err = s.renderThing(d, layout, renderBuffer)
	if err != nil {
		// Behavior here should be dependent on if running in server or watch mode.
		fmt.Println(fmt.Errorf("Rendering error: %v", err))
		if !s.Running() {
			os.Exit(-1)
		}
	}

	var outBuffer = new(bytes.Buffer)
	if strings.HasSuffix(out, ".xml") {
		outBuffer = renderBuffer
	} else {
		transformer.Apply(outBuffer, renderBuffer)
	}

	return s.WritePublic(out, outBuffer)
}
开发者ID:GuoJing,项目名称:hugo,代码行数:48,代码来源:site.go


示例7: renderAndWritePage

func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layouts ...string) error {
	renderBuffer := bp.GetBuffer()
	defer bp.PutBuffer(renderBuffer)

	err := s.render(name, d, renderBuffer, layouts...)

	outBuffer := bp.GetBuffer()
	defer bp.PutBuffer(outBuffer)

	transformLinks := transform.NewEmptyTransforms()

	if viper.GetBool("RelativeURLs") || viper.GetBool("CanonifyURLs") {
		transformLinks = append(transformLinks, transform.AbsURL)
	}

	if s.Running() && viper.GetBool("watch") && !viper.GetBool("DisableLiveReload") {
		transformLinks = append(transformLinks, transform.LiveReloadInject)
	}

	var path []byte

	if viper.GetBool("RelativeURLs") {
		translated, err := s.PageTarget().(target.OptionalTranslator).TranslateRelative(dest)
		if err != nil {
			return err
		}
		path = []byte(helpers.GetDottedRelativePath(translated))
	} else if viper.GetBool("CanonifyURLs") {
		s := viper.GetString("BaseURL")
		if !strings.HasSuffix(s, "/") {
			s += "/"
		}
		path = []byte(s)
	}

	transformer := transform.NewChain(transformLinks...)
	transformer.Apply(outBuffer, renderBuffer, path)

	if err == nil {
		if err = s.WriteDestPage(dest, outBuffer); err != nil {
			return err
		}
	}
	return err
}
开发者ID:maruel,项目名称:hugo,代码行数:45,代码来源:site.go


示例8: renderPage

func (s *Site) renderPage(name string, d interface{}, layouts ...string) (io.Reader, error) {
	renderBuffer := new(bytes.Buffer)
	err := s.render(name, d, renderBuffer, layouts...)

	var outBuffer = new(bytes.Buffer)

	transformLinks := transform.NewEmptyTransforms()

	if viper.GetBool("CanonifyUrls") {
		absURL, err := transform.AbsURL(viper.GetString("BaseUrl"))
		if err != nil {
			return nil, err
		}
		transformLinks = append(transformLinks, absURL...)
	}

	if viper.GetBool("watch") && !viper.GetBool("DisableLiveReload") {
		transformLinks = append(transformLinks, transform.LiveReloadInject)
	}

	transformer := transform.NewChain(transformLinks...)
	transformer.Apply(outBuffer, renderBuffer)
	return outBuffer, err
}
开发者ID:jaden,项目名称:hugo,代码行数:24,代码来源:site.go


示例9: renderAndWriteXML

func (s *Site) renderAndWriteXML(name string, dest string, d interface{}, layouts ...string) error {
	renderBuffer := bp.GetBuffer()
	defer bp.PutBuffer(renderBuffer)
	renderBuffer.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n")

	err := s.render(name, d, renderBuffer, layouts...)

	absURLInXML, err := transform.AbsURLInXML(viper.GetString("BaseUrl"))
	if err != nil {
		return err
	}

	outBuffer := bp.GetBuffer()
	defer bp.PutBuffer(outBuffer)

	transformer := transform.NewChain(absURLInXML...)
	transformer.Apply(outBuffer, renderBuffer)

	if err == nil {
		err = s.WriteDestFile(dest, outBuffer)
	}

	return err
}
开发者ID:dunn,项目名称:hugo,代码行数:24,代码来源:site.go


示例10: render

func (s *Site) render(d interface{}, out string, layouts ...string) (err error) {

	layout := s.findFirstLayout(layouts...)
	if layout == "" {
		if s.Config.Verbose {
			fmt.Printf("Unable to locate layout: %s\n", layouts)
		}
		return
	}

	section := ""
	if page, ok := d.(*Page); ok {
		section, _ = page.RelPermalink()
	}

	transformer := transform.NewChain(
		&transform.AbsURL{BaseURL: s.Config.BaseUrl},
		&transform.NavActive{Section: section},
	)

	renderReader, renderWriter := io.Pipe()
	go func() {
		err = s.renderThing(d, layout, renderWriter)
		if err != nil {
			panic(err)
		}
	}()

	trReader, trWriter := io.Pipe()
	go func() {
		transformer.Apply(trWriter, renderReader)
		trWriter.Close()
	}()

	return s.WritePublic(out, trReader)
}
开发者ID:nelsonsilva,项目名称:hugo,代码行数:36,代码来源:site.go



注:本文中的github.com/spf13/hugo/transform.NewChain函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang transform.NewEmptyTransforms函数代码示例发布时间:2022-05-28
下一篇:
Golang tpl.New函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap