Update website and bootloader
modules/config/web.scm
18 | 18 | (define-module (config web) | |
19 | 19 | #:export (web-base-policy | |
20 | 20 | web-html-policy | |
21 | - | default-web-policy)) | |
21 | + | default-web-policy | |
22 | + | accept-languages)) | |
23 | + | ||
24 | + | (define (accept-languages language-lists) | |
25 | + | "Returns nginx configuration code to set up the $lang variable | |
26 | + | according to the Accept-Language header in the HTTP request. The | |
27 | + | requesting user agent will be served the files at /$lang/some/url. | |
28 | + | Each list in LANGUAGE-LISTS starts with the $lang and is followed by | |
29 | + | synonymous IETF language tags that should be mapped to the same $lang." | |
30 | + | (define (language-mappings language-list) | |
31 | + | (define (language-mapping language) | |
32 | + | (string-join (list " " language (car language-list) ";"))) | |
33 | + | (string-join (map language-mapping language-list) "\n")) | |
34 | + | ||
35 | + | (let ((directives | |
36 | + | `(,(string-join | |
37 | + | `("set_from_accept_language $lang_unmapped" | |
38 | + | ,@(map string-join language-lists) | |
39 | + | ";")) | |
40 | + | "map $lang_unmapped $lang {" | |
41 | + | ,@(map language-mappings language-lists) | |
42 | + | "}"))) | |
43 | + | directives)) | |
22 | 44 | ||
23 | 45 | (define web-base-policy | |
24 | 46 | '("add_header Strict-Transport-Security \"max-age=31536000; includeSubDomains\" always;" |
systems/xana.scm
24 | 24 | (use-modules (config certbot) (config cuirass) (config network) (config os) (config web)) | |
25 | 25 | (use-modules (guix gexp)) | |
26 | 26 | (use-package-modules base compression gettext guile guile-xyz linux version-control | |
27 | - | wget) | |
27 | + | web wget) | |
28 | 28 | ||
29 | 29 | (define lepiller-policy | |
30 | 30 | (append | |
31 | 31 | web-base-policy | |
32 | - | '("# accept-language: en,en-US;q=0.8,ja;q=0.6" | |
33 | - | "set $first_language '';" | |
34 | - | "if ($http_accept_language ~* '(en|eo|fr)') {" | |
35 | - | " set $first_language $1;" | |
36 | - | "}" | |
37 | - | "if ($first_language = '') {" | |
38 | - | " set $first_language 'en';" | |
39 | - | "}" | |
40 | - | "set $my_uri $first_language/$uri;" | |
41 | - | "location ~ ^/[^/]*$ {" | |
42 | - | " return 301 /$first_language/$uri;" | |
43 | - | "}" | |
44 | - | ) | |
45 | 32 | (web-html-policy | |
46 | - | '(" try_files $my_uri $uri $uri/ =404;")) | |
47 | - | '("error_page 404 /404.html;"))) | |
33 | + | '(" try_files $uri /$lang/$uri /$lang/$uri/index.html =404;")) | |
34 | + | '("error_page 404 /$lang/404.html;"))) | |
48 | 35 | ||
49 | 36 | (define (makefile-job directory target packages env) | |
50 | 37 | #~(lambda () | |
… | |||
98 | 85 | (inherit (tyreunom-os "xana")) | |
99 | 86 | (bootloader | |
100 | 87 | (bootloader-configuration | |
101 | - | (target "/dev/sda") | |
88 | + | (targets '("/dev/sda")) | |
102 | 89 | (bootloader grub-bootloader))) | |
103 | 90 | (file-systems (cons (file-system | |
104 | 91 | (mount-point "/") | |
… | |||
110 | 97 | (append | |
111 | 98 | (list | |
112 | 99 | (service dhcp-client-service-type) | |
113 | - | (service nginx-service-type) | |
100 | + | (service nginx-service-type | |
101 | + | (nginx-configuration | |
102 | + | (modules | |
103 | + | (list | |
104 | + | (file-append nginx-accept-language-module | |
105 | + | "/etc/nginx/modules/ngx_http_accept_language_module.so"))) | |
106 | + | (extra-content | |
107 | + | (accept-languages | |
108 | + | '(("en") | |
109 | + | ("fr") | |
110 | + | ("uk") | |
111 | + | ("zh_CN" "zh-CN" "zh" "zh-Hans" "zh-Hans-CN")))))) | |
114 | 112 | (simple-service 'website-cron mcron-service-type | |
115 | 113 | (list i18n-download-job i18n-compile-job | |
116 | 114 | nani-download-job nani-update-job)) |