createSearchIndex function Null safety

List<Map<String, dynamic>> createSearchIndex(
  1. Content content,
  2. Config config
)

Implementation

List<Map<String, dynamic>> createSearchIndex(
  Content content,
  Config config,
) {
  final list = <Map<String, dynamic>>[];

  content.when(
    page: (page) {
      final metadata = page.toMap();
      list.add(
        <String, dynamic>{
          'title': metadata['name'],
          'url': '${config.baseUrl}${metadata['path']}',
        },
      );
    },
    section: (section) {
      for (final element in section.children) {
        list.addAll(createSearchIndex(element, config));
      }
    },
  );

  return list;
}