1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::;
/// Adds a task to the site configuration that finds files matching a glob
/// pattern, processes each file using a provided callback, and collects the
/// results into a `Registry`.
///
/// This function creates and registers a `GlobRegistryTask`. When the build
/// graph is executed, this task will:
/// 1. Find all files on the filesystem that match the `path_glob`.
/// 2. For each file found, it reads its content as raw bytes (`Vec<u8>`).
/// 3. It then invokes the provided `callback` for each file, passing in the
/// global context (`&Globals<G>`) and a `File<Vec<u8>>` struct.
/// 4. The `callback` processes the file and returns a value `R`.
/// 5. The task collects all results and returns a `Registry<R>`, which is a
/// map from the original file path (`Utf8PathBuf`) to the corresponding `R` value.
///
/// This task will also be marked as dirty (triggering a rebuild) if any file
/// matching the `path_glob` is modified.
///
/// # Parameters
///
/// * `site_config`: The mutable `SiteConfig` to which the new task will be added.
/// * `path_glob`: A glob pattern (e.g., `"static/**/*"`) used to find files. This
/// pattern is used for both the initial file discovery and for watching for changes.
/// * `callback`: A closure that defines the processing for each file. It receives
/// the `&Globals<G>` and a `File<Vec<u8>>` (containing the file's path and
/// raw byte content) and must return an `anyhow::Result<R>`.
///
/// # Generics
///
/// * `G`: The type of the global data.
/// * `R`: The return type of the `callback` for a single file. This is the
/// value that will be stored in the `Registry`.
///
/// # Returns
///
/// Returns a `Handle<super::Registry<R>>`, which is a typed reference to the
/// task's output in the build graph. The output will be the `Registry`
/// containing all processed file results.