Skip to content

Commit 8634829

Browse files
committed
Refactor folder retrieval logic to improve clarity and maintainability
1 parent 6cdb06a commit 8634829

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/Blake.BuildTools/Generator/SiteGenerator.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,7 @@ private static async Task<BlakeContext> GetBlakeContext(GenerationOptions option
247247
.SetupContainerRenderers(options.UseDefaultRenderers, useRazorContainers: true)
248248
};
249249

250-
var folders = Directory.GetDirectories(options.ProjectPath, "*", SearchOption.AllDirectories)
251-
.Select(Path.GetFileName)
252-
.Where(folder =>
253-
folder != null &&
254-
!folder.StartsWith('.') &&
255-
!folder.Equals("obj", StringComparison.OrdinalIgnoreCase) &&
256-
!folder.Equals("bin", StringComparison.OrdinalIgnoreCase))
257-
.Select(f => f!)
258-
.ToList();
250+
var folders = GetAllFolders(options.ProjectPath);
259251

260252
var templateMappings = MapTemplates(folders, options.ProjectPath, null, logger);
261253

@@ -366,7 +358,7 @@ private static Dictionary<string, string> MapTemplates(
366358
IEnumerable<string> folders,
367359
string rootPath,
368360
string? cascadingTemplatePath,
369-
ILogger? logger = null)
361+
ILogger logger)
370362
{
371363
Dictionary<string, string> templateMappings = [];
372364

@@ -412,20 +404,12 @@ private static Dictionary<string, string> MapTemplates(
412404
}
413405
}
414406

415-
var children = Directory.GetDirectories(fullFolderPath)
416-
.Select(Path.GetFileName)
417-
.Where(child =>
418-
child != null &&
419-
!child.StartsWith('.') &&
420-
!child.Equals("obj", StringComparison.OrdinalIgnoreCase) &&
421-
!child.Equals("bin", StringComparison.OrdinalIgnoreCase))
422-
.Select(child => child!)
423-
.ToList();
424-
407+
var children = GetAllFolders(fullFolderPath);
408+
425409
if (children.Count == 0) continue;
426-
410+
427411
var childMappings = MapTemplates(children, fullFolderPath, cascadingPath, logger);
428-
412+
429413
foreach (var child in childMappings)
430414
{
431415
templateMappings.Add(child.Key, child.Value);
@@ -434,4 +418,21 @@ private static Dictionary<string, string> MapTemplates(
434418

435419
return templateMappings;
436420
}
421+
422+
private static List<string> GetAllFolders(string rootPath)
423+
{
424+
var children = Directory.GetDirectories(rootPath, "*", SearchOption.TopDirectoryOnly)
425+
.Select(Path.GetFileName)
426+
.Where(child =>
427+
child != null &&
428+
!child.StartsWith('.') &&
429+
!child.Equals("obj", StringComparison.OrdinalIgnoreCase) &&
430+
!child.Equals("bin", StringComparison.OrdinalIgnoreCase) &&
431+
!child.Equals("wwwroot", StringComparison.OrdinalIgnoreCase) &&
432+
!child.Equals("node_modules", StringComparison.OrdinalIgnoreCase))
433+
.Select(child => child!)
434+
.ToList();
435+
436+
return children;
437+
}
437438
}

0 commit comments

Comments
 (0)