FileTopicHelper.ConstructHierarchyByFilenamePrefix Method

Namespace
Kampute.DocToolkit.Support
Assembly
  • Kampute.DocToolkit.dll

Definition

Organizes file-backed topics into a hierarchy using delimited prefixes in file names.
public static IEnumerable<FileTopic> ConstructHierarchyByFilenamePrefix(IEnumerable<FileTopic> topics, char delimiter)

Parameters

topics IEnumerable<FileTopic>
The collection of file-backed topics to organize.
delimiter char
The character used to separate hierarchy levels in file names.

Returns

IEnumerable<FileTopic>
An enumerable collection of FileTopic instances that represent the top-level topics in the hierarchy.

Exceptions

ArgumentNullException
Thrown when topics is null or contains a null topic.
ArgumentException
Thrown when multiple topics have the same file name (without extension), regardless of directory path.

Remarks

This method creates parent-child relationships by analyzing file name prefixes separated by the specified delimiter. Files with fewer delimiter segments become parents of files with more segments that share the same prefix. File name comparison is case-insensitive.

In this method, directories of files are ignored, and only the filenames are considered for hierarchy construction. This means that files with the same name but located in different directories will be treated as if they were in the same directory, and in such cases, an exception will be thrown.

This method assumes that the input topics do not have any existing parent-child relationships. If such relationships exist, they will be overwritten.
The method preserves the order of topics as they were provided in the input collection. Therefore, sort the input collection if you want to control the order of top-level topics and their subtopics.

Example file structure with delimiter = '.':

Input files (directories ignored):
  docs/guides.md
  help/guides.installation.md
  guides.advanced.md
  other/guides.advanced.scripting.md
  tutorials.md
  tutorials.setup.md

Resulting hierarchy:
  guides.md (parent)
  ├── guides.installation.md
  └── guides.advanced.md (parent)
      └── guides.advanced.scripting.md
  tutorials.md (parent)
  └── tutorials.setup.md