Fix content dir resolution when main project is a Hugo Module

Fixes #9177
This commit is contained in:
Bjørn Erik Pedersen 2021-11-16 19:54:41 +01:00
parent 1ed8069a3a
commit 2e70f61fb0
3 changed files with 6 additions and 2 deletions

View file

@ -64,6 +64,7 @@ type FileMeta struct {
IsOrdered bool IsOrdered bool
IsSymlink bool IsSymlink bool
IsRootFile bool IsRootFile bool
IsProject bool
Watch bool Watch bool
Classifier files.ContentClass Classifier files.ContentClass

View file

@ -62,6 +62,7 @@ func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) {
rm.Meta.BaseDir = rm.ToBasedir rm.Meta.BaseDir = rm.ToBasedir
rm.Meta.MountRoot = rm.path rm.Meta.MountRoot = rm.path
rm.Meta.Module = rm.Module rm.Meta.Module = rm.Module
rm.Meta.IsProject = rm.IsProject
meta := rm.Meta.Copy() meta := rm.Meta.Copy()
@ -118,6 +119,7 @@ type RootMapping struct {
To string // The source directory or file. To string // The source directory or file.
ToBasedir string // The base of To. May be empty if an absolute path was provided. ToBasedir string // The base of To. May be empty if an absolute path was provided.
Module string // The module path/ID. Module string // The module path/ID.
IsProject bool // Whether this is a mount in the main project.
Meta *FileMeta // File metadata (lang etc.) Meta *FileMeta // File metadata (lang etc.)
fi FileMetaInfo fi FileMetaInfo

View file

@ -136,7 +136,7 @@ func (b *BaseFs) AbsProjectContentDir(filename string) (string, string, error) {
isAbs := filepath.IsAbs(filename) isAbs := filepath.IsAbs(filename)
for _, dir := range b.SourceFilesystems.Content.Dirs { for _, dir := range b.SourceFilesystems.Content.Dirs {
meta := dir.Meta() meta := dir.Meta()
if meta.Module != "project" { if !meta.IsProject {
continue continue
} }
if isAbs { if isAbs {
@ -161,7 +161,7 @@ func (b *BaseFs) AbsProjectContentDir(filename string) (string, string, error) {
contentDirs := b.SourceFilesystems.Content.Dirs contentDirs := b.SourceFilesystems.Content.Dirs
for i := len(contentDirs) - 1; i >= 0; i-- { for i := len(contentDirs) - 1; i >= 0; i-- {
meta := contentDirs[i].Meta() meta := contentDirs[i].Meta()
if meta.Module == "project" { if meta.IsProject {
return filename, filepath.Join(meta.Filename, filename), nil return filename, filepath.Join(meta.Filename, filename), nil
} }
} }
@ -645,6 +645,7 @@ func (b *sourceFilesystemsBuilder) createModFs(
To: filename, To: filename,
ToBasedir: base, ToBasedir: base,
Module: md.Module.Path(), Module: md.Module.Path(),
IsProject: md.isMainProject,
Meta: &hugofs.FileMeta{ Meta: &hugofs.FileMeta{
Watch: md.Watch(), Watch: md.Watch(),
Weight: mountWeight, Weight: mountWeight,