コード例 #1
0
ファイル: new.go プロジェクト: vinchu/hugo
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)
	}
}
コード例 #2
0
ファイル: file.go プロジェクト: dunn/hugo
func (f *File) Section() string {
	if f.section != "" {
		return f.section
	}
	f.section = helpers.GuessSection(f.Dir())
	return f.section
}
コード例 #3
0
ファイル: new.go プロジェクト: nurhavid/hugo
// 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)
	}
}
コード例 #4
0
ファイル: new.go プロジェクト: maruel/hugo
func newContentPathSection(path string) (string, string) {
	// Forward slashes is used in all examples. Convert if needed.
	// Issue #1133
	createpath := strings.Replace(path, "/", helpers.FilePathSeparator, -1)
	var section string
	// assume the first directory is the section (kind)
	if strings.Contains(createpath[1:], helpers.FilePathSeparator) {
		section = helpers.GuessSection(createpath)
	}

	return createpath, section
}
コード例 #5
0
ファイル: file.go プロジェクト: eRadical/hugo
func NewFile(relpath string) *File {
	f := &File{
		relpath: relpath,
	}

	f.dir, f.logicalName = filepath.Split(f.relpath)
	f.ext = strings.TrimPrefix(filepath.Ext(f.LogicalName()), ".")
	f.section = helpers.GuessSection(f.Dir())
	f.uniqueID = helpers.Md5String(f.LogicalName())

	return f
}
コード例 #6
0
ファイル: file.go プロジェクト: tubo028/hugo
// NewFile creates a new File pointer with the given relative path.
func NewFile(relpath string) *File {
	f := &File{
		relpath: relpath,
	}

	f.dir, f.logicalName = filepath.Split(f.relpath)
	f.ext = strings.TrimPrefix(filepath.Ext(f.LogicalName()), ".")
	f.baseName = helpers.Filename(f.LogicalName())

	f.lang = strings.TrimPrefix(filepath.Ext(f.baseName), ".")
	if f.lang == "" {
		f.lang = viper.GetString("defaultContentLanguage")
	}
	f.translationBaseName = helpers.Filename(f.baseName)

	f.section = helpers.GuessSection(f.Dir())
	f.uniqueID = helpers.Md5String(f.LogicalName())

	return f
}
コード例 #7
0
ファイル: page.go プロジェクト: vinchu/hugo
func (p *Page) guessSection() {
	if p.Section == "" {
		p.Section = helpers.GuessSection(p.FileName)
	}
}