本文整理汇总了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)
}
}
示例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)
}
}
示例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)
}
示例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)
}
}
示例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)
}
}
}
}