loadNavigation method

Future<List<NavSection>> loadNavigation()

Load all content and build navigation structure

Implementation

Future<List<NavSection>> loadNavigation() async {
  final dir = Directory(config.contentDir);
  if (!await dir.exists()) {
    return [];
  }

  final sections = <String, NavSection>{};

  await for (final entity in dir.list()) {
    if (entity is Directory) {
      final sectionName = p.basename(entity.path);
      final docs = await loadDirectory(sectionName);

      if (docs.isNotEmpty) {
        sections[sectionName] = NavSection(
          title: _formatTitle(sectionName),
          path: '/$sectionName',
          items: docs.map((doc) => NavItem(
            title: doc.title,
            path: '/${doc.slug}',
            description: doc.description,
          )).toList(),
        );
      }
    }
  }

  return sections.values.toList();
}