In addition to content, Statiq Web has rich support for data files.
Data files should be placed in the input
folder (or a sub-folder) alongside content and are processed based on their media type (which is determined by file extension). The following extensions are recognized by default:
.json
processes the file as JSON..yaml
and.yml
processes the file as YAML.
Regardless of format the data files are parsed and the data in them is added as metadata to the resulting documents.
Accessing Data Files
Data files are processed by the Data
pipeline and can be accessed through the Outputs
property of the execution context (which is also available directly in some templating languages like Razor as an Outputs
property).
For example, the following code will find all documents containing data from YAML files that describe different fruits stored in a food/fruit
folder under the default input
folder:
IDocument[] fruits = Outputs
.FromPipeline("Data")
.FilterSources("food/fruit/*")
.ToArray();
Outputting Data Files
By default data files are not output. You may want to adjust this behavior for individual data files or entire directories. This behavior can be controlled with the ShouldOutput
metadata and there are a few ways to set it:
- Set
ShouldOutput
totrue
directly in the data file. This will result in theShouldOutput
value being present in the output file, but that's not always a problem. - Set
ShouldOutput
totrue
for an individual file, and entire directory, or an entire directory tree in a directory metadata file. - Set
ShouldOutput
totrue
in a sidecar file. - Set
ShouldOutput
totrue
in front matter.