@@ -126,10 +126,28 @@ type SourceFilesystems struct {
126
126
StaticDirs []hugofs.FileMetaInfo
127
127
}
128
128
129
+ // FileSystems returns the FileSystems relevant for the change detection
130
+ // in server mode.
131
+ // Note: This does currently not return any static fs.
132
+ func (s * SourceFilesystems ) FileSystems () []* SourceFilesystem {
133
+ return []* SourceFilesystem {
134
+ s .Content ,
135
+ s .Data ,
136
+ s .I18n ,
137
+ s .Layouts ,
138
+ s .Archetypes ,
139
+ // TODO(bep) static
140
+ }
141
+
142
+ }
143
+
129
144
// A SourceFilesystem holds the filesystem for a given source type in Hugo (data,
130
145
// i18n, layouts, static) and additional metadata to be able to use that filesystem
131
146
// in server mode.
132
147
type SourceFilesystem struct {
148
+ // Name matches one in files.ComponentFolders
149
+ Name string
150
+
133
151
// This is a virtual composite filesystem. It expects path relative to a context.
134
152
Fs afero.Fs
135
153
@@ -275,6 +293,19 @@ func (d *SourceFilesystem) Contains(filename string) bool {
275
293
return false
276
294
}
277
295
296
+ // Path returns the relative path to the given filename if it is a member of
297
+ // of the current filesystem, an empty string if not.
298
+ func (d * SourceFilesystem ) Path (filename string ) string {
299
+ for _ , dir := range d .Dirs {
300
+ meta := dir .Meta ()
301
+ if strings .HasPrefix (filename , meta .Filename ()) {
302
+ p := strings .TrimPrefix (strings .TrimPrefix (filename , meta .Filename ()), filePathSeparator )
303
+ return p
304
+ }
305
+ }
306
+ return ""
307
+ }
308
+
278
309
// RealDirs gets a list of absolute paths to directories starting from the given
279
310
// path.
280
311
func (d * SourceFilesystem ) RealDirs (from string ) []string {
@@ -349,12 +380,14 @@ func newSourceFilesystemsBuilder(p *paths.Paths, logger *loggers.Logger, b *Base
349
380
return & sourceFilesystemsBuilder {p : p , logger : logger , sourceFs : sourceFs , theBigFs : b .theBigFs , result : & SourceFilesystems {}}
350
381
}
351
382
352
- func (b * sourceFilesystemsBuilder ) newSourceFilesystem (fs afero.Fs , dirs []hugofs.FileMetaInfo ) * SourceFilesystem {
383
+ func (b * sourceFilesystemsBuilder ) newSourceFilesystem (name string , fs afero.Fs , dirs []hugofs.FileMetaInfo ) * SourceFilesystem {
353
384
return & SourceFilesystem {
385
+ Name : name ,
354
386
Fs : fs ,
355
387
Dirs : dirs ,
356
388
}
357
389
}
390
+
358
391
func (b * sourceFilesystemsBuilder ) Build () (* SourceFilesystems , error ) {
359
392
360
393
if b .theBigFs == nil {
@@ -369,12 +402,12 @@ func (b *sourceFilesystemsBuilder) Build() (*SourceFilesystems, error) {
369
402
370
403
createView := func (componentID string ) * SourceFilesystem {
371
404
if b .theBigFs == nil || b .theBigFs .overlayMounts == nil {
372
- return b .newSourceFilesystem (hugofs .NoOpFs , nil )
405
+ return b .newSourceFilesystem (componentID , hugofs .NoOpFs , nil )
373
406
}
374
407
375
408
dirs := b .theBigFs .overlayDirs [componentID ]
376
409
377
- return b .newSourceFilesystem (afero .NewBasePathFs (b .theBigFs .overlayMounts , componentID ), dirs )
410
+ return b .newSourceFilesystem (componentID , afero .NewBasePathFs (b .theBigFs .overlayMounts , componentID ), dirs )
378
411
379
412
}
380
413
@@ -392,14 +425,14 @@ func (b *sourceFilesystemsBuilder) Build() (*SourceFilesystems, error) {
392
425
return nil , err
393
426
}
394
427
395
- b .result .Data = b .newSourceFilesystem (dataFs , dataDirs )
428
+ b .result .Data = b .newSourceFilesystem (files . ComponentFolderData , dataFs , dataDirs )
396
429
397
430
i18nDirs := b .theBigFs .overlayDirs [files .ComponentFolderI18n ]
398
431
i18nFs , err := hugofs .NewSliceFs (i18nDirs ... )
399
432
if err != nil {
400
433
return nil , err
401
434
}
402
- b .result .I18n = b .newSourceFilesystem (i18nFs , i18nDirs )
435
+ b .result .I18n = b .newSourceFilesystem (files . ComponentFolderI18n , i18nFs , i18nDirs )
403
436
404
437
contentDirs := b .theBigFs .overlayDirs [files .ComponentFolderContent ]
405
438
contentBfs := afero .NewBasePathFs (b .theBigFs .overlayMountsContent , files .ComponentFolderContent )
@@ -409,7 +442,7 @@ func (b *sourceFilesystemsBuilder) Build() (*SourceFilesystems, error) {
409
442
return nil , errors .Wrap (err , "create content filesystem" )
410
443
}
411
444
412
- b .result .Content = b .newSourceFilesystem (contentFs , contentDirs )
445
+ b .result .Content = b .newSourceFilesystem (files . ComponentFolderContent , contentFs , contentDirs )
413
446
414
447
b .result .Work = afero .NewReadOnlyFs (b .theBigFs .overlayFull )
415
448
@@ -421,13 +454,13 @@ func (b *sourceFilesystemsBuilder) Build() (*SourceFilesystems, error) {
421
454
if b .theBigFs .staticPerLanguage != nil {
422
455
// Multihost mode
423
456
for k , v := range b .theBigFs .staticPerLanguage {
424
- sfs := b .newSourceFilesystem (v , b .result .StaticDirs )
457
+ sfs := b .newSourceFilesystem (files . ComponentFolderStatic , v , b .result .StaticDirs )
425
458
sfs .PublishFolder = k
426
459
ms [k ] = sfs
427
460
}
428
461
} else {
429
462
bfs := afero .NewBasePathFs (b .theBigFs .overlayMountsStatic , files .ComponentFolderStatic )
430
- ms ["" ] = b .newSourceFilesystem (bfs , b .result .StaticDirs )
463
+ ms ["" ] = b .newSourceFilesystem (files . ComponentFolderStatic , bfs , b .result .StaticDirs )
431
464
}
432
465
433
466
return b .result , nil
0 commit comments