Press constructor
Creates a snapshot and validates page identity.
Implementation
Press(Iterable<PressPage> pages) {
final ordered = pages.toList(growable: false)..sort(_comparePages);
final bySlug = <String, PressPage>{};
final byLocation = <String, PressPage>{};
for (final page in ordered) {
final slug = _slugKey(page.slug).toLowerCase();
final previousSlug = bySlug[slug];
if (previousSlug != null) {
throw ArgumentError(
'Press pages "${previousSlug.sourcePath}" and '
'"${page.sourcePath}" use the same slug.',
);
}
final location = page.location.toString().toLowerCase();
final previousLocation = byLocation[location];
if (previousLocation != null) {
throw ArgumentError(
'Press pages "${previousLocation.sourcePath}" and '
'"${page.sourcePath}" use the same location.',
);
}
bySlug[slug] = page;
byLocation[location] = page;
}
this.pages = List<PressPage>.unmodifiable(ordered);
_bySlug = Map<String, PressPage>.unmodifiable(bySlug);
}