Skip to content

Commit 5902c57

Browse files
oluwandabiraKrzysztof-Cieslak
authored andcommitted
Add some Generator documentation.
1 parent c9d8b94 commit 5902c57

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ let config = {
170170
171171
```
172172

173+
Possible Generator Triggers are:
174+
- `Once` : Runs once, globally.
175+
- `OnFile filename`: Run once for the given filename.
176+
- `OnFileExt extension` : Runs once for each file with the given extension.
177+
- `OnFilePredicate predicate` : Runs once for each file satisfying the predicate (`string -> string`).
178+
179+
Possible Generator Outputs are:
180+
- `SameFileName` : Output has the same filename as input file.
181+
- `ChangeExtension newExtension` : Output has the same filename but with extention change to `newExtension`.
182+
- `NewFileName newFileName` : Output filename is `newFileName`.
183+
- `Custom mapper` : Output filename is the result of applying the mapper to the input filename.
184+
- `MultipleFiles mapper` : Outputs multiple files, the names of which are a result of applying the mapper to the first string output of the generator.
185+
186+
**Note**: For `MultipleFiles` the `generate` function *must* output a `list<string * string>`.
187+
188+
173189
## How to contribute
174190

175191
*Imposter syndrome disclaimer*: I want your help. No really, I do.

src/Fornax.Core/Model.fs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,17 +1327,23 @@ module Config =
13271327
| Once
13281328
///Generator runs once, for given filename (file name is relative to project root, for example `post/post.md`). It runs only if the given file exist.
13291329
| OnFile of filename : string
1330-
///Generator runs for any file with given extension (for example `md`)
1330+
///Generator runs for any file with given extension (for example `md`).
13311331
| OnFileExt of extension: string
1332-
///Generator runs for any file matching predicate. Parameters of predicate are absolut path to project root, and path to the file relative to project root.
1332+
///Generator runs for any file matching predicate. Parameters of predicate are absolute path to project root, and path to the file relative to project root.
13331333
| OnFilePredicate of predicate: ((string * string) -> bool)
13341334

13351335
type GeneratorOutput =
1336+
///Generates a file with the same name.
13361337
| SameFileName
1338+
///Generates a file with the same base name but with the extension changed.
13371339
| ChangeExtension of newExtension: string
1340+
///Generates a file with name `newFileName`.
13381341
| NewFileName of newFileName: string
1339-
| Custom of (string -> string)
1340-
| MultipleFiles of (string -> string)
1342+
///Generates a file with the name as the result of `mapper orignalFileName`.
1343+
| Custom of mapper: (string -> string)
1344+
///Generates multiple files with each name being the result of applying the mapper to the first string of the generator output.
1345+
///The generator must have a type `SiteContents -> string -> string -> list<string * string>`
1346+
| MultipleFiles of mapper: (string -> string)
13411347

13421348
type GeneratorConfig = {
13431349
Script: string

0 commit comments

Comments
 (0)