Skip to content

Commit

Permalink
Adds *.txt to the list of template files loaded by Tera (#2769)
Browse files Browse the repository at this point in the history
* Add `*.txt` files to the files loaded by `tera`

* Add note to `robots.txt` docs about extending the file with a .txt file
  • Loading branch information
ky-bean authored Jan 13, 2025
1 parent 9733135 commit 897d8f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/templates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn render_redirect_template(url: &str, tera: &Tera) -> Result<String> {

pub fn load_tera(path: &Path, config: &Config) -> Result<Tera> {
let tpl_glob =
format!("{}/{}", path.to_string_lossy().replace('\\', "/"), "templates/**/*.{*ml,md}");
format!("{}/{}", path.to_string_lossy().replace('\\', "/"), "templates/**/*.{*ml,md,txt}");

// Only parsing as we might be extending templates from themes and that would error
// as we haven't loaded them yet
Expand Down
11 changes: 11 additions & 0 deletions docs/content/documentation/templates/robots.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ Disallow:
Allow: /
Sitemap: {{/* get_url(path="sitemap.xml") */}}
```

The file can be extended & expanded like other templates using e.g. Tera's `include` tag:

```jinja2
User-agent: *
Disallow:
Allow: /
Sitemap: {{/* get_url(path="sitemap.xml") */}}
{% include "path/to/other/robots.txt" %}
```

0 comments on commit 897d8f5

Please sign in to comment.