FileTopicHelper.ConstructHierarchyByIndexFile Method

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

Definition

Organizes file-backed topics into a hierarchy where index files become parent topics for other files in the same directory.
public static IEnumerable<FileTopic> ConstructHierarchyByIndexFile(IEnumerable<FileTopic> topics, string indexFileName)

Parameters

topics IEnumerable<FileTopic>
The collection of file-backed topics to organize.
indexFileName string
The file name (without extension) that identifies index files.

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 indexFileName is null, empty, or whitespace.

Remarks

This method creates parent-child relationships within each directory by designating files with the specified index name as parent topics for all other files in the same directory. The index file name matching is case-insensitive.

Files in directories that contain only one file or lack an index file are not assigned parent relationships.

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 indexFileName = "index":

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

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