Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/content/concepts/route_loading.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The `FilesystemLoader` loads pages from a specified directory on your local file
- Supports hot-reloading in debug mode: Changes to files trigger a rebuild of the affected pages.
- Can keep file suffixes for specific paths using the `keepSuffixPattern` argument.
- Can ignore unknown file extensions using the `filterExtensions` argument, which allows for co-locating data files or assets within the content directory.
- Can skip files by path using the `ignorePattern` argument, for example `RegExp(r'(.*/)?README\.md$')` to leave out every `README.md`.

**Example:**

Expand Down
2 changes: 2 additions & 0 deletions packages/jaspr_content/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased 0.6.0-beta.1

- Added `ignorePattern` parameter to `FilesystemLoader`, which skips the files whose path it matches from the start. This can be used to leave files such as `README.md` out of the pages.
- Fixed pages not being rebuilt when a partial that is not a page source, such as a file excluded by `filterExtensions`, is edited while serving.
- Fixed `RSSOutput` writing feeds that are not valid RSS 2.0. Dates now use the RFC 822 format, text is escaped, and the `guid` is marked as not a permalink.

## 0.6.0-beta.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class FilesystemLoader extends RouteLoaderBase<FilePageSource> {
this.directory, {
this.filterExtensions = const {},
this.keepSuffixPattern,
this.ignorePattern,
super.debugPrint,
@visibleForTesting this.fileSystem = const LocalFileSystem(),
@visibleForTesting DirectoryWatcherFactory? watcherFactory,
Expand All @@ -37,13 +38,24 @@ class FilesystemLoader extends RouteLoaderBase<FilePageSource> {
/// A pattern to keep the file suffix for all matching pages.
final Pattern? keepSuffixPattern;

/// A pattern for files that should not be loaded as pages.
///
/// A file is skipped when the pattern matches at the start of its path. The path is relative to [directory]
/// and written with forward slashes on every platform. For example, `RegExp(r'(.*/)?README\.md$')` skips
/// every README.md, and `RegExp(r'drafts/.*')` skips everything below the top-level drafts folder.
///
/// Like files excluded by [filterExtensions], ignored files can still be read as partials.
final Pattern? ignorePattern;

@visibleForTesting
final FileSystem fileSystem;
@visibleForTesting
final DirectoryWatcherFactory watcherFactory;

static DirectoryWatcher _defaultWatcherFactory(String path) => DirectoryWatcher(path);

bool _isIgnored(String posixPath) => ignorePattern?.matchAsPrefix(posixPath) != null;

final Map<String, Set<FilePageSource>> dependentSources = {};

StreamSubscription<WatchEvent>? _watcherSub;
Expand Down Expand Up @@ -113,6 +125,9 @@ class FilesystemLoader extends RouteLoaderBase<FilePageSource> {
final posixPath = p.posix.fromUri(
fileSystem.path.toUri(fileSystem.path.relative(entry.path, from: directory)),
);
if (_isIgnored(posixPath)) {
continue;
}
entities.add(
FilePageSource(
posixPath,
Expand Down Expand Up @@ -142,6 +157,12 @@ class FilesystemLoader extends RouteLoaderBase<FilePageSource> {
final posixPath = p.posix.fromUri(
fileSystem.path.toUri(fileSystem.path.relative(path, from: directory)),
);
if (_isIgnored(posixPath)) {
// Like partials excluded by filterExtensions, ignored files are not page sources,
// but pages that read them as partials need a rebuild if they failed while the file was missing.
_invalidateDependentSources(path);
return;
}
addSource(
FilePageSource(
posixPath,
Expand All @@ -161,7 +182,7 @@ class FilesystemLoader extends RouteLoaderBase<FilePageSource> {
if (source != null) {
removeSource(source);
} else {
// Partials excluded by filterExtensions are not page sources,
// Partials excluded by filterExtensions or ignorePattern are not page sources,
// but might still have dependents registered through readPartial.
_invalidateDependentSources(path);
}
Expand All @@ -171,6 +192,10 @@ class FilesystemLoader extends RouteLoaderBase<FilePageSource> {
final source = sources.where((source) => source.file.path == path).firstOrNull;
if (source != null) {
invalidateSource(source, rebuild: rebuild);
} else {
// Partials excluded by filterExtensions or ignorePattern are not page sources,
// but might still have dependents registered through readPartial.
_invalidateDependentSources(path, rebuild: rebuild);
}
}

Expand Down
Loading
Loading