Skip to content

Commit

Permalink
feat: redirect by language
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Sep 1, 2022
1 parent af64f85 commit b170332
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ theme:
- netlify
```
Add redirections:
### Add redirections
```yaml
netlify:
Expand All @@ -29,3 +29,18 @@ netlify:
status: 301 # optional
force: true # optional
```
### Enable redirect by language
```yaml
netlify:
redirect_by_language: true # false by default
```
It generate the following redirect:
```
/ /fr/ 302! Language=fr
```

> The language can be specified in the cookie `nf_lang`, so you can override the default behavior with JavaScript.
4 changes: 2 additions & 2 deletions layouts/page.netlify_redirects.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
{{ url(redirect.from, {'canonical': false}) }} {{ url(redirect.to, {'canonical': false}) }}{% if redirect.status is defined %} {{ redirect.status }}{% if redirect.force is defined and redirect.force %}!{% endif %}{% endif ~%}
{%- endfor ~%}
{%- endif -%}
{#{%- if site.languages > 1 ~%}
{%- if site.netlify.redirect_by_language|default(false) and site.languages > 1 ~%}
# Language redirects
{%- for language in site.languages|filter(l => l.code != site.language) ~%}
/ /{{ language.code }}/ 302! Language={{ language.code }}
{%- endfor -%}
{%- endif -%}#}
{%- endif -%}

0 comments on commit b170332

Please sign in to comment.