diff options
Diffstat (limited to 'create/content.go')
-rw-r--r-- | create/content.go | 80 |
1 files changed, 58 insertions, 22 deletions
diff --git a/create/content.go b/create/content.go index e48dfc078..0e05adf93 100644 --- a/create/content.go +++ b/create/content.go @@ -25,6 +25,8 @@ import ( "path/filepath" "strings" + "github.com/gohugoio/hugo/hugofs/files" + "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/helpers" @@ -50,7 +52,10 @@ func NewContent( if isDir { - langFs := hugofs.NewLanguageFs(s.Language().Lang, sites.LanguageSet(), archetypeFs) + langFs, err := hugofs.NewLanguageFs(sites.LanguageSet(), archetypeFs) + if err != nil { + return err + } cm, err := mapArcheTypeDir(ps, langFs, archetypeFilename) if err != nil { @@ -64,7 +69,7 @@ func NewContent( } name := filepath.Base(targetPath) - return newContentFromDir(archetypeFilename, sites, archetypeFs, sourceFs, cm, name, contentPath) + return newContentFromDir(archetypeFilename, sites, sourceFs, cm, name, contentPath) } // Building the sites can be expensive, so only do it if really needed. @@ -111,9 +116,9 @@ func NewContent( return nil } -func targetSite(sites *hugolib.HugoSites, fi *hugofs.LanguageFileInfo) *hugolib.Site { +func targetSite(sites *hugolib.HugoSites, fi hugofs.FileMetaInfo) *hugolib.Site { for _, s := range sites.Sites { - if fi.Lang() == s.Language().Lang { + if fi.Meta().Lang() == s.Language().Lang { return s } } @@ -123,13 +128,14 @@ func targetSite(sites *hugolib.HugoSites, fi *hugofs.LanguageFileInfo) *hugolib. func newContentFromDir( archetypeDir string, sites *hugolib.HugoSites, - sourceFs, targetFs afero.Fs, + targetFs afero.Fs, cm archetypeMap, name, targetPath string) error { for _, f := range cm.otherFiles { - filename := f.Filename() + meta := f.Meta() + filename := meta.Path() // Just copy the file to destination. - in, err := sourceFs.Open(filename) + in, err := meta.Open() if err != nil { return errors.Wrap(err, "failed to open non-content file") } @@ -156,7 +162,7 @@ func newContentFromDir( } for _, f := range cm.contentFiles { - filename := f.Filename() + filename := f.Meta().Path() s := targetSite(sites, f) targetFilename := filepath.Join(targetPath, strings.TrimPrefix(filename, archetypeDir)) @@ -177,9 +183,9 @@ func newContentFromDir( type archetypeMap struct { // These needs to be parsed and executed as Go templates. - contentFiles []*hugofs.LanguageFileInfo + contentFiles []hugofs.FileMetaInfo // These are just copied to destination. - otherFiles []*hugofs.LanguageFileInfo + otherFiles []hugofs.FileMetaInfo // If the templates needs a fully built site. This can potentially be // expensive, so only do when needed. siteUsed bool @@ -192,7 +198,7 @@ func mapArcheTypeDir( var m archetypeMap - walkFn := func(filename string, fi os.FileInfo, err error) error { + walkFn := func(path string, fi hugofs.FileMetaInfo, err error) error { if err != nil { return err @@ -202,12 +208,12 @@ func mapArcheTypeDir( return nil } - fil := fi.(*hugofs.LanguageFileInfo) + fil := fi.(hugofs.FileMetaInfo) - if hugolib.IsContentFile(filename) { + if files.IsContentFile(path) { m.contentFiles = append(m.contentFiles, fil) if !m.siteUsed { - m.siteUsed, err = usesSiteVar(fs, filename) + m.siteUsed, err = usesSiteVar(fs, path) if err != nil { return err } @@ -220,7 +226,15 @@ func mapArcheTypeDir( return nil } - if err := helpers.SymbolicWalk(fs, archetypeDir, walkFn); err != nil { + walkCfg := hugofs.WalkwayConfig{ + WalkFn: walkFn, + Fs: fs, + Root: archetypeDir, + } + + w := hugofs.NewWalkway(walkCfg) + + if err := w.Walk(); err != nil { return m, errors.Wrapf(err, "failed to walk archetype dir %q", archetypeDir) } @@ -254,17 +268,29 @@ func resolveContentPath(sites *hugolib.HugoSites, fs afero.Fs, targetPath string } } - for _, ss := range sites.Sites { - contentDir := ss.PathSpec.ContentDir + var dirLang string + + for _, dir := range sites.BaseFs.Content.Dirs { + meta := dir.Meta() + contentDir := meta.Filename() + if !strings.HasSuffix(contentDir, helpers.FilePathSeparator) { contentDir += helpers.FilePathSeparator } + if strings.HasPrefix(targetPath, contentDir) { - siteContentDir = ss.PathSpec.ContentDir - if s == nil { + siteContentDir = contentDir + dirLang = meta.Lang() + break + } + } + + if s == nil && dirLang != "" { + for _, ss := range sites.Sites { + if ss.Lang() == dirLang { s = ss + break } - break } } @@ -280,12 +306,22 @@ func resolveContentPath(sites *hugolib.HugoSites, fs afero.Fs, targetPath string } } + if siteContentDir == "" { + + } + if siteContentDir != "" { pp := filepath.Join(siteContentDir, strings.TrimPrefix(targetPath, siteContentDir)) return s.PathSpec.AbsPathify(pp), s - } else { - return s.PathSpec.AbsPathify(filepath.Join(first.PathSpec.ContentDir, targetPath)), s + var contentDir string + for _, dir := range sites.BaseFs.Content.Dirs { + contentDir = dir.Meta().Filename() + if dir.Meta().Lang() == s.Lang() { + break + } + } + return s.PathSpec.AbsPathify(filepath.Join(contentDir, targetPath)), s } } |