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

Golang goldsmith.Context类代码示例

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

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



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

示例1: Initialize

func (i *include) Initialize(ctx goldsmith.Context) error {
	var paths []string
	err := filepath.Walk(i.src, func(path string, info os.FileInfo, err error) error {
		if err == nil && !info.IsDir() {
			paths = append(paths, path)
		}

		return err
	})

	if err != nil {
		return err
	}

	for _, path := range paths {
		srcRelPath, err := filepath.Rel(i.src, path)
		if err != nil {
			panic(err)
		}

		dstRelPath := filepath.Join(i.dst, srcRelPath)
		f, err := goldsmith.NewFileFromAsset(dstRelPath, path)
		if err != nil {
			return err
		}

		ctx.DispatchFile(f)
	}

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:31,代码来源:include.go


示例2: Process

func (*minify) Process(ctx goldsmith.Context, f goldsmith.File) error {
	var (
		buff bytes.Buffer
		err  error
	)

	switch m := min.New(); filepath.Ext(f.Path()) {
	case ".css":
		err = css.Minify(m, &buff, f, nil)
	case ".html", ".htm":
		err = html.Minify(m, &buff, f, nil)
	case ".js":
		err = js.Minify(m, &buff, f, nil)
	case ".json":
		err = json.Minify(m, &buff, f, nil)
	case ".svg":
		err = svg.Minify(m, &buff, f, nil)
	case ".xml":
		err = xml.Minify(m, &buff, f, nil)
	}

	if err != nil {
		return err
	}

	nf := goldsmith.NewFileFromData(f.Path(), buff.Bytes())
	nf.CopyValues(f)
	ctx.DispatchFile(nf)

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:31,代码来源:minify.go


示例3: Finalize

func (t *breadcrumbs) Finalize(ctx goldsmith.Context) error {
	for _, n := range t.allNodes {
		if len(n.parentName) == 0 {
			continue
		}

		if parent, ok := t.namedNodes[n.parentName]; ok {
			parent.Children = append(parent.Children, n)
			n.Parent = parent
		} else {
			return fmt.Errorf("undefined parent: %s", n.parentName)
		}
	}

	for _, n := range t.allNodes {
		var ancestors []*bcNode
		for c := n.Parent; c != nil; c = c.Parent {
			ancestors = append([]*bcNode{c}, ancestors...)
		}

		n.File.SetValue(t.crumbsKey, bcInfo{ancestors, n})
		ctx.DispatchFile(n.File)
	}

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:26,代码来源:breadcrumbs.go


示例4: Finalize

func (c *collection) Finalize(ctx goldsmith.Context) error {
	for _, files := range c.groups {
		fg := &fileGroup{files, c.comp}
		sort.Sort(fg)
	}

	for _, f := range c.files {
		ctx.DispatchFile(f)
	}

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:12,代码来源:collection.go


示例5: cached

func cached(ctx goldsmith.Context, srcPath, dstPath string) bool {
	srcPathFull := filepath.Join(ctx.SrcDir(), srcPath)
	srcStat, err := os.Stat(srcPathFull)
	if err != nil {
		return false
	}

	dstPathFull := filepath.Join(ctx.DstDir(), dstPath)
	dstStat, err := os.Stat(dstPathFull)
	if err != nil {
		return false
	}

	return dstStat.ModTime().Unix() >= srcStat.ModTime().Unix()
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:15,代码来源:thumbnail.go


示例6: Process

func (*frontmatter) Process(ctx goldsmith.Context, f goldsmith.File) error {
	meta, body, err := fm.Parse(f)
	if err != nil {
		return err
	}

	nf := goldsmith.NewFileFromData(f.Path(), body.Bytes())
	nf.CopyValues(f)
	for name, value := range meta {
		nf.SetValue(name, value)
	}
	ctx.DispatchFile(nf)

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:15,代码来源:frontmatter.go


示例7: Finalize

func (t *tags) Finalize(ctx goldsmith.Context) error {
	for _, meta := range t.info {
		sort.Sort(meta.Files)
	}

	if t.indexMeta != nil {
		for _, f := range t.buildPages(ctx, t.info) {
			ctx.DispatchFile(f)
		}
	}

	for _, f := range t.files {
		ctx.DispatchFile(f)
	}

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:17,代码来源:tags.go


示例8: Process

func (l *livejs) Process(ctx goldsmith.Context, f goldsmith.File) error {
	doc, err := goquery.NewDocumentFromReader(f)
	if err != nil {
		return err
	}

	doc.Find("body").AppendHtml(l.js)

	html, err := doc.Html()
	if err != nil {
		return err
	}

	nf := goldsmith.NewFileFromData(f.Path(), []byte(html))
	ctx.DispatchFile(nf)

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:18,代码来源:livejs.go


示例9: Finalize

func (idx *index) Finalize(ctx goldsmith.Context) error {
	for name, summary := range idx.dirs {
		sort.Sort(summary.entries)

		f := summary.index
		if f == nil {
			f = goldsmith.NewFileFromData(path.Join(name, idx.filename), make([]byte, 0))
			for name, value := range idx.meta {
				f.SetValue(name, value)
			}
		}

		f.SetValue(idx.filesKey, summary.entries)
		ctx.DispatchFile(f)
	}

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:18,代码来源:index.go


示例10: Process

func (lay *layout) Process(ctx goldsmith.Context, f goldsmith.File) error {
	var buff bytes.Buffer
	if _, err := buff.ReadFrom(f); err != nil {
		return err
	}

	if _, ok := f.Value(lay.layoutKey); ok {
		f.SetValue(lay.contentKey, template.HTML(buff.Bytes()))

		lay.filesMtx.Lock()
		lay.files = append(lay.files, f)
		lay.filesMtx.Unlock()
	} else {
		ctx.DispatchFile(f)
	}

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:18,代码来源:layout.go


示例11: Process

func (idx *index) Process(ctx goldsmith.Context, f goldsmith.File) error {
	idx.dirsMtx.Lock()
	defer idx.dirsMtx.Unlock()

	curr := f.Path()
	leaf := true

	for {
		if handled, _ := idx.handled[curr]; handled {
			break
		}

		idx.handled[curr] = true

		dir := path.Dir(curr)
		base := path.Base(curr)

		summary, ok := idx.dirs[dir]
		if !ok {
			summary = new(dirSummary)
			idx.dirs[dir] = summary
		}

		if leaf {
			if base == idx.filename {
				summary.index = f
			} else {
				ctx.DispatchFile(f)
			}
		}

		entry := DirEntry{Name: base, Path: curr, IsDir: !leaf, File: f}
		summary.entries = append(summary.entries, entry)

		if dir == "." {
			break
		}

		curr = dir
		leaf = false
	}

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:44,代码来源:index.go


示例12: Process

func (m *markdown) Process(ctx goldsmith.Context, f goldsmith.File) error {
	var buff bytes.Buffer
	if _, err := buff.ReadFrom(f); err != nil {
		return err
	}

	var data []byte
	switch m.mdType {
	case mdCommon:
		data = blackfriday.MarkdownCommon(buff.Bytes())
	case mdBasic:
		data = blackfriday.MarkdownBasic(buff.Bytes())
	}

	name := strings.TrimSuffix(f.Path(), path.Ext(f.Path())) + ".html"
	nf := goldsmith.NewFileFromData(name, data)
	nf.CopyValues(f)
	ctx.DispatchFile(nf)

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:21,代码来源:markdown.go


示例13: Process

func (t *thumbnail) Process(ctx goldsmith.Context, f goldsmith.File) error {
	defer ctx.DispatchFile(f)

	thumbPath, create := t.thumbName(f.Path())
	if !create {
		return nil
	}

	var (
		fn  goldsmith.File
		err error
	)

	if cached(ctx, f.Path(), thumbPath) {
		thumbPathDst := filepath.Join(ctx.DstDir(), thumbPath)
		fn, err = goldsmith.NewFileFromAsset(thumbPath, thumbPathDst)
		if err != nil {
			return err
		}
	} else {
		var err error
		fn, err = t.thumbnail(f, thumbPath)
		if err != nil {
			return err
		}
	}

	ctx.DispatchFile(fn)
	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:30,代码来源:thumbnail.go


示例14: Finalize

func (lay *layout) Finalize(ctx goldsmith.Context) error {
	for _, f := range lay.files {
		name, ok := f.Value(lay.layoutKey)
		if !ok {
			ctx.DispatchFile(f)
			continue
		}

		nameStr, ok := name.(string)
		if !ok {
			ctx.DispatchFile(f)
			continue
		}

		var buff bytes.Buffer
		if err := lay.tmpl.ExecuteTemplate(&buff, nameStr, f); err != nil {
			return err
		}

		nf := goldsmith.NewFileFromData(f.Path(), buff.Bytes())
		nf.CopyValues(f)
		ctx.DispatchFile(nf)
	}

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:26,代码来源:layout.go


示例15: Process

func (a *abs) Process(ctx goldsmith.Context, f goldsmith.File) error {
	doc, err := goquery.NewDocumentFromReader(f)
	if err != nil {
		return err
	}

	for _, attr := range a.attrs {
		path := fmt.Sprintf("*[%s]", attr)
		doc.Find(path).Each(func(index int, sel *goquery.Selection) {
			baseUrl, err := url.Parse(f.Path())
			val, _ := sel.Attr(attr)

			currUrl, err := url.Parse(val)
			if err != nil || currUrl.IsAbs() {
				return
			}

			currUrl = baseUrl.ResolveReference(currUrl)
			if a.baseUrl != nil {
				currUrl = a.baseUrl.ResolveReference(currUrl)
			}

			sel.SetAttr(attr, currUrl.String())
		})
	}

	html, err := doc.Html()
	if err != nil {
		return err
	}

	nf := goldsmith.NewFileFromData(f.Path(), []byte(html))
	nf.CopyValues(f)
	ctx.DispatchFile(nf)

	return nil
}
开发者ID:FooSoft,项目名称:goldsmith-plugins,代码行数:37,代码来源:abs.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang goldsmith.File类代码示例发布时间:2022-05-23
下一篇:
Golang pt.Scene类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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