mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-25 00:52:46 +00:00
parent
be72f234f8
commit
be3a3506c4
2 changed files with 28 additions and 4 deletions
|
@ -92,10 +92,7 @@ func NewContent(cmd *cobra.Command, args []string) {
|
|||
|
||||
var kind string
|
||||
|
||||
// assume the first directory is the section (kind)
|
||||
if strings.Contains(createpath[1:], helpers.FilePathSeparator) {
|
||||
kind = helpers.GuessSection(createpath)
|
||||
}
|
||||
createpath, kind = newContentPathSection(createpath)
|
||||
|
||||
if contentType != "" {
|
||||
kind = contentType
|
||||
|
@ -251,6 +248,19 @@ min_version = 0.13
|
|||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func createConfig(inpath string, kind string) (err error) {
|
||||
in := map[string]string{
|
||||
"baseurl": "http://replace-this-with-your-hugo-site.com/",
|
||||
|
|
14
commands/new_test.go
Normal file
14
commands/new_test.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Issue #1133
|
||||
func TestNewContentPathSectionWithForwardSlashes(t *testing.T) {
|
||||
p, s := newContentPathSection("/post/new.md")
|
||||
assert.Equal(t, filepath.FromSlash("/post/new.md"), p)
|
||||
assert.Equal(t, "post", s)
|
||||
}
|
Loading…
Reference in a new issue