dvStudioSitePages function
Every route of the site: each compiled one, marked as overridden when
stored has a document at its path, then the stored routes no compiled
page answers. Sorted by path.
compiled is the application's own route list, however it was learned:
the project graph a build wrote beside Studio, or the route manifest
compiled into the application Studio runs in. Each entry carries path,
and may carry page, source, kind and module. stored maps a
stored document's route to its title. Nothing here knows any one
project's routes.
Implementation
List<DVStudioSitePage> dvStudioSitePages({
required Iterable<Map<String, Object?>> compiled,
required Map<String, String?> stored,
bool Function(String path)? hasStructure,
}) {
final List<DVStudioSitePage> pages = <DVStudioSitePage>[];
final Set<String> seen = <String>{};
for (final Map<String, Object?> route in compiled) {
final Object? path = route['path'];
if (path is! String || !seen.add(path)) continue;
String? text(String key) =>
route[key] is String && '${route[key]}'.isNotEmpty
? route[key]! as String
: null;
pages.add(
DVStudioSitePage(
path: path,
kind: stored.containsKey(path)
? DVStudioPageKind.override
: DVStudioPageKind.code,
page: text('page'),
source: text('source'),
module: text('module'),
pageKind: text('kind'),
title: stored[path],
structure: hasStructure?.call(path) ?? false,
),
);
}
for (final MapEntry<String, String?> page in stored.entries) {
if (seen.contains(page.key) || dvStudioIsReservedRoute(page.key)) continue;
pages.add(
DVStudioSitePage(
path: page.key,
kind: DVStudioPageKind.stored,
title: page.value,
),
);
}
pages.sort(
(DVStudioSitePage a, DVStudioSitePage b) => a.path.compareTo(b.path),
);
return pages;
}