FileTopicHelper.ConstructHierarchyByDirectory Method

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

Definition

Organizes file-backed topics into a hierarchy where files become parent topics for directories with matching names.
public static IEnumerable<FileTopic> ConstructHierarchyByDirectory(IEnumerable<FileTopic> topics)

Parameters

topics IEnumerable<FileTopic>
The collection of file-backed topics to organize.

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.

Remarks

This method creates parent-child relationships by matching file names (without extension) to directory names. When a file and directory share the same name, the file becomes the parent topic for all files within that directory. The matching is case-insensitive and works recursively through nested directory structures.

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 and resulting hierarchy:

Input files:
  guides.md
  guides/installation.md
  guides/advanced.md
  guides/advanced/scripting.md
  tutorials.md
  tutorials/setup.md
  standalone.md

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