routeFor function

String routeFor(
  1. String path,
  2. String contentPath
)

content/operations/streaming.md -> /operations/streaming.

index.md drops its trailing segment: content/index.md -> /, content/guides/index.md -> /guides. Mirrors jaspr_content's own PageSource url derivation, which does the same.

Implementation

String routeFor(String path, String contentPath) {
  var relative = path.substring(contentPath.length).replaceAll(r'\', '/');
  relative = relative
      .replaceFirst(RegExp('^/'), '')
      .replaceFirst(RegExp(r'\.md$'), '');
  final segments = relative.split('/');
  if (segments.last == 'index') segments.removeLast();
  if (segments.isEmpty) return '/';
  return '/${segments.join('/')}';
}