Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Dec 15, 2022
1 parent fbc6d51 commit 0507bd0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 18 deletions.
65 changes: 53 additions & 12 deletions src/docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,17 +407,59 @@ module.exports = function(eleventyConfig) {
};
```

### Change File Suffix for Template and Directory Data Files {% addedin "0.5.3" %}
When using [Template and Directory Specific Data Files](/docs/data-template-dir/), to prevent file name conflicts with non-Eleventy files in the project directory, we scope these files with a unique-to-Eleventy suffix. This key is customizable using `jsDataFileSuffix`. For example, using `.11tydata` for this value will search for `*.11tydata.js` and `*.11tydata.json` data files. Read more about [Template and Directory Specific Data Files](/docs/data-template-dir/).
### Change Base File Name for Data Files

{% addedin "2.0.0-canary.19" %} When using [Directory Specific Data Files](/docs/data-template-dir/), looks for data files that match the current folder name. You can override this behavior to a static string with the `setDataFileBaseName` method.

| File Suffix | |
| --- | --- |
| _Object Key_ | `jsDataFileSuffix` |
| _Default_ | `.11tydata` |
| _Valid Options_ | Any valid string |
| _Configuration API_ | `setDataFileBaseName` |
| _Default_ | _Current folder name_ |
| _Valid Options_ | String |
| _Command Line Override_ | _None_ |

#### Example
{% codetitle ".eleventy.js" %}

```js
module.exports = function(eleventyConfig) {
// Looks for index.json and index.11tydata.json instead of using folder names
eleventyConfig.setDataFileBaseName("index");
};
```

### Change File Suffix for Data Files

{% addedin "2.0.0-canary.19" %} When using [Template and Directory Specific Data Files](/docs/data-template-dir/), to prevent file name conflicts with non-Eleventy files in the project directory, we scope these files with a unique-to-Eleventy suffix. This suffix is customizable using the `setDataFileSuffixes` configuration API method.

| File Suffix | |
| --- | --- |
| _Configuration API_ | `setDataFileSuffixes` |
| _Default_ | `[".11tydata", ""]` |
| _Valid Options_ | Array |
| _Command Line Override_ | _None_ |

For example, using `".11tydata"` will search for `*.11tydata.js` and `*.11tydata.json` data files. The empty string (`""`) here represents a file without a suffix—and this entry only applies to `*.json` data files.

This feature can also be used to disable Template and Directory Data Files altogether with an empty array (`[]`).

Read more about [Template and Directory Specific Data Files](/docs/data-template-dir/).

{% codetitle ".eleventy.js" %}

```js
module.exports = function(eleventyConfig) {
eleventyConfig.setDataFileSuffixes([".11tydata", ""]); // e.g. file.json and file.11tydata.json

eleventyConfig.setDataFileSuffixes([".11tydata"]); // e.g. file.11tydata.json

eleventyConfig.setDataFileSuffixes([]); // No data files are used.
};
```

<details>
<summary><em><strong>Backwards Compatibility Note</strong></em> (prior to <code>2.0.0-canary.19</code>)</summary>

Prior to 2.0.0-canary.19 this feature was exposed using a `jsDataFileSuffix` property in your configuration return object. When the `setDataFileSuffixes` method has not been used, Eleventy maintains backwards compatibility for old projects by using this property as a fallback.

{% codetitle ".eleventy.js" %}

Expand All @@ -429,21 +471,20 @@ module.exports = function(eleventyConfig) {
};
```

### Transforms
</details>

_These used to be called Filters but were renamed to Transforms to avoid confusion with Template Language Filters._
### Transforms

Transforms can modify a template’s output. For example, use a transform to format/prettify an HTML file with proper whitespace.

The provided transform function must return the original or transformed content.

| Transforms | |
| --- | --- |
| _Object Key_ | `filters` _(Removed in 1.0, use `addTransform` instead)_ |
| _Configuration API_ | `addTransform` |
| _Default_ | `{}` |
| _Valid Options_ | Object literal |
| _Command Line Override_ | _None_ |
| _Configuration API_ | `addTransform` {% addedin "0.3.3" %} |

```js
module.exports = function(eleventyConfig) {
Expand Down Expand Up @@ -494,10 +535,10 @@ Similar to Transforms, Linters are provided to analyze a template’s output wit

| Linters | |
| --- | --- |
| _Configuration API_ | `addLinter` |
| _Object Key_ | _N/A_ |
| _Valid Options_ | Callback function |
| _Command Line Override_ | _None_ |
| _Configuration API_ | `addLinter` {% addedin "0.5.4" %} |

```js
module.exports = function(eleventyConfig) {
Expand Down Expand Up @@ -568,7 +609,7 @@ module.exports = function (eleventyConfig) {
};
```

More background information at [Issue 2091](https://github.com/11ty/eleventy/pull/2091).
* More background information at [Issue 2091](https://github.com/11ty/eleventy/pull/2091).

### Documentation Moved to Dedicated Pages

Expand Down
2 changes: 2 additions & 0 deletions src/docs/data-custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,5 @@ Consider the [template data file search](/docs/data-template-dir/) for a `my-fir
* `my-first-blog-post.toml` (custom)

This same ordering would be used for [template directory data files](/docs/data-template-dir/) as well.

* You can also use the [`setDataFileSuffixes` Configuration API method to **customize the `.11tydata` file suffix**](/docs/config/#change-file-suffix-for-data-files).
18 changes: 12 additions & 6 deletions src/docs/data-template-dir.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@ For example, consider a template located at `posts/subdir/my-first-blog-post.md`
* `posts/posts.json`
1. [Global Data Files](/docs/data-global/) in `_data/*` (`.js` or `.json` files) available to all templates.

{% callout "info" %}Note that the name of the data file must match either the post or the directory it resides within.{% endcallout %}
## Examples

Note that any [Custom Formats](/docs/data-custom/#ordering-in-the-data-cascade) {% addedin "0.10.0" %} specified in your configuration will also be taken into account at a lower priority than their JavaScript or JSON counterparts.
### Apply a default layout to multiple templates

### Change the `.11tydata.js` file suffix {% addedin "0.5.3" %}
{% codetitle "posts/post.json" %}

Use the [Configuration API to change the file suffix](/docs/config/#change-file-suffix-for-template-and-directory-data-files) used to search for Eleventy data files.
```json
{ "layout": "layouts/post.njk" }
```

## Example: Apply a default layout to multiple templates
Using the above in `posts/post.json` will configure a layout for all of the templates inside of `posts/*`.

Try adding `{ "layout": "layouts/post.njk" }` to `posts/posts.json` to configure a layout for all of the templates inside of `posts/*`.
## Additional Customizations

* The name of the data file must match either the post or the directory it resides within. You can [change this behavior using the `setDataFileBaseName` method in the Configuration API](/docs/config/#change-base-file-name-for-data-files).
* You can use the [`setDataFileSuffixes` Configuration API method to **customize the default file suffixes or disable this feature altogether**](/docs/config/#change-file-suffix-for-data-files).
* Note that any [Custom Formats](/docs/data-custom/#ordering-in-the-data-cascade) {% addedin "0.10.0" %} specified in your configuration will also be taken into account at a lower priority than their JavaScript or JSON counterparts.

## Sources of Data

Expand Down

0 comments on commit 0507bd0

Please sign in to comment.