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

Golang helpers.IsEmpty函数代码示例

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

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



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

示例1: NewSite

// NewSite creates a new hugo site and initializes a structured Hugo directory.
func NewSite(cmd *cobra.Command, args []string) {
	if len(args) < 1 {
		cmd.Usage()
		jww.FATAL.Fatalln("path needs to be provided")
	}

	createpath, err := filepath.Abs(filepath.Clean(args[0]))
	if err != nil {
		cmd.Usage()
		jww.FATAL.Fatalln(err)
	}

	if x, _ := helpers.Exists(createpath, hugofs.SourceFs); x {
		y, _ := helpers.IsDir(createpath, hugofs.SourceFs)
		if z, _ := helpers.IsEmpty(createpath, hugofs.SourceFs); y && z {
			jww.INFO.Println(createpath, "already exists and is empty")
		} else {
			jww.FATAL.Fatalln(createpath, "already exists and is not empty")
		}
	}

	mkdir(createpath, "layouts")
	mkdir(createpath, "content")
	mkdir(createpath, "archetypes")
	mkdir(createpath, "static")
	mkdir(createpath, "data")

	createConfig(createpath, configFormat)
}
开发者ID:n2xnot,项目名称:hugo,代码行数:30,代码来源:new.go


示例2: createSiteFromJekyll

// TODO: Consider calling doNewSite() instead?
func createSiteFromJekyll(jekyllRoot, targetDir string, force bool) error {
	fs := hugofs.Source()
	if exists, _ := helpers.Exists(targetDir, fs); exists {
		if isDir, _ := helpers.IsDir(targetDir, fs); !isDir {
			return errors.New("Target path \"" + targetDir + "\" already exists but not a directory")
		}

		isEmpty, _ := helpers.IsEmpty(targetDir, fs)

		if !isEmpty && !force {
			return errors.New("Target path \"" + targetDir + "\" already exists and is not empty")
		}
	}

	jekyllConfig := loadJekyllConfig(jekyllRoot)

	// Crude test to make sure at least one of _drafts/ and _posts/ exists
	// and is not empty.
	hasPostsOrDrafts := false
	postsDir := filepath.Join(jekyllRoot, "_posts")
	draftsDir := filepath.Join(jekyllRoot, "_drafts")
	for _, d := range []string{postsDir, draftsDir} {
		if exists, _ := helpers.Exists(d, fs); exists {
			if isDir, _ := helpers.IsDir(d, fs); isDir {
				if isEmpty, _ := helpers.IsEmpty(d, fs); !isEmpty {
					hasPostsOrDrafts = true
				}
			}
		}
	}
	if !hasPostsOrDrafts {
		return errors.New("Your Jekyll root contains neither posts nor drafts, aborting.")
	}

	mkdir(targetDir, "layouts")
	mkdir(targetDir, "content")
	mkdir(targetDir, "archetypes")
	mkdir(targetDir, "static")
	mkdir(targetDir, "data")
	mkdir(targetDir, "themes")

	createConfigFromJekyll(targetDir, "yaml", jekyllConfig)

	copyJekyllFilesAndFolders(jekyllRoot, filepath.Join(targetDir, "static"))

	return nil
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:48,代码来源:import_jekyll.go


示例3: doNewSite

func doNewSite(basepath string, force bool) error {
	dirs := []string{
		filepath.Join(basepath, "layouts"),
		filepath.Join(basepath, "content"),
		filepath.Join(basepath, "archetypes"),
		filepath.Join(basepath, "static"),
		filepath.Join(basepath, "data"),
		filepath.Join(basepath, "themes"),
	}

	if exists, _ := helpers.Exists(basepath, hugofs.Source()); exists {
		if isDir, _ := helpers.IsDir(basepath, hugofs.Source()); !isDir {
			return errors.New(basepath + " already exists but not a directory")
		}

		isEmpty, _ := helpers.IsEmpty(basepath, hugofs.Source())

		switch {
		case !isEmpty && !force:
			return errors.New(basepath + " already exists and is not empty")

		case !isEmpty && force:
			all := append(dirs, filepath.Join(basepath, "config."+configFormat))
			for _, path := range all {
				if exists, _ := helpers.Exists(path, hugofs.Source()); exists {
					return errors.New(path + " already exists")
				}
			}
		}
	}

	for _, dir := range dirs {
		hugofs.Source().MkdirAll(dir, 0777)
	}

	createConfig(basepath, configFormat)

	jww.FEEDBACK.Printf("Congratulations! Your new Hugo site is created in %q.\n\n", basepath)
	jww.FEEDBACK.Println(`Just a few more steps and you're ready to go:

1. Download a theme into the same-named folder. Choose a theme from https://themes.gohugo.io or
   create your own with the "hugo new theme <THEMENAME>" command
2. Perhaps you want to add some content. You can add single files with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>"
3. Start the built-in live server via "hugo server"

For more information read the documentation at https://gohugo.io.`)

	return nil
}
开发者ID:CODECOMMUNITY,项目名称:hugo,代码行数:49,代码来源:new.go


示例4: doNewSite

func doNewSite(basepath string, force bool) error {
	dirs := []string{
		filepath.Join(basepath, "layouts"),
		filepath.Join(basepath, "content"),
		filepath.Join(basepath, "archetypes"),
		filepath.Join(basepath, "static"),
		filepath.Join(basepath, "data"),
		filepath.Join(basepath, "themes"),
	}

	if exists, _ := helpers.Exists(basepath, hugofs.Source()); exists {
		if isDir, _ := helpers.IsDir(basepath, hugofs.Source()); !isDir {
			return errors.New(basepath + " already exists but not a directory")
		}

		isEmpty, _ := helpers.IsEmpty(basepath, hugofs.Source())

		switch {
		case !isEmpty && !force:
			return errors.New(basepath + " already exists and is not empty")

		case !isEmpty && force:
			all := append(dirs, filepath.Join(basepath, "config."+configFormat))
			for _, path := range all {
				if exists, _ := helpers.Exists(path, hugofs.Source()); exists {
					return errors.New(path + " already exists")
				}
			}
		}
	}

	for _, dir := range dirs {
		hugofs.Source().MkdirAll(dir, 0777)
	}

	createConfig(basepath, configFormat)

	jww.FEEDBACK.Printf("Congratulations! Your new Hugo site is created in %s.\n\n", basepath)
	jww.FEEDBACK.Println(nextStepsText())

	return nil
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:42,代码来源:new.go


示例5: doNewSite

func doNewSite(basepath string, force bool) error {
	dirs := []string{
		filepath.Join(basepath, "layouts"),
		filepath.Join(basepath, "content"),
		filepath.Join(basepath, "archetypes"),
		filepath.Join(basepath, "static"),
		filepath.Join(basepath, "data"),
		filepath.Join(basepath, "themes"),
	}

	if exists, _ := helpers.Exists(basepath, hugofs.SourceFs); exists {
		if isDir, _ := helpers.IsDir(basepath, hugofs.SourceFs); !isDir {
			return errors.New(basepath + " already exists but not a directory")
		}

		isEmpty, _ := helpers.IsEmpty(basepath, hugofs.SourceFs)

		switch {
		case !isEmpty && !force:
			return errors.New(basepath + " already exists and is not empty")

		case !isEmpty && force:
			all := append(dirs, filepath.Join(basepath, "config."+configFormat))
			for _, path := range all {
				if exists, _ := helpers.Exists(path, hugofs.SourceFs); exists {
					return errors.New(path + " already exists")
				}
			}
		}
	}

	for _, dir := range dirs {
		hugofs.SourceFs.MkdirAll(dir, 0777)
	}

	createConfig(basepath, configFormat)

	return nil
}
开发者ID:bramp,项目名称:hugo,代码行数:39,代码来源:new.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang helpers.MakePath函数代码示例发布时间:2022-05-28
下一篇:
Golang helpers.IsDir函数代码示例发布时间: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