本文整理汇总了Golang中github.com/spf13/hugo/create.NewContent函数的典型用法代码示例。如果您正苦于以下问题:Golang NewContent函数的具体用法?Golang NewContent怎么用?Golang NewContent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewContent函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewContent
// NewContent adds new content to a Hugo site.
func NewContent(cmd *cobra.Command, args []string) {
InitializeConfig()
if cmd.Flags().Lookup("format").Changed {
viper.Set("MetaDataFormat", configFormat)
}
if len(args) < 1 {
cmd.Usage()
jww.FATAL.Fatalln("path needs to be provided")
}
createpath := args[0]
var kind string
createpath, kind = newContentPathSection(createpath)
if contentType != "" {
kind = contentType
}
err := create.NewContent(kind, createpath)
if err != nil {
jww.ERROR.Println(err)
}
}
开发者ID:maruel,项目名称:hugo,代码行数:28,代码来源:new.go
示例2: NewContent
func NewContent(cmd *cobra.Command, args []string) {
InitializeConfig()
if len(args) < 1 {
cmd.Usage()
jww.FATAL.Fatalln("path needs to be provided")
}
createpath := args[0]
var kind string
// assume the first directory is the section (kind)
if strings.Contains(createpath[1:], "/") {
kind = helpers.GuessSection(createpath)
}
if contentType != "" {
kind = contentType
}
err := create.NewContent(kind, createpath)
if err != nil {
jww.ERROR.Println(err)
}
}
开发者ID:vinchu,项目名称:hugo,代码行数:26,代码来源:new.go
示例3: NewContent
// NewContent adds new content to a Hugo site.
func NewContent(cmd *cobra.Command, args []string) error {
if err := InitializeConfig(); err != nil {
return err
}
if flagChanged(cmd.Flags(), "format") {
viper.Set("MetaDataFormat", configFormat)
}
if flagChanged(cmd.Flags(), "editor") {
viper.Set("NewContentEditor", contentEditor)
}
if len(args) < 1 {
return newUserError("path needs to be provided")
}
createpath := args[0]
var kind string
createpath, kind = newContentPathSection(createpath)
if contentType != "" {
kind = contentType
}
return create.NewContent(kind, createpath)
}
开发者ID:nitoyon,项目名称:hugo,代码行数:31,代码来源:new.go
示例4: NewContent
// NewContent adds new content to a Hugo site.
func NewContent(cmd *cobra.Command, args []string) {
InitializeConfig()
if cmd.Flags().Lookup("format").Changed {
viper.Set("MetaDataFormat", configFormat)
}
if len(args) < 1 {
cmd.Usage()
jww.FATAL.Fatalln("path needs to be provided")
}
createpath := args[0]
var kind string
// assume the first directory is the section (kind)
if strings.Contains(createpath[1:], helpers.FilePathSeparator) {
kind = helpers.GuessSection(createpath)
}
if contentType != "" {
kind = contentType
}
err := create.NewContent(kind, createpath)
if err != nil {
jww.ERROR.Println(err)
}
}
开发者ID:nurhavid,项目名称:hugo,代码行数:31,代码来源:new.go
示例5: TestNewContent
func TestNewContent(t *testing.T) {
initViper()
err := initFs()
if err != nil {
t.Fatalf("initialization error: %s", err)
}
cases := []struct {
kind string
path string
resultStrings []string
}{
{"post", "post/sample-1.md", []string{`title = "sample 1"`, `test = "test1"`}},
{"stump", "stump/sample-2.md", []string{`title = "sample 2"`}}, // no archetype file
{"", "sample-3.md", []string{`title = "sample 3"`}}, // no archetype
{"product", "product/sample-4.md", []string{`title = "sample 4"`}}, // empty archetype front matter
}
for i, c := range cases {
err = create.NewContent(hugofs.Source(), c.kind, c.path)
if err != nil {
t.Errorf("[%d] NewContent: %s", i, err)
}
fname := filepath.Join(os.TempDir(), "content", filepath.FromSlash(c.path))
_, err = hugofs.Source().Stat(fname)
if err != nil {
t.Errorf("[%d] Stat: %s", i, err)
}
for _, v := range c.resultStrings {
found, err := afero.FileContainsBytes(hugofs.Source(), fname, []byte(v))
if err != nil {
t.Errorf("[%d] FileContainsBytes: %s", i, err)
}
if !found {
t.Errorf("content missing from output: %q", v)
}
}
}
}
开发者ID:CODECOMMUNITY,项目名称:hugo,代码行数:42,代码来源:content_test.go
注:本文中的github.com/spf13/hugo/create.NewContent函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论