-
-
Notifications
You must be signed in to change notification settings - Fork 14
Use map instead of 'if' where applicable #8
Copy link
Copy link
Open
Description
vincent.bernat.ch/layout/nginx.j2
Line 50 in b1fd00d
| {% for code, lang in languages %} |
this part:
{% for code, lang in languages %}
if ($http_accept_language ~* ^{{code}}) {
# Not safe, but it seems to work. May change depending on the outer directives.
set $lang {{code}};
}
{% endfor %}
can be replaced with:
map $http_accept_language $lang {
{% for code, lang in languages %}
^{{code}} {{code}};
{% endfor %}
default en;
}
which reduces the size of configuration (and let you avoid IFs).
You can make it even more interesting by composing a more complex RE with capture like:
^(?<language>(en|fr|de)) $language
Which will result in only two lines: one RE for languages and one default.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels