private IReadOnlyCollection ReadChildren()

in src/Elastic.Documentation.Configuration/Builder/TableOfContentsConfiguration.cs [58:96]


	private IReadOnlyCollection<ITocItem> ReadChildren()
	{
		if (!DefinitionFile.Exists)
			return [];
		var reader = new YamlStreamReader(DefinitionFile, _context.Collector);
		foreach (var entry in reader.Read())
		{
			switch (entry.Key)
			{
				case "toc":
					var children = ReadChildren(reader, entry.Entry);
					var tocEntries = TableOfContents.OfType<TocReference>().ToArray();

					// if no nested toc sections simply return
					if (tocEntries.Length == 0)
						return children;

					// dev docs may mix and match as they please because they publish in isolation
					if (_configuration.DevelopmentDocs)
						return children;

					// narrative docs may put files at the root as they please.
					if (_configuration.IsNarrativeDocs && _depth == 0)
						return children;

					var filePaths = children.OfType<FileReference>().ToArray();
					if (filePaths.Length == 0 && _depth == 0)
						return children;
					if (filePaths.Length is > 1 or 0)
						reader.EmitError("toc with nested toc sections must only link a single file: index.md", entry.Key);
					else if (!filePaths[0].RelativePath.EndsWith("index.md", StringComparison.OrdinalIgnoreCase))
						reader.EmitError($"toc with nested toc sections must only link a single file: 'index.md' actually linked {filePaths[0].RelativePath}", entry.Key);
					return children;
			}
		}


		return [];
	}